U
    (dJ                     @   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 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dFe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d7e$j,fd8dd9d:ee$ eeed;d<dZ-ed7e%j,fd8dd9d:ee% eeed;d=dZ.ed7e&j,fd8dd9d:ee& eeed;d>dZ/ed7e'j,fd8dd9d:ee' eeed;d?dZ0ed7e(j,fd8dd9d:ee( eeed;d@dZ1ed7e)j,fd8dd9d:ee) eeed;dAdZ2ed7e*j,fd8dd9d:ee* eeed;dBdZ3ed7e+j,fd8dd9d:ee+ eeed;dCdZ4ddDlm5Z5 e5e$j,j6e&j,j6e(j,j6e*j,j6e%j,j6e'j,j6e)j,j6e+j,j6dEZ7dS )G    )partial)UnionListDictAnyOptionalcastN   )ImageClassification)_log_api_usage_once   )WeightsEnumWeights)_IMAGENET_CATEGORIES)handle_legacy_interface_ovewrite_named_param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rtjj|jddd |jd k	rtj|jd	 q~t|tjrt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{Gz?)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__ :/tmp/pip-unpacked-wheel-vx7f76es/torchvision/models/vgg.pyr.   $   s2    





	
zVGG.__init__)xr)   c                 C   s.   |  |}| |}t|d}| |}|S )Nr   )r%   r0   torchflattenr3   )r9   r?   r=   r=   r>   forwardA   s
    


zVGG.forward)r#   Tr$   )__name__
__module____qualname__r/   Moduleintboolfloatr.   r@   ZTensorrB   __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   )rO   paddingT)Zinplace)r/   Z	MaxPool2dr   rG   r6   r8   r2   r1   )rK   rL   ZlayersZin_channelsvZconv2dr=   r=   r>   make_layersI   s    
rR   @   rN         i   )ABDEcfgs)rK   rL   weightsprogresskwargsr)   c                 K   sj   |d k	r4d|d< |j d d k	r4t|dt|j d  ttt|  |df|}|d k	rf||j|d |S )NFr'   
categoriesr&   )rL   )r\   )metar   lenr   rR   rZ   Zload_state_dictZget_state_dict)rK   rL   r[   r\   r]   modelr=   r=   r>   _vggb   s    rb   )    rc   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
ZeZdS )r   z6https://download.pytorch.org/models/vgg11-8a719046.pth   	crop_sizeihUImageNet-1KgzGAQ@gx&1(V@zacc@1zacc@5
num_params_metricsurlZ
transformsr_   N	rC   rD   rE   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
ZeZdS )r   z9https://download.pytorch.org/models/vgg11_bn-6002323d.pthrf   rg   ijri   gHzQ@gp=
sV@rj   rk   rn   Nrp   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
ZeZdS )r   z6https://download.pytorch.org/models/vgg13-19584684.pthrf   rg   i(&ri   gZd{Q@g9vOV@rj   rk   rn   Nrp   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
ZeZdS )r   z9https://download.pytorch.org/models/vgg13_bn-abd245e5.pthrf   rg   i(=ri   g/$Q@g-V@rj   rk   rn   Nrp   r=   r=   r=   r>   r      s   
c                   @   sv   e Zd Zedeeddedddddi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
Z	eZ
dS )r   z6https://download.pytorch.org/models/vgg16-397923af.pthrf   rg   i(+?ri   gSQ@g rV@rj   rk   rn   zIhttps://download.pytorch.org/models/vgg16_features-amdegroot-88682ab5.pth)g;pΈ?gN]?g|
?)p?rt   rt   )rh   ZmeanZstdNz5https://github.com/amdegroot/ssd.pytorch#training-ssdnana`  
                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.
            )rl   r^   rd   rm   re   )rC   rD   rE   r   r   r
   rq   rr   rI   ZIMAGENET1K_FEATURESrs   r=   r=   r=   r>   r      sB   
c                	   @   s:   e Zd Zedeeddedddddid	d
ZeZdS )r   z9https://download.pytorch.org/models/vgg16_bn-6c64b313.pthrf   rg   i(L?ri   gףp=
WR@g/$V@rj   rk   rn   Nrp   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
ZeZdS )r   z6https://download.pytorch.org/models/vgg19-dcbb9e9d.pthrf   rg   i(0ri   gMbR@gMbV@rj   rk   rn   Nrp   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
ZeZdS )r   z9https://download.pytorch.org/models/vgg19_bn-c79401a0.pthrf   rg   i([ri   gˡER@gSV@rj   rk   rn   Nrp   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:
    rV   F)r   verifyrb   r[   r\   r]   r=   r=   r>   r      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:
    rV   T)r   rv   rb   rw   r=   r=   r>   r   9  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:
    rW   F)r   rv   rb   rw   r=   r=   r>   r   R  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:
    rW   T)r   rv   rb   rw   r=   r=   r>   r   k  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:
    rX   F)r   rv   rb   rw   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:
    rX   T)r   rv   rb   rw   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:
    rY   F)r   rv   rb   rw   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:
    rY   T)r   rv   rb   rw   r=   r=   r>   r"     s    
)
_ModelURLs)r   r   r   r!   r   r   r    r"   )F)8	functoolsr   typingr   r   r   r   r   r   r@   Ztorch.nnr/   Ztransforms._presetsr
   utilsr   Z_apir   r   Z_metar   _utilsr   r   __all__rF   r   strrG   rH   r1   rR   rZ   __annotations__rb   rq   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   r    r!   r"   rx   ro   Z
model_urlsr=   r=   r=   r>   <module>   s     &" &,"-""""""""