a
    d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 g dZG dd dejZdDe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 ed/e%j-fd0dd1d2ee% eeed3d4d5Z.e ed/e&j-fd0dd1d2ee& eeed3d6d7Z/e ed/e'j-fd0dd1d2ee' eeed3d8d9Z0e ed/e(j-fd0dd1d2ee( eeed3d:d;Z1e ed/e)j-fd0dd1d2ee) eeed3d<d=Z2e ed/e*j-fd0dd1d2ee* eeed3d>d?Z3e ed/e+j-fd0dd1d2ee+ eeed3d@dAZ4e ed/e,j-fd0dd1d2ee, eeed3dBdC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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)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__ _/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/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    
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_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      rO      rV   rO      rW   rO   rW   rW   rO   )rT   rT   rO   rU   rU   rO   rV   rV   rO   rW   rW   rO   rW   rW   rO   )rT   rT   rO   rU   rU   rO   rV   rV   rV   rO   rW   rW   rW   rO   rW   rW   rW   rO   )rT   rT   rO   rU   rU   rO   rV   rV   rV   rV   rO   rW   rW   rW   rW   rO   rW   rW   rW   rW   rO   )ABDEcfgs)rL   rM   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'   )rM   )r^   )metar   lenr   rS   r\   Zload_state_dictZget_state_dict)rL   rM   r]   r^   r_   modelr>   r>   r?   _vggb   s    rd   )    re   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                	   @   sB   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urlZ
transformsra   N	rD   rE   rF   r   r   r
   _COMMON_METAIMAGENET1K_V1DEFAULTr>   r>   r>   r?   r   u   s"   
r   c                	   @   sB   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   z9https://download.pytorch.org/models/vgg11_bn-6002323d.pthrh   ri   ijrk   gHzQ@gp=
sV@rl   rm   gjt@rn   rs   Nru   r>   r>   r>   r?   r      s"   
r   c                	   @   sB   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/vgg13-19584684.pthrh   ri   i(&rk   gZd{Q@g9vOV@rl   V-&@gQ@rn   rs   Nru   r>   r>   r>   r?   r      s"   
r   c                	   @   sB   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   z9https://download.pytorch.org/models/vgg13_bn-abd245e5.pthrh   ri   i(=rk   g/$Q@g-V@rl   ry   g=
ףp@rn   rs   Nru   r>   r>   r>   r?   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
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.pthrh   ri   i(+?rk   gSQ@g rV@rl   q=
ף.@g|?5^~@rn   rs   zIhttps://download.pytorch.org/models/vgg16_features-amdegroot-88682ab5.pth)g;pΈ?gN]?g|
?)p?r{   r{   )rj   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.
            )ro   r`   rf   rp   rq   rr   rg   )rD   rE   rF   r   r   r
   rv   rw   rJ   ZIMAGENET1K_FEATURESrx   r>   r>   r>   r?   r      sR   
r   c                	   @   sB   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   z9https://download.pytorch.org/models/vgg16_bn-6c64b313.pthrh   ri   i(L?rk   gףp=
WR@g/$V@rl   rz   grh~@rn   rs   Nru   r>   r>   r>   r?   r      s"   
r   c                	   @   sB   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/vgg19-dcbb9e9d.pthrh   ri   i(0rk   gMbR@gMbV@rl   oʡ3@g rh @rn   rs   Nru   r>   r>   r>   r?   r   
  s"   
r   c                	   @   sB   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   z9https://download.pytorch.org/models/vgg19_bn-c79401a0.pthrh   ri   i([rk   gˡER@gSV@rl   r~   g/$!@rn   rs   Nru   r>   r>   r>   r?   r     s"   
r   Z
pretrained)r]   T)r]   r^   )r]   r^   r_   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:
    rX   F)r   verifyrd   r]   r^   r_   r>   r>   r?   r   2  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:
    rX   T)r   r   rd   r   r>   r>   r?   r   L  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:
    rY   F)r   r   rd   r   r>   r>   r?   r   f  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:
    rY   T)r   r   rd   r   r>   r>   r?   r     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:
    rZ   F)r   r   rd   r   r>   r>   r?   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:
    rZ   T)r   r   rd   r   r>   r>   r?   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:
    r[   F)r   r   rd   r   r>   r>   r?   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:
    r[   T)r   r   rd   r   r>   r>   r?   r#     s    
r#   )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__rd   rv   r   r   r   r   r   r   r   r   rw   r   r   r   r   r    r!   r"   r#   r>   r>   r>   r?   <module>   sl    &""1$$$$$$$