
    hF                     <   S SK Jr  S SKJrJrJr  S SKrS SKJr  S SKJ	r	  S SK
JrJrJrJrJrJr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SKJrJrJ r   / SQr! " S S\5      r" " S S\5      r# " S S\5      r$S\%\\"\#4      S\&\'   S\\   S\(S\(S\S\$4S jr)S\SSS S!.r* " S" S#\5      r+ " S$ S%\5      r, " S& S'\5      r- " S( S)\5      r.\" S*S+9\" S,S- 4S.9SS/S0S1.S\\\+\4      S\(S\(S\S\$4
S2 jj5       5       r/\" S3S+9\" S,S4 4S.9SS/S0S1.S\\\,\4      S\(S\(S\S\$4
S5 jj5       5       r0\" S6S+9\" S,S7 4S.9SS/S0S1.S\\\-\4      S\(S\(S\S\$4
S8 jj5       5       r1\" S9S+9\" S,S: 4S.9SS/S0S1.S\\\.\4      S\(S\(S\S\$4
S; jj5       5       r2g)<    )partial)AnyOptionalUnionN)Tensor)
BasicBlock
BottleneckResNetResNet18_WeightsResNet50_WeightsResNeXt101_32X8D_WeightsResNeXt101_64X4D_Weights   )ImageClassification   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface   )_fuse_modules_replace_reluquantize_model)	QuantizableResNetResNet18_QuantizedWeightsResNet50_QuantizedWeights!ResNeXt101_32X8D_QuantizedWeights!ResNeXt101_64X4D_QuantizedWeightsresnet18resnet50resnext101_32x8dresnext101_64x4dc                   f   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrSS	\\	   SS4S
 jjr
SrU =r$ )QuantizableBasicBlock%   argskwargsreturnNc                    > [         TU ]  " U0 UD6  [        R                  R                  R                  5       U l        g N)super__init__torchnn	quantizedFloatFunctionaladd_reluselfr(   r)   	__class__s      ^/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/quantization/resnet.pyr.   QuantizableBasicBlock.__init__&   s/    $)&)**::<    xc                 &   UnU R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R	                  U5      nU R
                  b  U R                  U5      nU R                  R                  X25      nU$ r,   )conv1bn1reluconv2bn2
downsampler3   r5   r:   identityouts       r7   forwardQuantizableBasicBlock.forward*   sy    jjmhhsmiinjjohhsm??&q)Hmm$$S3
r9   is_qatc                 |    [        U / SQSS//USS9  U R                  (       a  [        U R                  SS/USS9  g g )Nr<   r=   r>   r?   r@   Tinplace01r   rA   r5   rG   s     r7   
fuse_model QuantizableBasicBlock.fuse_model;   s>    d57GH&Z^_??$//C:vtL r9   )r3   r,   __name__
__module____qualname____firstlineno__r   r.   r   rE   r   boolrP   __static_attributes____classcell__r6   s   @r7   r&   r&   %   sP    =c =S =T = F "M$ M4 M Mr9   r&   c                   f   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrSS	\\	   SS4S
 jjr
SrU =r$ )QuantizableBottleneckA   r(   r)   r*   Nc                    > [         TU ]  " U0 UD6  [        R                  R	                  5       U l        [        R                  " SS9U l        [        R                  " SS9U l        g )NFrJ   )	r-   r.   r0   r1   r2   skip_add_reluReLUrelu1relu2r4   s      r7   r.   QuantizableBottleneck.__init__B   sJ    $)&)\\99;WWU+
WWU+
r9   r:   c                    UnU R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R	                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  b  U R                  U5      nU R                  R                  X25      nU$ r,   )r<   r=   ra   r?   r@   rb   conv3bn3rA   r_   r3   rB   s       r7   rE   QuantizableBottleneck.forwardH   s    jjmhhsmjjojjohhsmjjojjohhsm??&q)H  ))#8
r9   rG   c                     [        U / SQ/ SQSS//USS9  U R                  (       a  [        U R                  SS/USS9  g g )	N)r<   r=   ra   )r?   r@   rb   re   rf   TrJ   rL   rM   rN   rO   s     r7   rP    QuantizableBottleneck.fuse_modelZ   sH    ,.G'SXIYZ\blp	
 ??$//C:vtL r9   )ra   rb   r_   r,   rR   rZ   s   @r7   r\   r\   A   sP    ,c ,S ,T , F $M$ M4 M Mr9   r\   c                   f   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrSS	\\	   SS4S
 jjr
SrU =r$ )r   b   r(   r)   r*   Nc                    > [         TU ]  " U0 UD6  [        R                  R                  R                  5       U l        [        R                  R                  R                  5       U l        g r,   )	r-   r.   r/   aoquantization	QuantStubquantDeQuantStubdequantr4   s      r7   r.   QuantizableResNet.__init__c   sI    $)&)XX**446
xx,,88:r9   r:   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r,   )rp   _forward_implrr   )r5   r:   s     r7   rE   QuantizableResNet.forwardi   s3    JJqM q!LLOr9   rG   c                     [        U / SQUSS9  U R                  5        H:  n[        U5      [        L d  [        U5      [        L d  M)  UR                  U5        M<     g)zFuse conv/bn/relu modules in resnet models

Fuse conv+bn+relu/ Conv+relu/conv+Bn modules to prepare for quantization.
Model is modified in place.  Note that this operation does not change numerics
and the model after modification is in floating point
rI   TrJ   N)r   modulestyper\   r&   rP   )r5   rG   ms      r7   rP   QuantizableResNet.fuse_modelr   sH     	d4fdKAAw//47>S3SV$  r9   )rr   rp   r,   rR   rZ   s   @r7   r   r   b   sL    ;c ;S ;T ; F 
%$ 
%4 
% 
%r9   r   blocklayersweightsprogressquantizer)   r*   c                 `   UbM  [        US[        UR                  S   5      5        SUR                  ;   a  [        USUR                  S   5        UR                  SS5      n[	        X40 UD6n[        U5        U(       a  [        Xv5        Ub  UR                  UR                  USS95        U$ )Nnum_classes
categoriesbackendfbgemmT)r   
check_hash)	r   lenmetapopr   r   r   load_state_dictget_state_dict)r|   r}   r~   r   r   r)   r   models           r7   _resnetr      s     fmSl9S5TU$!&)W\\)5LMjjH-Ge6v6E%u&g44hSW4XYLr9   )r   r   r   zdhttps://github.com/pytorch/vision/tree/main/references/classification#post-training-quantized-modelsz
        These weights were produced by doing Post Training Quantization (eager mode) on top of the unquantized
        weights listed below.
    )min_sizer   r   recipe_docsc                   d    \ rS rSr\" S\" \SS90 \ES\R                  SSSS	.0S
SS.ES9r
\
rSrg)r      zJhttps://download.pytorch.org/models/quantized/resnet18_fbgemm_16fa66dd.pth   	crop_sizei(^ ImageNet-1KgV-_Q@g r8V@zacc@1zacc@5g/$?g`"y&@
num_paramsunquantized_metrics_ops
_file_sizeurl
transformsr    N)rS   rT   rU   rV   r   r   r   _COMMON_METAr   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULTrX   r   r9   r7   r   r      s[    "X.#>

"+99##   
" #Gr9   r   c                       \ rS rSr\" S\" \SS90 \ES\R                  SSSS	.0S
SS.ES9r
\" S\" \SSS90 \ES\R                  SSSS	.0S
SS.ES9r\rSrg)r      zJhttps://download.pytorch.org/models/quantized/resnet50_fbgemm_bf931d71.pthr   r   i(r   g{GR@gjt4W@r   gB`"[@gM8@r   r   zJhttps://download.pytorch.org/models/quantized/resnet50_fbgemm-23753f79.pth   r   resize_sizeg5^IT@gX9vW@g8@r   N)rS   rT   rU   rV   r   r   r   r   r   r   r   IMAGENET1K_V2IMAGENET1K_FBGEMM_V2r   rX   r   r9   r7   r   r      s    "X.#>

"+99##   
" #X.#3O

"+99##   
" #Gr9   r   c                       \ rS rSr\" S\" \SS90 \ES\R                  SSSS	.0S
SS.ES9r
\" S\" \SSS90 \ES\R                  SSSS	.0S
SS.ES9r\rSrg)r      zQhttps://download.pytorch.org/models/quantized/resnext101_32x8_fbgemm_09835ccf.pthr   r   i(Jr   gvS@gQW@r   gDli0@gV-U@r   r   zQhttps://download.pytorch.org/models/quantized/resnext101_32x8_fbgemm-ee16d00c.pthr   r   g~jT@g rX@gzGU@r   N)rS   rT   rU   rV   r   r   r   r   r   r   r   r   r   r   rX   r   r9   r7   r   r      s    "_.#>

"3AA##   
" #_.#3O

"3AA##   
" #Gr9   r   c                   h    \ rS rSr\" S\" \SSS90 \ESS\R                  SS	S
S.0SSS.ES9r
\
rSrg)r    i  zRhttps://download.pytorch.org/models/quantized/resnext101_64x4d_fbgemm-605a1cb3.pthr   r   r   i(mz+https://github.com/pytorch/vision/pull/5935r   gxT@g/X@r   gQ.@g$cT@)r   r   r   r   r   r   r   r   N)rS   rT   rU   rV   r   r   r   r   r   r   r   r   rX   r   r9   r7   r    r      s`    "`.#3O

"C3AA##   
$ #Gr9   r    quantized_resnet18)name
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ Nr   F)getr   r   r   r   r)   s    r7   <lambda>r     1    zz*e,, &:: 0!//0r9   )r~   TF)r~   r   r   c                 p    U(       a  [         O[        R                  U 5      n [        [        / SQXU40 UD6$ )aC  ResNet-18 model from
`Deep Residual Learning for Image Recognition <https://arxiv.org/abs/1512.03385>`_

.. note::
    Note that ``quantize = True`` returns a quantized model with 8 bit
    weights. Quantized models only support inference and run on CPUs.
    GPU inference is not yet supported.

Args:
    weights (:class:`~torchvision.models.quantization.ResNet18_QuantizedWeights` or :class:`~torchvision.models.ResNet18_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ResNet18_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model. Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.QuantizableResNet``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/resnet.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ResNet18_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ResNet18_Weights
    :members:
    :noindex:
)r   r   r   r   )r   r   verifyr   r&   r~   r   r   r)   s       r7   r!   r!     4    ^ -5(:JRRSZ[G(,8^W]^^r9   quantized_resnet50c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r7   r   r   S  r   r9   c                 p    U(       a  [         O[        R                  U 5      n [        [        / SQXU40 UD6$ )aC  ResNet-50 model from
`Deep Residual Learning for Image Recognition <https://arxiv.org/abs/1512.03385>`_

.. note::
    Note that ``quantize = True`` returns a quantized model with 8 bit
    weights. Quantized models only support inference and run on CPUs.
    GPU inference is not yet supported.

Args:
    weights (:class:`~torchvision.models.quantization.ResNet50_QuantizedWeights` or :class:`~torchvision.models.ResNet50_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ResNet50_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model. Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.QuantizableResNet``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/resnet.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ResNet50_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ResNet50_Weights
    :members:
    :noindex:
)r         r   )r   r   r   r   r\   r   s       r7   r"   r"   O  r   r9   quantized_resnext101_32x8dc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r7   r   r     1    zz*e,, .BB 8)778r9   c                     U(       a  [         O[        R                  U 5      n [        USS5        [        USS5        [	        [
        / SQXU40 UD6$ )a  ResNeXt-101 32x8d model from
`Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>`_

.. note::
    Note that ``quantize = True`` returns a quantized model with 8 bit
    weights. Quantized models only support inference and run on CPUs.
    GPU inference is not yet supported.

Args:
    weights (:class:`~torchvision.models.quantization.ResNeXt101_32X8D_QuantizedWeights` or :class:`~torchvision.models.ResNeXt101_32X8D_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ResNet101_32X8D_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model. Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.QuantizableResNet``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/resnet.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ResNeXt101_32X8D_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ResNeXt101_32X8D_Weights
    :members:
    :noindex:
groups    width_per_group   r   r      r   )r   r   r   r   r   r\   r   s       r7   r#   r#     M    ^ 5=0BZbbcjkG&(B/&"3Q7(-H_X^__r9   quantized_resnext101_64x4dc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r    r   r   r   r   s    r7   r   r     r   r9   c                     U(       a  [         O[        R                  U 5      n [        USS5        [        USS5        [	        [
        / SQXU40 UD6$ )a  ResNeXt-101 64x4d model from
`Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>`_

.. note::
    Note that ``quantize = True`` returns a quantized model with 8 bit
    weights. Quantized models only support inference and run on CPUs.
    GPU inference is not yet supported.

Args:
    weights (:class:`~torchvision.models.quantization.ResNeXt101_64X4D_QuantizedWeights` or :class:`~torchvision.models.ResNeXt101_64X4D_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ResNet101_64X4D_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model. Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.QuantizableResNet``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/resnet.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ResNeXt101_64X4D_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ResNeXt101_64X4D_Weights
    :members:
    :noindex:
r   @   r   r   r   )r    r   r   r   r   r\   r   s       r7   r$   r$     r   r9   )3	functoolsr   typingr   r   r   r/   torch.nnr0   r   torchvision.models.resnetr   r	   r
   r   r   r   r   transforms._presetsr   _apir   r   r   _metar   _utilsr   r   utilsr   r   r   __all__r&   r\   r   ry   listintrW   r   r   r   r   r   r    r!   r"   r#   r$   r   r9   r7   <module>r      sA    ' '      7 7 7 ( C ? ?
MJ M8MJ MB% %:+-BBCDI k" 	
   4 &t	# #*## ##L## ##L# #, )*	
	 MQ	&_e57GGHI&_ &_ 	&_
 &_ &_	 +&_R )*	
	 MQ	&_e57GGHI&_ &_ 	&_
 &_ &_	 +&_R 12	
	 ]a	(`e=?WWXY(` (` 	(`
 (` (`	 3(`V 12	
	 ]a	(`e=?WWXY(` (` 	(`
 (` (`	 3(`r9   