U
    Ð‹ÑhK  ã                   @   sò  U d dl mZ d dlmZmZmZmZmZmZ d dl	Z	d dl
mZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZmZ dddddddddddddddddgZG dd„ dejƒZdDeeeef  eejdœdd „Z d!d"d#d"d$d$d"d%d%d"d%d%d"gd!d!d"d#d#d"d$d$d"d%d%d"d%d%d"gd!d!d"d#d#d"d$d$d$d"d%d%d%d"d%d%d%d"gd!d!d"d#d#d"d$d$d$d$d"d%d%d%d%d"d%d%d%d%d"gd&œZ!eeeeeef  f e"d'< eeee eeed(œd)d*„Z#d+ed,d-d.œZ$G d/d„ deƒZ%G d0d„ deƒZ&G d1d„ deƒZ'G d2d„ deƒZ(G d3d„ deƒZ)G d4d„ deƒZ*G d5d„ deƒZ+G d6d„ deƒZ,eƒ ed7e%j-fd8�dd9d:œee% eeed;œd<d„ƒƒZ.eƒ ed7e&j-fd8�dd9d:œee& eeed;œd=d„ƒƒZ/eƒ ed7e'j-fd8�dd9d:œee' eeed;œd>d„ƒƒZ0eƒ ed7e(j-fd8�dd9d:œee( eeed;œd?d„ƒƒZ1eƒ ed7e)j-fd8�dd9d:œee) eeed;œd@d„ƒƒZ2eƒ ed7e*j-fd8�dd9d:œee* eeed;œdAd„ƒƒZ3eƒ ed7e+j-fd8�dd9d:œee+ eeed;œdBd„ƒƒZ4eƒ ed7e,j-fd8�dd9d:œee, eeed;œdCd„ƒƒZ5dS )Eé    )Úpartial)ÚAnyÚcastÚDictÚListÚOptionalÚUnionNé   )ÚImageClassification)Ú_log_api_usage_onceé   )Úregister_modelÚWeightsÚWeightsEnum)Ú_IMAGENET_CATEGORIES)Ú_ovewrite_named_paramÚhandle_legacy_interfaceÚVGGÚVGG11_WeightsÚVGG11_BN_WeightsÚVGG13_WeightsÚVGG13_BN_WeightsÚVGG16_WeightsÚVGG16_BN_WeightsÚVGG19_WeightsÚVGG19_BN_WeightsÚvgg11Úvgg11_bnÚvgg13Úvgg13_bnÚvgg16Úvgg16_bnÚvgg19Úvgg19_bnc                       sB   e Zd Zdejeeeddœ‡ fdd„Ze	j
e	j
dœd	d
„Z‡  ZS )r   éè  Tç      à?N)ÚfeaturesÚnum_classesÚinit_weightsÚdropoutÚreturnc                    s   t ƒ  ¡  t| ƒ || _t d¡| _t t dd¡t 	d¡tj
|d�t dd¡t 	d¡tj
|d�t d|¡¡| _|�r|  ¡ D ]œ}t|tjƒr¾tjj|jddd� |jd k	r¼tj |jd	¡ q~t|tjƒrìtj |jd
¡ tj |jd	¡ q~t|tjƒr~tj |jd	d¡ tj |jd	¡ q~d S )N)é   r+   i b  i   T)ÚpZfan_outZrelu)ÚmodeZnonlinearityr   r   g{®Gáz„?)ÚsuperÚ__init__r   r&   ÚnnZAdaptiveAvgPool2dÚavgpoolÚ
SequentialZLinearÚReLUZDropoutÚ
classifierÚmodulesÚ
isinstanceÚConv2dÚinitZkaiming_normal_ZweightZbiasZ	constant_ÚBatchNorm2dZnormal_)Úselfr&   r'   r(   r)   Úm©Ú	__class__© úD/tmp/user/2202/pip-unpacked-wheel-mjxxo1pc/torchvision/models/vgg.pyr/   $   s2    





ù	
zVGG.__init__)Úxr*   c                 C   s.   |   |¡}|  |¡}t |d¡}|  |¡}|S )Nr   )r&   r1   ÚtorchÚflattenr4   )r:   r@   r>   r>   r?   ÚforwardA   s
    


zVGG.forward)r$   Tr%   )Ú__name__Ú
__module__Ú__qualname__r0   ÚModuleÚintÚboolÚfloatr/   rA   ZTensorrC   Ú__classcell__r>   r>   r<   r?   r   #   s        ÿ   þF)ÚcfgÚ
batch_normr*   c                 C   s�   g }d}| D ]x}|dkr.|t jddd�g7 }qtt|ƒ}t j||ddd�}|rl||t  |¡t jdd�g7 }n||t jdd�g7 }|}qt j|Ž S )	Né   ÚMr	   )Úkernel_sizeZstrider   )rP   ÚpaddingT)Zinplace)r0   Z	MaxPool2dr   rH   r7   r9   r3   r2   )rL   rM   ZlayersZin_channelsÚvZconv2dr>   r>   r?   Úmake_layersI   s    
rS   é@   rO   é€   é   i   )ÚAÚBÚDÚEÚcfgs)rL   rM   ÚweightsÚprogressÚkwargsr*   c                 K   sl   |d k	r4d|d< |j d d k	r4t|dt|j d ƒƒ ttt|  |d�f|Ž}|d k	rh| |j|dd�¡ |S )NFr(   Ú
categoriesr'   )rM   T)r]   Z
check_hash)Úmetar   Úlenr   rS   r[   Zload_state_dictZget_state_dict)rL   rM   r\   r]   r^   Úmodelr>   r>   r?   Ú_vggb   s    rc   )é    rd   zUhttps://github.com/pytorch/vision/tree/main/references/classification#alexnet-and-vggzNThese weights were trained from scratch by using a simplified training recipe.)Zmin_sizer_   ÚrecipeÚ_docsc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z6https://download.pytorch.org/models/vgg11-8a719046.pthéà   ©Ú	crop_sizeihUëúImageNet-1Kgáz®GAQ@gÕxé&1(V@©zacc@1zacc@5çV-²�o@g=
×£p­@©Ú
num_paramsÚ_metricsÚ_opsÚ
_file_size©ÚurlZ
transformsr`   N©	rD   rE   rF   r   r   r
   Ú_COMMON_METAÚIMAGENET1K_V1ÚDEFAULTr>   r>   r>   r?   r   u   s   
þÿöýc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z9https://download.pytorch.org/models/vgg11_bn-6002323d.pthrg   rh   ièjërj   gHáz®—Q@g¤p=
×sV@rk   rl   gj¼t“®@rm   rr   Nrt   r>   r>   r>   r?   r   ‰   s   
þÿöýc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z6https://download.pytorch.org/models/vgg13-19584684.pthrg   rh   i(&îrj   g¬Zd{Q@g9´Èv¾OV@rk   çV-²�&@g…ëQ¸¸@rm   rr   Nrt   r>   r>   r>   r?   r   �   s   
þÿöýc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z9https://download.pytorch.org/models/vgg13_bn-abd245e5.pthrg   rh   i(=îrj   g/Ý$�åQ@g-²�ï—V@rk   rx   g=
×£p¹@rm   rr   Nrt   r>   r>   r>   r?   r   ±   s   
þÿöýc                   @   s~   e Zd Zedeedd�edddddœid	d
dœ–d�Zedeedddd�eddddedƒedƒdœid	dddœ–d�Z	eZ
dS )r   z6https://download.pytorch.org/models/vgg16-397923af.pthrg   rh   i(+?rj   gÙÎ÷SãåQ@gœÄ °r˜V@rk   çq=
×£ð.@gî|?5^~€@rm   rr   zIhttps://download.pytorch.org/models/vgg16_features-amdegroot-88682ab5.pth)g;pÎˆÒÞÞ?gÌ°�N]Ý?g|
€ñÚ?)çp?rz   rz   )ri   ZmeanZstdNz5https://github.com/amdegroot/ssd.pytorch#training-ssdÚnang#Ûù~j~€@a`  
                These weights can't be used for classification because they are missing values in the `classifier`
                module. Only the `features` module has valid values and can be used for feature extraction. The weights
                were trained using the original input standardization method as described in the paper.
            )rn   r_   re   ro   rp   rq   rf   )rD   rE   rF   r   r   r
   ru   rv   rJ   ZIMAGENET1K_FEATURESrw   r>   r>   r>   r?   r   Å   sJ   
þÿöýüþÿó÷c                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z9https://download.pytorch.org/models/vgg16_bn-6c64b313.pthrg   rh   i(L?rj   g×£p=
WR@g/Ý$áV@rk   ry   g°rh‘í~€@rm   rr   Nrt   r>   r>   r>   r?   r   ö   s   
þÿöýc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z6https://download.pytorch.org/models/vgg19-dcbb9e9d.pthrg   rh   i(0�rj   gòÒMbR@gòÒMb¸V@rk   çoƒÀÊ¡3@gÅ °rh �@rm   rr   Nrt   r>   r>   r>   r?   r   
  s   
þÿöýc                	   @   s>   e Zd Zedeedd�edddddœid	d
dœ–d�ZeZdS )r   z9https://download.pytorch.org/models/vgg19_bn-c79401a0.pthrg   rh   i([�rj   gË¡E¶ó�R@gÙÎ÷SãõV@rk   r|   g /Ý$!�@rm   rr   Nrt   r>   r>   r>   r?   r     s   
þÿöýZ
pretrained)r\   T)r\   r]   )r\   r]   r^   r*   c                 K   s   t  | ¡} tdd| |f|ŽS )ap  VGG-11 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG11_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG11_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG11_Weights
        :members:
    rW   F)r   Úverifyrc   ©r\   r]   r^   r>   r>   r?   r   2  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )a|  VGG-11-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG11_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG11_BN_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG11_BN_Weights
        :members:
    rW   T)r   r}   rc   r~   r>   r>   r?   r   L  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )ap  VGG-13 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG13_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG13_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG13_Weights
        :members:
    rX   F)r   r}   rc   r~   r>   r>   r?   r   f  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )a|  VGG-13-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG13_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG13_BN_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG13_BN_Weights
        :members:
    rX   T)r   r}   rc   r~   r>   r>   r?   r   €  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )ap  VGG-16 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG16_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG16_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG16_Weights
        :members:
    rY   F)r   r}   rc   r~   r>   r>   r?   r    š  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )a|  VGG-16-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG16_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG16_BN_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG16_BN_Weights
        :members:
    rY   T)r   r}   rc   r~   r>   r>   r?   r!   ´  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )ap  VGG-19 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG19_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG19_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG19_Weights
        :members:
    rZ   F)r   r}   rc   r~   r>   r>   r?   r"   Î  s    
c                 K   s   t  | ¡} tdd| |f|ŽS )a|  VGG-19_BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG19_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG19_BN_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.VGG19_BN_Weights
        :members:
    rZ   T)r   r}   rc   r~   r>   r>   r?   r#   è  s    
)F)6Ú	functoolsr   Útypingr   r   r   r   r   r   rA   Ztorch.nnr0   Ztransforms._presetsr
   Úutilsr   Z_apir   r   r   Z_metar   Ú_utilsr   r   Ú__all__rG   r   ÚstrrH   rI   r2   rS   r[   Ú__annotations__rc   ru   r   r   r   r   r   r   r   r   rv   r   r   r   r   r    r!   r"   r#   r>   r>   r>   r?   Ú<module>   s�     ï&" &,ü"ü1$$$$$$$