U
    ­Ê¹j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_ÚweightZbiasZ	constant_ÚBatchNorm2dZnormal_)Úselfr&   r'   r(   r)   Úm©Ú	__class__© úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchvision/models/vgg.pyr/   $   s2    





ù	
zVGG.__init__)Úxr*   c                 C   s.   |   |¡}|  |¡}t |d¡}|  |¡}|S )Nr   )r&   r1   ÚtorchÚflattenr4   )r;   rA   r?   r?   r@   ÚforwardA   s
    


zVGG.forward)r$   Tr%   )Ú__name__Ú
__module__Ú__qualname__r0   ÚModuleÚintÚboolÚfloatr/   rB   ZTensorrD   Ú__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   )rQ   ÚpaddingT)Zinplace)r0   Z	MaxPool2dr   rI   r7   r:   r3   r2   )rM   rN   ZlayersZin_channelsÚvZconv2dr?   r?   r@   Úmake_layersI   s    
rT   é@   rP   é€   é   i   )ÚAÚBÚDÚEÚcfgs)rM   rN   Ú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'   )rN   T)r^   Z
check_hash)Úmetar   Úlenr   rT   r\   Zload_state_dictZget_state_dict)rM   rN   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                	   @   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
transformsra   N©	rE   rF   rG   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.pthrh   ri   ièjërk   gHáz®—Q@g¤p=
×sV@rl   rm   gj¼t“®@rn   rs   Nru   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.pthrh   ri   i(&îrk   g¬Zd{Q@g9´Èv¾OV@rl   çV-²�&@g…ëQ¸¸@rn   rs   Nru   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.pthrh   ri   i(=îrk   g/Ý$�åQ@g-²�ï—V@rl   ry   g=
×£p¹@rn   rs   Nru   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.pthrh   ri   i(+?rk   gÙÎ÷SãåQ@gœÄ °r˜V@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   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.
            )ro   r`   rf   rp   rq   rr   rg   )rE   rF   rG   r   r   r
   rv   rw   rK   ZIMAGENET1K_FEATURESrx   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.pthrh   ri   i(L?rk   g×£p=
WR@g/Ý$áV@rl   rz   g°rh‘í~€@rn   rs   Nru   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.pthrh   ri   i(0�rk   gòÒMbR@gòÒMb¸V@rl   çoƒÀÊ¡3@gÅ °rh �@rn   rs   Nru   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.pthrh   ri   i([�rk   gË¡E¶ó�R@gÙÎ÷SãõV@rl   r}   g /Ý$!�@rn   rs   Nru   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:
    rX   F)r   Úverifyrd   ©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:
    rX   T)r   r~   rd   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:
    rY   F)r   r~   rd   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:
    rY   T)r   r~   rd   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:
    rZ   F)r   r~   rd   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:
    rZ   T)r   r~   rd   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:
    r[   F)r   r~   rd   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:
    r[   T)r   r~   rd   r   r?   r?   r@   r#   è  s    
)F)6Ú	functoolsr   Útypingr   r   r   r   r   r   rB   Ztorch.nnr0   Ztransforms._presetsr
   Úutilsr   Z_apir   r   r   Ú_metar   Z_utilsr   r   Ú__all__rH   r   ÚstrrI   rJ   r2   rT   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>   s�     ï&" &,ü"ü1$$$$$$$