
    hD                        S SK r S SKJr  S SKJrJr  S SKrS SKJr  S SKJ	r	  SSK
Jr  SSKJr  SS	KJrJrJr  SS
KJr  SSKJrJr  / SQrSr " S S\R2                  5      rS\S\S\S\S\S\S\S\R:                  4S jrS8S\S\S\S\4S jjrS\S\ \   4S jr! " S S \R                  R2                  5      r"S!\S"S#.r# " S$ S%\5      r$ " S& S'\5      r% " S( S)\5      r& " S* S+\5      r'S\S,\\   S-\(S.\S\"4
S/ jr)\" 5       \" S0\$RT                  4S19SS2S3.S,\\$   S-\(S.\S\"4S4 jj5       5       r+\" 5       \" S0\%RT                  4S19SS2S3.S,\\%   S-\(S.\S\"4S5 jj5       5       r,\" 5       \" S0\&RT                  4S19SS2S3.S,\\&   S-\(S.\S\"4S6 jj5       5       r-\" 5       \" S0\'RT                  4S19SS2S3.S,\\'   S-\(S.\S\"4S7 jj5       5       r.g)9    N)partial)AnyOptional)Tensor   )ImageClassification)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)	MNASNetMNASNet0_5_WeightsMNASNet0_75_WeightsMNASNet1_0_WeightsMNASNet1_3_Weights
mnasnet0_5mnasnet0_75
mnasnet1_0
mnasnet1_3g 0U0*3?c                   `   ^  \ rS rSr SS\S\S\S\S\S\SS	4U 4S
 jjjrS\S\4S jrSr	U =r
$ )_InvertedResidual"   in_chout_chkernel_sizestrideexpansion_factorbn_momentumreturnNc                   > [         TU ]  5         US;  a  [        SU 35      eUS;  a  [        SU 35      eX-  nX:H  =(       a    US:H  U l        [        R
                  " [        R                  " XSSS9[        R                  " XvS9[        R                  " S	S
9[        R                  " XwX3S-  XGSS9[        R                  " XvS9[        R                  " S	S
9[        R                  " XrSSS9[        R                  " X&S95      U l	        g )Nr
   r   z#stride should be 1 or 2 instead of )      z(kernel_size should be 3 or 5 instead of r
   F)biasmomentumTinplacer   paddingr    groupsr(   )
super__init__
ValueErrorapply_residualnn
SequentialConv2dBatchNorm2dReLUlayers)	selfr   r   r   r    r!   r"   mid_ch	__class__s	           R/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/mnasnet.pyr1   _InvertedResidual.__init__#   s     	B6(KLLf$G}UVV)#o=&A+mmIIeQU3NN68GGD!IIfk!;KTZpuvNN68GGD!IIfae4NN68
    inputc                 n    U R                   (       a  U R                  U5      U-   $ U R                  U5      $ )Nr3   r9   )r:   r@   s     r=   forward_InvertedResidual.forward;   s.    ;;u%--;;u%%r?   rB   )g?)__name__
__module____qualname____firstlineno__intfloatr1   r   rC   __static_attributes____classcell__r<   s   @r=   r   r   "   s`    ru

"%
47
AD
X[
jo
	
 
0&V & & &r?   r   r   r   r   r    
exp_factorrepeatsr"   r#   c                     US:  a  [        SU 35      e[        XX#XFS9n/ n[        SU5       H  n	UR                  [        XUSXFS95        M      [        R
                  " U/UQ76 $ )z&Creates a stack of inverted residuals.r
   z$repeats should be >= 1, instead got )r"   )r2   r   rangeappendr4   r5   )
r   r   r   r    rN   rO   r"   first	remaining_s
             r=   _stackrV   B   sp     {?yIJJe[*fEI1g*6;:op ==+++r?   valdivisorround_up_biasc                     SUs=:  a  S:  d  O  [        SU 35      e[        U[        XS-  -   5      U-  U-  5      nX2U -  :  a  U$ X1-   $ )zAsymmetric rounding to make `val` divisible by `divisor`. With default
bias, will round up, unless the number is no more than 10% greater than the
smaller divisible value, i.e. (83, 8) -> 80, but (84, 8) -> 88.              ?zIround_up_bias should be greater than 0.0 and smaller than 1.0 instead of r   )r2   maxrI   )rW   rX   rY   new_vals       r=   _round_to_multiple_ofr_   P   s`     $$derdstuu'3sq[01W<wFGG!447K':KKr?   alphac                 R    / SQnU Vs/ s H  n[        X -  S5      PM     sn$ s  snf )zZScales tensor depths as in reference MobileNet code, prefers rounding up
rather than down.)          (   P   `      i@     )r_   )r`   depthsdepths      r=   _get_depthsrl   Z   s+     0FAGH!%-3HHHs   $c                      ^  \ rS rSrSrSrSS\S\S\SS4U 4S	 jjjrS
\	S\	4S jr
S\S\S\S\S\\   S\\   S\\   SS4U 4S jjrSrU =r$ )r   a   zMNASNet, as described in https://arxiv.org/abs/1807.11626. This
implements the B1 variant of the model.
>>> model = MNASNet(1.0, num_classes=1000)
>>> x = torch.rand(1, 3, 224, 224)
>>> y = model(x)
>>> y.dim()
2
>>> y.nelement()
1000
r   r`   num_classesdropoutr#   Nc                   > [         TU ]  5         [        U 5        US::  a  [        SU 35      eXl        X l        [        U5      n[        R                  " SUS   SSSSS9[        R                  " US   [        S	9[        R                  " S
S9[        R                  " US   US   SSSUS   SS9[        R                  " US   [        S	9[        R                  " S
S9[        R                  " US   US   SSSSS9[        R                  " US   [        S	9[        US   US   SSSS[        5      [        US   US   SSSS[        5      [        US   US   SSSS[        5      [        US   US   SSSS[        5      [        US   US   SSSS[        5      [        US   US   SSSS[        5      [        R                  " US   SSSSSS9[        R                  " S[        S	9[        R                  " S
S9/n[        R                  " U6 U l        [        R                  " [        R                  " US
S9[        R                   " SU5      5      U l        U R%                  5        GHm  n['        U[        R                  5      (       ac  [        R(                  R+                  UR,                  SSS9  UR.                  b+  [        R(                  R1                  UR.                  5        M  M  ['        U[        R                  5      (       aT  [        R(                  R3                  UR,                  5        [        R(                  R1                  UR.                  5        M  ['        U[        R                   5      (       d  GM  [        R(                  R5                  UR,                  SSS9  [        R(                  R1                  UR.                  5        GMp     g )Nr[   z,alpha should be greater than 0.0 instead of r&   r   r
   r   Fr.   r    r(   r)   Tr+   r-   r'            i   )pr,   fan_outrelu)modenonlinearitysigmoid)r0   r1   r	   r2   r`   ro   rl   r4   r6   r7   _BN_MOMENTUMr8   rV   r5   r9   DropoutLinear
classifiermodules
isinstanceinitkaiming_normal_weightr(   zeros_ones_kaiming_uniform_)r:   r`   ro   rp   rj   r9   mr<   s          r=   r1   MNASNet.__init__p   s   D!C<KE7STT
&U# IIaAqGNN6!9|<GGD!IIfQiAq6RS9[`aNN6!9|<GGD!IIfQiAqONN6!9|<6!9fQiAq!\B6!9fQiAq!\B6!9fQiAq!\B6!9fQiAq!\B6!9fQiAq!\B6!9fQiAq!\BIIfQiq!AEJNN4,7GGD!+
. mmV,--

Wd(KRYYW[]hMijA!RYY''''yv'V66%GGNN166* &Ar~~..ahh'qvv&Aryy))((	PY(Zqvv&  r?   xc                 l    U R                  U5      nUR                  SS/5      nU R                  U5      $ )Nr   r&   )r9   meanr   )r:   r   s     r=   rC   MNASNet.forward   s/    KKNFFAq6Nq!!r?   
state_dictprefixlocal_metadatastrictmissing_keysunexpected_keys
error_msgsc                   > UR                  SS 5      nUS;  a  [        SU 35      eUS:X  Ga:  U R                  S:X  Gd)  [        U R                  5      n	[        R
                  " SSSSSS	S
9[        R                  " S[        S9[        R                  " SS9[        R
                  " SSSSSSS	S9[        R                  " S[        S9[        R                  " SS9[        R
                  " SSSSSS	S
9[        R                  " S[        S9[        SU	S   SSSS[        5      /	n
[        U
5       H  u  pXR                  U'   M     SU l        [        R                  " S[        5        [         TU ]E  XX4XVU5        g )Nversionr%   z+version shluld be set to 1 or 2 instead of r
   r\   r&   rb   r   Frr   r)   Tr+   r-   rc   r   a  A new version of MNASNet model has been implemented. Your checkpoint was saved using the previous version. This checkpoint will load and work as before, but you may want to upgrade by training a newer model or transfer learning from an updated ImageNet checkpoint.)getr2   r`   rl   r4   r6   r7   r|   r8   rV   	enumerater9   _versionwarningswarnUserWarningr0   _load_from_state_dict)r:   r   r   r   r   r   r   r   r   rj   v1_stemidxlayerr<   s                r=   r   MNASNet._load_from_state_dict   sQ    !$$Y5& J7)TUUa<

c 1
 !,F		!RAaeDrL9%		"b!Qq%PrL9%		"b!QquErL9r6!9aAq,?
G (0
#(C  1 DMMMI
  	%Wa	
r?   )r   r`   r   r9   ro   )i  g?)rE   rF   rG   rH   __doc__r   rJ   rI   r1   r   rC   dictstrboollistr   rK   rL   rM   s   @r=   r   r   a   s    	 H,'e ,'# ,'u ,'W[ ,' ,'\" "F "/
/
 /
 	/

 /
 3i/
 c/
 I/
 
/
 /
r?   r   )r
   r
   z(https://github.com/1e100/mnasnet_trainer)min_size
categoriesrecipec                   P    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SSS.ES9r\r	Sr
g)r      zIhttps://download.pytorch.org/models/mnasnet0.5_top1_67.823-3ffadce67e.pth   	crop_sizei! ImageNet-1Kg"P@g(\U@zacc@1zacc@5g9v?g;O.!@9These weights reproduce closely the results of the paper.
num_params_metrics_ops
_file_size_docsurl
transformsmeta NrE   rF   rG   rH   r   r   r   _COMMON_METAIMAGENET1K_V1DEFAULTrK   r   r?   r=   r   r      sT    W.#>

!##  T
M" Gr?   r   c                   T    \ rS rSr\" S\" \SSS90 \ESSSS	S
S.0SSSS.ES9r\r	Sr
g)r      z<https://download.pytorch.org/models/mnasnet0_75-7090bc5f.pthr      r   resize_size+https://github.com/pytorch/vision/pull/6019i_0 r   gQQ@g9vV@r   gQ?gB`"(@
                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   r   Nr   r   r?   r=   r   r      s[    J.#3O

C!##   
M* Gr?   r   c                   P    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SSS.ES9r\r	Sr
g)r   i  zIhttps://download.pytorch.org/models/mnasnet1.0_top1_73.512-f206786ef8.pthr   r   iPB r   gw/]R@gq=
ףV@r   gjt?g
ףp=0@r   r   r   r   Nr   r   r?   r=   r   r     sT    W.#>

!##   T
M" Gr?   r   c                   T    \ rS rSr\" S\" \SSS90 \ESSSS	S
S.0SSSS.ES9r\r	Sr
g)r   i   z;https://download.pytorch.org/models/mnasnet1_3-a4c69d6f.pthr   r   r   r   i_ r   gMb S@g rhaW@r   gE?g">8@r   r   r   r   Nr   r   r?   r=   r   r      s[    I.#3O

C!##   
M* Gr?   r   weightsprogresskwargsc                     Ub#  [        US[        UR                  S   5      5        [        U 40 UD6nU(       a  UR	                  UR                  USS95        U$ )Nro   r   T)r   
check_hash)r   lenr   r   load_state_dictget_state_dict)r`   r   r   r   models        r=   _mnasnetr   9  sX    fmSl9S5TUE$V$Eg44hSW4XYLr?   
pretrained)r   T)r   r   c                 F    [         R                  U 5      n [        SX40 UD6$ )an  MNASNet with depth multiplier of 0.5 from
`MnasNet: Platform-Aware Neural Architecture Search for Mobile
<https://arxiv.org/abs/1807.11626>`_ paper.

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

.. autoclass:: torchvision.models.MNASNet0_5_Weights
    :members:
g      ?)r   verifyr   r   r   r   s      r=   r   r   E  &    . !''0GC5f55r?   c                 F    [         R                  U 5      n [        SX40 UD6$ )ar  MNASNet with depth multiplier of 0.75 from
`MnasNet: Platform-Aware Neural Architecture Search for Mobile
<https://arxiv.org/abs/1807.11626>`_ paper.

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

.. autoclass:: torchvision.models.MNASNet0_75_Weights
    :members:
g      ?)r   r   r   r   s      r=   r   r   a  s&    . "((1GD'6v66r?   c                 F    [         R                  U 5      n [        SX40 UD6$ )an  MNASNet with depth multiplier of 1.0 from
`MnasNet: Platform-Aware Neural Architecture Search for Mobile
<https://arxiv.org/abs/1807.11626>`_ paper.

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

.. autoclass:: torchvision.models.MNASNet1_0_Weights
    :members:
r\   )r   r   r   r   s      r=   r   r   }  r   r?   c                 F    [         R                  U 5      n [        SX40 UD6$ )an  MNASNet with depth multiplier of 1.3 from
`MnasNet: Platform-Aware Neural Architecture Search for Mobile
<https://arxiv.org/abs/1807.11626>`_ paper.

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

.. autoclass:: torchvision.models.MNASNet1_3_Weights
    :members:
g?)r   r   r   r   s      r=   r   r     r   r?   )g?)/r   	functoolsr   typingr   r   torchtorch.nnr4   r   transforms._presetsr   utilsr	   _apir   r   r   _metar   _utilsr   r   __all__r|   Moduler   rI   rJ   r5   rV   r_   r   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r?   r=   <module>r      s          5 ' 6 6 ' B
 &		 &@,,,*-,7:,HK,VY,hm,]],Lu Ls L5 LSV LIu Ic Ir
ehhoo r
l &8 *+ 2 * 2	E 	H[$9 	T 	UX 	]d 	 ,0B0P0P!QR:>QU 68$67 6$ 6ad 6ip 6 S 64 ,0C0Q0Q!RS<@SW 7H%89 7D 7cf 7kr 7 T 74 ,0B0P0P!QR:>QU 68$67 6$ 6ad 6ip 6 S 64 ,0B0P0P!QR:>QU 68$67 6$ 6ad 6ip 6 S 6r?   