a
    PSicJ                  
   @   sp  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 g dZG dd dejZdFeeeef  eejdddZg dg dg dg d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 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-d. d.eZ+ed/e$j,fd0dd1d2ee$ eeed3d4d5Z-ed/e%j,fd0dd1d2ee% eeed3d6d7Z.ed/e&j,fd0dd1d2ee& eeed3d8d9Z/ed/e'j,fd0dd1d2ee' eeed3d:d;Z0ed/e(j,fd0dd1d2ee( eeed3d<d=Z1ed/e)j,fd0dd1d2ee) eeed3d>d?Z2ed/e*j,fd0dd1d2ee* eeed3d@dAZ3ed/e+j,fd0dd1d2ee+ eeed3dBdC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 u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)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__ R/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/models/vgg.pyr1   $   s2    





	
zVGG.__init__)xr)   c                 C   s.   |  |}| |}t|d}| |}|S )Nr   )r%   r4   torchflattenr9   )rD   rJ   rH   rH   rI   forwardA   s
    


zVGG.forward)r#   Tr$   )__name__
__module____qualname__r2   Moduleintboolfloatr1   rK   TensorrM   __classcell__rH   rH   rF   rI   r   #   s    
r   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_sizestrider   )r[   paddingT)inplace)r2   	MaxPool2dr   rR   r<   rB   r7   r5   )rW   rX   layersin_channelsvconv2drH   rH   rI   make_layersI   s    
rd   )@   rZ      rZ      rg   rZ      rh   rZ   rh   rh   rZ   )re   re   rZ   rf   rf   rZ   rg   rg   rZ   rh   rh   rZ   rh   rh   rZ   )re   re   rZ   rf   rf   rZ   rg   rg   rg   rZ   rh   rh   rh   rZ   rh   rh   rh   rZ   )re   re   rZ   rf   rf   rZ   rg   rg   rg   rg   rZ   rh   rh   rh   rh   rZ   rh   rh   rh   rh   rZ   )ABDEcfgs)rW   rX   weightsprogresskwargsr)   c                 K   sn   |d ur4d|d< |j d d ur4t|dt|j d  ttt|  |dfi |}|d urj||j|d |S )NFr'   
categoriesr&   )rX   )ro   )metar   lenr   rd   rm   load_state_dictget_state_dict)rW   rX   rn   ro   rp   modelrH   rH   rI   _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_sizerq   recipe_docsc                	   @   s>   e Zd Zedeeddi 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url
transformsrr   N	rN   rO   rP   r   r   r
   _COMMON_METAIMAGENET1K_V1DEFAULTrH   rH   rH   rI   r   u   s   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z9https://download.pytorch.org/models/vgg11_bn-6002323d.pthr|   r}   ijr   gHzQ@gp=
sV@r   r   r   Nr   rH   rH   rH   rI   r      s   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z6https://download.pytorch.org/models/vgg13-19584684.pthr|   r}   i(&r   gZd{Q@g9vOV@r   r   r   Nr   rH   rH   rH   rI   r      s   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z9https://download.pytorch.org/models/vgg13_bn-abd245e5.pthr|   r}   i(=r   g/$Q@g-V@r   r   r   Nr   rH   rH   rH   rI   r      s   
r   c                   @   s~   e Zd Zedeeddi edddddi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
Z	eZ
dS )r   z6https://download.pytorch.org/models/vgg16-397923af.pthr|   r}   i(+?r   gSQ@g rV@r   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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.
            )r   rq   rz   r   r{   )rN   rO   rP   r   r   r
   r   r   rT   ZIMAGENET1K_FEATURESr   rH   rH   rH   rI   r      sJ   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z9https://download.pytorch.org/models/vgg16_bn-6c64b313.pthr|   r}   i(L?r   gףp=
WR@g/$V@r   r   r   Nr   rH   rH   rH   rI   r      s   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z6https://download.pytorch.org/models/vgg19-dcbb9e9d.pthr|   r}   i(0r   gMbR@gMbV@r   r   r   Nr   rH   rH   rH   rI   r      s   
r   c                	   @   s>   e Zd Zedeeddi edddddid	d
ZeZdS )r   z9https://download.pytorch.org/models/vgg19_bn-c79401a0.pthr|   r}   i([r   gˡER@gSV@r   r   r   Nr   rH   rH   rH   rI   r     s   
r   
pretrained)rn   T)rn   ro   )rn   ro   rp   r)   c                 K   s    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:
    ri   F)r   verifyrw   rn   ro   rp   rH   rH   rI   r      s    
r   c                 K   s    t | } tdd| |fi |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:
    ri   T)r   r   rw   r   rH   rH   rI   r   9  s    
r   c                 K   s    t | } tdd| |fi |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:
    rj   F)r   r   rw   r   rH   rH   rI   r   R  s    
r   c                 K   s    t | } tdd| |fi |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:
    rj   T)r   r   rw   r   rH   rH   rI   r   k  s    
r   c                 K   s    t | } tdd| |fi |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:
    rk   F)r   r   rw   r   rH   rH   rI   r     s    
r   c                 K   s    t | } tdd| |fi |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:
    rk   T)r   r   rw   r   rH   rH   rI   r      s    
r    c                 K   s    t | } tdd| |fi |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:
    rl   F)r   r   rw   r   rH   rH   rI   r!     s    
r!   c                 K   s    t | } tdd| |fi |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:
    rl   T)r   r   rw   r   rH   rH   rI   r"     s    
r"   )
_ModelURLs)r   r   r   r!   r   r   r    r"   )F)8	functoolsr   typingr   r   r   r   r   r   rK   torch.nnr2   Ztransforms._presetsr
   utilsr   _apir   r   _metar   _utilsr   r   __all__rQ   r   strrR   rS   r5   rd   rm   __annotations__rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r   r   
model_urlsrH   rH   rH   rI   <module>   st    &""-""""""""