o
    ôjT<  ã                   @   s0  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 dd	lmZmZmZ dd
lmZ ddlmZmZ g d¢Zde
dede
fdd„ZG dd„ de	jƒZG dd„ de	jƒZdee dedededef
dd„Zde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$eƒ ed'e!j%fd(�dd)d*œdee! dededefd+d,„ƒƒZ&eƒ ed'e"j%fd(�dd)d*œdee" dededefd-d.„ƒƒZ'eƒ ed'e#j%fd(�dd)d*œdee# dededefd/d0„ƒƒZ(eƒ ed'e$j%fd(�dd)d*œdee$ dededefd1d2„ƒƒZ)dS )3é    )Úpartial)ÚAnyÚCallableÚListÚOptionalN)ÚTensoré   )ÚImageClassification)Ú_log_api_usage_onceé   )Úregister_modelÚWeightsÚWeightsEnum)Ú_IMAGENET_CATEGORIES)Ú_ovewrite_named_paramÚhandle_legacy_interface)	ÚShuffleNetV2ÚShuffleNet_V2_X0_5_WeightsÚShuffleNet_V2_X1_0_WeightsÚShuffleNet_V2_X1_5_WeightsÚShuffleNet_V2_X2_0_WeightsÚshufflenet_v2_x0_5Úshufflenet_v2_x1_0Úshufflenet_v2_x1_5Úshufflenet_v2_x2_0ÚxÚgroupsÚreturnc                 C   sP   |   ¡ \}}}}|| }|  |||||¡} t | dd¡ ¡ } |  ||||¡} | S )Nr   r   )ÚsizeÚviewÚtorchÚ	transposeÚ
contiguous)r   r   Z	batchsizeÚnum_channelsÚheightÚwidthZchannels_per_group© r&   úp/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/models/shufflenetv2.pyÚchannel_shuffle   s   r(   c                       sp   e Zd Zdedededdf‡ fdd„Ze	
ddededededededejfdd„ƒZ	de
de
fdd„Z‡  ZS )ÚInvertedResidualÚinpÚoupÚstrider   Nc                    sT  t ƒ  ¡  d|  krdkstdƒ‚ tdƒ‚|| _|d }| jdkr7||d> kr7td|› d|› d|› d�ƒ‚| jdkrct | j||d| jdd	�t |¡tj||ddd
dd�t |¡tj	dd�¡| _
nt ¡ | _
t tj| jdkrs|n||ddd
dd�t |¡tj	dd�| j||d| jdd	�t |¡tj||ddd
dd�t |¡tj	dd�¡| _d S )Nr   é   zillegal stride valuer   zInvalid combination of stride z, inp z	 and oup zB values. If stride == 1 then inp should be equal to oup // 2 << 1.©Úkernel_sizer,   Úpaddingr   F)r/   r,   r0   ÚbiasT©Úinplace)ÚsuperÚ__init__Ú
ValueErrorr,   ÚnnÚ
SequentialÚdepthwise_convÚBatchNorm2dÚConv2dÚReLUÚbranch1Úbranch2)Úselfr*   r+   r,   Zbranch_features©Ú	__class__r&   r'   r5   ,   sJ   
ÿÿ

û
ú


ñzInvertedResidual.__init__r   r   FÚiÚor/   r0   r1   c              	   C   s   t j| |||||| d�S )N)r1   r   )r7   r;   )rB   rC   r/   r,   r0   r1   r&   r&   r'   r9   V   s   zInvertedResidual.depthwise_convr   c                 C   sb   | j dkr|jddd�\}}tj||  |¡fdd�}ntj|  |¡|  |¡fdd�}t|dƒ}|S )Nr   r   )Údim)r,   Úchunkr    Úcatr>   r=   r(   )r?   r   Úx1Úx2Úoutr&   r&   r'   Úforward\   s   

zInvertedResidual.forward)r   r   F)Ú__name__Ú
__module__Ú__qualname__Úintr5   ÚstaticmethodÚboolr7   r;   r9   r   rJ   Ú__classcell__r&   r&   r@   r'   r)   +   s(    *ÿÿÿÿÿÿÿþr)   c                       sn   e Zd Zdefdee dee dededejf ddf
‡ fd	d
„Z	de
de
fdd„Zde
de
fdd„Z‡  ZS )r   iè  Ústages_repeatsÚstages_out_channelsÚnum_classesÚinverted_residual.r   Nc              
      sd  t ƒ  ¡  t| ƒ t|ƒdkrtdƒ‚t|ƒdkrtdƒ‚|| _d}| jd }t tj||ddddd	�t 	|¡tj
d
d�¡| _|}tjdddd�| _|  |  |  dd„ dD ƒ}t||| jdd … ƒD ])\}}	}|||dƒg}
t|	d ƒD ]}|
 |||dƒ¡ qtt| |tj|
Ž ƒ |}qb| jd }t tj||ddddd	�t 	|¡tj
d
d�¡| _t ||¡| _d S )Nr-   z2expected stages_repeats as list of 3 positive intsé   z7expected stages_out_channels as list of 5 positive intsr   r   r   F)r1   Tr2   r.   c                 S   s   g | ]}d |› �‘qS )Ústager&   )Ú.0rB   r&   r&   r'   Ú
<listcomp>ˆ   s    z)ShuffleNetV2.__init__.<locals>.<listcomp>)r   r-   é   éÿÿÿÿ)r4   r5   r
   Úlenr6   Z_stage_out_channelsr7   r8   r;   r:   r<   Úconv1Ú	MaxPool2dÚmaxpoolÚzipÚrangeÚappendÚsetattrÚconv5ÚLinearÚfc)r?   rR   rS   rT   rU   Úinput_channelsZoutput_channelsÚstage_namesÚnameÚrepeatsÚseqrB   r@   r&   r'   r5   i   sB   


ý 

ýzShuffleNetV2.__init__r   c                 C   sX   |   |¡}|  |¡}|  |¡}|  |¡}|  |¡}|  |¡}| ddg¡}|  |¡}|S )Nr   r-   )r]   r_   Zstage2Zstage3Zstage4rd   Úmeanrf   ©r?   r   r&   r&   r'   Ú_forward_impl™   s   






zShuffleNetV2._forward_implc                 C   s
   |   |¡S )N)rn   rm   r&   r&   r'   rJ   ¥   s   
zShuffleNetV2.forward)rK   rL   rM   r)   r   rN   r   r7   ÚModuler5   r   rn   rJ   rQ   r&   r&   r@   r'   r   h   s     ûþýüûú0r   ÚweightsÚprogressÚargsÚkwargsc                 O   sL   | d urt |dt| jd ƒƒ t|i |¤Ž}| d ur$| | j|dd�¡ |S )NrT   Ú
categoriesT)rq   Ú
check_hash)r   r\   Úmetar   Úload_state_dictÚget_state_dict)rp   rq   rr   rs   Úmodelr&   r&   r'   Ú_shufflenetv2©   s   rz   )r   r   z2https://github.com/ericsun99/Shufflenet-v2-Pytorch)Úmin_sizert   Úrecipec                
   @   óD   e Zd Zedeedd�i e¥dddddœid	d
ddœ¥d�ZeZdS )r   zDhttps://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pthéà   ©Ú	crop_sizeiÛ úImageNet-1Kg-²�ï§FN@g9´Èv¾oT@©zacc@1zacc@5g{®Gáz¤?gTã¥›Ä @úVThese weights were trained from scratch to reproduce closely the results of the paper.©Ú
num_paramsÚ_metricsÚ_opsÚ
_file_sizeÚ_docs©ÚurlÚ
transformsrv   N©	rK   rL   rM   r   r   r	   Ú_COMMON_METAÚIMAGENET1K_V1ÚDEFAULTr&   r&   r&   r'   r   Á   ó&    
ÿþÿõür   c                
   @   r}   )r   zBhttps://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pthr~   r   iÌÄ" r�   gºI+WQ@gNbX9V@r‚   g�Âõ(\�Â?g¢E¶óý”!@rƒ   r„   rŠ   Nr�   r&   r&   r&   r'   r   ×   r‘   r   c                   @   óH   e Zd Zedeeddd�i e¥ddddd	d
œiddddœ¥d�ZeZdS )r   zBhttps://download.pytorch.org/models/shufflenetv2_x1_5-3c479a10.pthr~   éè   ©r€   Úresize_sizeú+https://github.com/pytorch/vision/pull/5906iv5 r�   g9´Èv¾?R@g/Ý$�ÅV@r‚   g‹lçû©ñÒ?gw¾Ÿ/+@úé
                These weights were trained from scratch by using TorchVision's `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            ©r|   r…   r†   r‡   rˆ   r‰   rŠ   Nr�   r&   r&   r&   r'   r   í   ó(    ÿþÿôýr   c                   @   r’   )r   zBhttps://download.pytorch.org/models/shufflenetv2_x2_0-8be3c8ee.pthr~   r“   r”   r–   iÌÒp r�   g…ëQ¸S@gªñÒMb@W@r‚   g-²�ï§â?g+‡Ùn<@r—   r˜   rŠ   Nr�   r&   r&   r&   r'   r     r™   r   Ú
pretrained)rp   T)rp   rq   c                 K   ó(   t  | ¡} t| |g d¢g d¢fi |¤ŽS )a  
    Constructs a ShuffleNetV2 architecture with 0.5x output channels, as described in
    `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
    <https://arxiv.org/abs/1807.11164>`__.

    Args:
        weights (:class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ShuffleNet_V2_X0_5_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.shufflenetv2.ShuffleNetV2``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ShuffleNet_V2_X0_5_Weights
        :members:
    ©rZ   é   rZ   )é   é0   é`   éÀ   é   )r   Úverifyrz   ©rp   rq   rs   r&   r&   r'   r     ó   
r   c                 K   r›   )a  
    Constructs a ShuffleNetV2 architecture with 1.0x output channels, as described in
    `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
    <https://arxiv.org/abs/1807.11164>`__.

    Args:
        weights (:class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ShuffleNet_V2_X1_0_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.shufflenetv2.ShuffleNetV2``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ShuffleNet_V2_X1_0_Weights
        :members:
    rœ   )rž   ét   r“   iÐ  r¢   )r   r£   rz   r¤   r&   r&   r'   r   >  r¥   r   c                 K   r›   )a  
    Constructs a ShuffleNetV2 architecture with 1.5x output channels, as described in
    `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
    <https://arxiv.org/abs/1807.11164>`__.

    Args:
        weights (:class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ShuffleNet_V2_X1_5_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.shufflenetv2.ShuffleNetV2``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ShuffleNet_V2_X1_5_Weights
        :members:
    rœ   )rž   é°   i`  iÀ  r¢   )r   r£   rz   r¤   r&   r&   r'   r   ]  r¥   r   c                 K   r›   )a  
    Constructs a ShuffleNetV2 architecture with 2.0x output channels, as described in
    `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
    <https://arxiv.org/abs/1807.11164>`__.

    Args:
        weights (:class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ShuffleNet_V2_X2_0_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.shufflenetv2.ShuffleNetV2``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ShuffleNet_V2_X2_0_Weights
        :members:
    rœ   )rž   éô   iè  iÐ  i   )r   r£   rz   r¤   r&   r&   r'   r   |  r¥   r   )*Ú	functoolsr   Útypingr   r   r   r   r    Útorch.nnr7   r   Ztransforms._presetsr	   Úutilsr
   Ú_apir   r   r   Ú_metar   Ú_utilsr   r   Ú__all__rN   r(   ro   r)   r   rP   rz   rŽ   r   r   r   r   r�   r   r   r   r   r&   r&   r&   r'   Ú<module>   s¢    =Aÿþýü
ûýÿÿÿÿþÿÿÿÿþÿÿÿÿþÿÿÿÿþ