o
    ,hK                     @   s  U d dl mZ d dl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 g dZG dd de	jZdGdeeeef  dede	jfddZg dg dg dg ddZ e!eeeeef  f e"d< dededee dededefddZ#ded d!d"Z$G d#d$ d$eZ%G d%d& d&eZ&G d'd( d(eZ'G d)d* d*eZ(G d+d, d,eZ)G d-d. d.eZ*G d/d0 d0eZ+G d1d2 d2eZ,e ed3e%j-fd4dd5d6dee% dededefd7d8Z.e ed3e&j-fd4dd5d6dee& dededefd9d:Z/e ed3e'j-fd4dd5d6dee' dededefd;d<Z0e ed3e(j-fd4dd5d6dee( dededefd=d>Z1e ed3e)j-fd4dd5d6dee) dededefd?d@Z2e ed3e*j-fd4dd5d6dee* dededefdAdBZ3e ed3e+j-fd4dd5d6dee+ dededefdCdDZ4e ed3e,j-fd4dd5d6dee, dededefdEdFZ5dS )H    )partial)Anycast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                       sN   e Zd Z	ddejdedededd	f
 fd
dZde	j
de	j
fddZ  ZS )r     T      ?featuresnum_classesinit_weightsdropoutreturnNc                    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 ]P}t|tjr^tjj|jddd |jd ur]tj|jd	 q>t|tjrutj|jd
 tj|jd	 q>t|tjrtj|jd	d tj|jd	 q>d S d S )N)   r)   i b  i   T)pfan_outrelu)modenonlinearityr   r
   g{Gz?)super__init__r	   r$   nnAdaptiveAvgPool2davgpool
SequentialLinearReLUDropout
classifiermodules
isinstanceConv2dinitkaiming_normal_weightbias	constant_BatchNorm2dnormal_)selfr$   r%   r&   r'   m	__class__ Q/var/www/html/scripts/venv/lib/python3.10/site-packages/torchvision/models/vgg.pyr0   $   s:   





	
zVGG.__init__xc                 C   s.   |  |}| |}t|d}| |}|S )Nr
   )r$   r3   torchflattenr8   )rC   rI   rG   rG   rH   forwardA   s
   


zVGG.forward)r"   Tr#   )__name__
__module____qualname__r1   Moduleintboolfloatr0   rJ   TensorrL   __classcell__rG   rG   rE   rH   r   #   s    r   Fcfg
batch_normr(   c                 C   s   g }d}| D ]<}|dkr|t jdddg7 }qtt|}t j||ddd}|r6||t |t jddg7 }n
||t jddg7 }|}qt j| S )	N   Mr   )kernel_sizestrider
   )rZ   paddingT)inplace)r1   	MaxPool2dr   rQ   r;   rA   r6   r4   )rV   rW   layersin_channelsvconv2drG   rG   rH   make_layersI   s   

rc   )@   rY      rY      rf   rY      rg   rY   rg   rg   rY   )rd   rd   rY   re   re   rY   rf   rf   rY   rg   rg   rY   rg   rg   rY   )rd   rd   rY   re   re   rY   rf   rf   rf   rY   rg   rg   rg   rY   rg   rg   rg   rY   )rd   rd   rY   re   re   rY   rf   rf   rf   rf   rY   rg   rg   rg   rg   rY   rg   rg   rg   rg   rY   )ABDEcfgsweightsprogresskwargsc                 K   sp   |d urd|d< |j d d urt|dt|j d  ttt|  |dfi |}|d ur6||j|dd |S )NFr&   
categoriesr%   )rW   T)rn   
check_hash)metar   lenr   rc   rl   load_state_dictget_state_dict)rV   rW   rm   rn   ro   modelrG   rG   rH   _vggb   s   rw   )    rx   zUhttps://github.com/pytorch/vision/tree/main/references/classification#alexnet-and-vggzNThese weights were trained from scratch by using a simplified training recipe.)min_sizerp   recipe_docsc                	   @   B   e Zd Zedeeddi 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-1KgzGAQ@gx&1(V@zacc@1zacc@5V-o@g=
ףp@
num_params_metrics_ops
_file_sizeurl
transformsrr   N	rM   rN   rO   r   r   r   _COMMON_METAIMAGENET1K_V1DEFAULTrG   rG   rG   rH   r   u   $    
r   c                	   @   r|   )r   z9https://download.pytorch.org/models/vgg11_bn-6002323d.pthr}   r~   ijr   gHzQ@gp=
sV@r   r   gjt@r   r   Nr   rG   rG   rG   rH   r      r   r   c                	   @   r|   )r   z6https://download.pytorch.org/models/vgg13-19584684.pthr}   r~   i(&r   gZd{Q@g9vOV@r   V-&@gQ@r   r   Nr   rG   rG   rG   rH   r      r   r   c                	   @   r|   )r   z9https://download.pytorch.org/models/vgg13_bn-abd245e5.pthr}   r~   i(=r   g/$Q@g-V@r   r   g=
ףp@r   r   Nr   rG   rG   rG   rH   r      r   r   c                   @   s   e Zd Zedeeddi edddddid	d
ddZedeeddddi 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.pthr}   r~   i(+?r   gSQ@g rV@r   q=
ף.@g|?5^~@r   r   zIhttps://download.pytorch.org/models/vgg16_features-amdegroot-88682ab5.pth)g;pΈ?gN]?g|
?)p?r   r   )r   mean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.
            )r   rp   rz   r   r   r   r{   )rM   rN   rO   r   r   r   r   r   rS   IMAGENET1K_FEATURESr   rG   rG   rG   rH   r      sT    
r   c                	   @   r|   )r   z9https://download.pytorch.org/models/vgg16_bn-6c64b313.pthr}   r~   i(L?r   gףp=
WR@g/$V@r   r   grh~@r   r   Nr   rG   rG   rG   rH   r      r   r   c                	   @   r|   )r   z6https://download.pytorch.org/models/vgg19-dcbb9e9d.pthr}   r~   i(0r   gMbR@gMbV@r   oʡ3@g rh @r   r   Nr   rG   rG   rG   rH   r   
  r   r   c                	   @   r|   )r   z9https://download.pytorch.org/models/vgg19_bn-c79401a0.pthr}   r~   i([r   gˡER@gSV@r   r   g/$!@r   r   Nr   rG   rG   rG   rH   r     r   r   
pretrained)rm   T)rm   rn   c                 K       t | } tdd| |fi |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:
    rh   F)r   verifyrw   rm   rn   ro   rG   rG   rH   r   2     
r   c                 K   r   )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:
    rh   T)r   r   rw   r   rG   rG   rH   r   L  r   r   c                 K   r   )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:
    ri   F)r   r   rw   r   rG   rG   rH   r   f  r   r   c                 K   r   )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:
    ri   T)r   r   rw   r   rG   rG   rH   r     r   r   c                 K   r   )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:
    rj   F)r   r   rw   r   rG   rG   rH   r     r   r   c                 K   r   )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:
    rj   T)r   r   rw   r   rG   rG   rH   r     r   r   c                 K   r   )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:
    rk   F)r   r   rw   r   rG   rG   rH   r      r   r    c                 K   r   )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:
    rk   T)r   r   rw   r   rG   rG   rH   r!     r   r!   )F)6	functoolsr   typingr   r   r   r   rJ   torch.nnr1   transforms._presetsr   utilsr	   _apir   r   r   _metar   _utilsr   r   __all__rP   r   liststrrQ   rR   r4   rc   rl   dict__annotations__rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   rG   rG   rG   rH   <module>   sn    &&"&1*******.