o
    ôjî%  ã                   @   s  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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mZ g d¢ZG dd„ dejƒZG dd„ dejƒZddedœ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"dS )!é    )Úpartial)ÚAnyÚCallableÚListÚOptionalN)ÚnnÚTensoré   )ÚConv2dNormActivation)ÚImageClassification)Ú_log_api_usage_onceé   )Úregister_modelÚWeightsÚWeightsEnum)Ú_IMAGENET_CATEGORIES)Ú_make_divisibleÚ_ovewrite_named_paramÚhandle_legacy_interface)ÚMobileNetV2ÚMobileNet_V2_WeightsÚmobilenet_v2c                       sZ   e Zd Z	ddededededeedejf  ddf‡ fd	d
„Zde	de	fdd„Z
‡  ZS )ÚInvertedResidualNÚinpÚoupÚstrideÚexpand_ratioÚ
norm_layer.Úreturnc                    sÖ   t ƒ  ¡  || _|dvrtd|› �ƒ‚|d u rtj}tt|| ƒƒ}| jdko*||k| _g }|dkr?| 	t
||d|tjd�¡ | t
|||||tjd�tj||ddddd�||ƒg¡ tj|Ž | _|| _|dk| _d S )	N)r   r	   z#stride should be 1 or 2 instead of r   ©Úkernel_sizer   Úactivation_layer)r   Úgroupsr   r!   r   F)Úbias)ÚsuperÚ__init__r   Ú
ValueErrorr   ÚBatchNorm2dÚintÚroundÚuse_res_connectÚappendr
   ÚReLU6ÚextendÚConv2dÚ
SequentialÚconvÚout_channelsZ_is_cn)Úselfr   r   r   r   r   Ú
hidden_dimÚlayers©Ú	__class__© úo/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/models/mobilenetv2.pyr%      s:   
ÿú	ôÿzInvertedResidual.__init__Úxc                 C   s   | j r
||  |¡ S |  |¡S ©N)r*   r0   ©r2   r9   r7   r7   r8   Úforward<   s   
zInvertedResidual.forwardr:   )Ú__name__Ú
__module__Ú__qualname__r(   r   r   r   ÚModuler%   r   r<   Ú__classcell__r7   r7   r5   r8   r      s     ÿÿÿÿÿÿþ(r   c                       sš   e Zd Z							ddededeeee   d	ed
eedej	f  deedej	f  de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   éè  ç      ð?Né   çš™™™™™É?Únum_classesÚ
width_multÚinverted_residual_settingÚround_nearestÚblock.r   Údropoutr   c                    s  t ƒ  ¡  t| ƒ |du rt}|du rtj}d}d}	|du r5g d¢g d¢g d¢g d¢g d¢g d	¢g d
¢g}t|ƒdksCt|d ƒdkrJtd|› �ƒ‚t|| |ƒ}t|	t	d|ƒ |ƒ| _
td|d|tjd�g}
|D ]*\}}}}t|| |ƒ}t|ƒD ]}|dkr‚|nd}|
 ||||||d�¡ |}qzqi|
 t|| j
d|tjd�¡ tj|
Ž | _t tj|d�t | j
|¡¡| _|  ¡ D ]M}t|tjƒrÚtjj|jdd� |jdurÙtj |j¡ q¼t|tjtjfƒròtj |j¡ tj |j¡ q¼t|tjƒ�r	tj |jdd¡ tj |j¡ q¼dS )aw  
        MobileNet V2 main class

        Args:
            num_classes (int): Number of classes
            width_mult (float): Width multiplier - adjusts number of channels in each layer by this amount
            inverted_residual_setting: Network structure
            round_nearest (int): Round the number of channels in each layer to be a multiple of this number
            Set to 1 to turn off rounding
            block: Module specifying inverted residual building block for mobilenet
            norm_layer: Module specifying the normalization layer to use
            dropout (float): The droupout probability

        Né    i   )r   é   r   r   )é   é   r	   r	   )rN   rL   é   r	   )rN   é@   é   r	   )rN   é`   rP   r   )rN   é    rP   r	   )rN   i@  r   r   r   rR   zGinverted_residual_setting should be non-empty or a 4-element list, got rC   rP   r	   )r   r   r!   r   )r   r   r   )ÚpÚfan_out)Úmodeg{®Gáz„?)r$   r%   r   r   r   r'   Úlenr&   r   ÚmaxÚlast_channelr
   r,   Úranger+   r/   ÚfeaturesÚDropoutÚLinearÚ
classifierÚmodulesÚ
isinstancer.   ÚinitÚkaiming_normal_Úweightr#   Úzeros_Ú	GroupNormÚones_Únormal_)r2   rF   rG   rH   rI   rJ   r   rK   Úinput_channelrZ   r\   ÚtÚcÚnÚsÚoutput_channelÚir   Úmr5   r7   r8   r%   D   sp   
øÿÿýÿÿ
þ
€€özMobileNetV2.__init__r9   c                 C   s2   |   |¡}tj |d¡}t |d¡}|  |¡}|S )N©r   r   r   )r\   r   Ú
functionalÚadaptive_avg_pool2dÚtorchÚflattenr_   r;   r7   r7   r8   Ú_forward_impl£   s
   

zMobileNetV2._forward_implc                 C   s
   |   |¡S r:   )rv   r;   r7   r7   r8   r<   ­   s   
zMobileNetV2.forward)rB   rC   NrD   NNrE   )r=   r>   r?   r(   Úfloatr   r   r   r   r@   r%   r   rv   r<   rA   r7   r7   r5   r8   r   C   s6    øþýüûúùø	÷_
r   ièz5 rq   )Ú
num_paramsÚmin_sizeÚ
categoriesc                
   @   sz   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deeddd�i e¥dddddœid	dddœ¥d�ZeZ	dS )r   z=https://download.pytorch.org/models/mobilenet_v2-b0353104.pthéà   )Ú	crop_sizezQhttps://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2zImageNet-1KgÕxé&1øQ@gü©ñÒM’V@)zacc@1zacc@5gÝ$�•CÓ?g\�Âõ(+@zXThese weights reproduce closely the results of the paper using a simple training recipe.)ÚrecipeÚ_metricsÚ_opsÚ
_file_sizeÚ_docs)ÚurlÚ
transformsÚmetaz=https://download.pytorch.org/models/mobilenet_v2-7ebf99e0.pthéè   )r|   Úresize_sizezHhttps://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuningg`åÐ"Û	R@gøSã¥›´V@gV-2+@a$  
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            N)
r=   r>   r?   r   r   r   Ú_COMMON_METAÚIMAGENET1K_V1ÚIMAGENET1K_V2ÚDEFAULTr7   r7   r7   r8   r   ¸   sH    
ÿþÿõýÿþÿõýr   Ú
pretrained)ÚweightsT)rŒ   ÚprogressrŒ   r�   Úkwargsr   c                 K   sV   t  | ¡} | durt|dt| jd ƒƒ tdi |¤Ž}| dur)| | j|dd�¡ |S )a±  MobileNetV2 architecture from the `MobileNetV2: Inverted Residuals and Linear
    Bottlenecks <https://arxiv.org/abs/1801.04381>`_ paper.

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

    .. autoclass:: torchvision.models.MobileNet_V2_Weights
        :members:
    NrF   rz   T)r�   Ú
check_hashr7   )r   Úverifyr   rX   r„   r   Úload_state_dictÚget_state_dict)rŒ   r�   rŽ   Úmodelr7   r7   r8   r   â   s   
r   )#Ú	functoolsr   Útypingr   r   r   r   rt   r   r   Zops.miscr
   Ztransforms._presetsr   Úutilsr   Ú_apir   r   r   Ú_metar   Ú_utilsr   r   r   Ú__all__r@   r   r   r‡   r   rˆ   Úboolr   r7   r7   r7   r8   Ú<module>   s<    0oý*ÿÿÿÿþ