
    QЦi?*                        S SK r S SKJr  S SKJrJrJrJr  S SKrS SK	J
r
  S SKJ
s  Jr  S SKJr  S SKJr  S SK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\RJ                  5      r& " S S\RN                  5      r( " S S\RR                  5      r* " S S\RV                  5      r, " S S\RZ                  5      r. " S S\R^                  5      r0 " S S\Rb                  5      r2 " S S\Rf                  5      r4 " S  S!\5      r5\" S"S#9\" S$S% 4S&9SS'S(S).S*\\\5\4      S+\6S,\6S-\S.\44
S/ jj5       5       r7g)0    N)partial)AnyListOptionalUnion)Tensor)	inception)Inception_V3_WeightsInceptionOutputs   )ImageClassification   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface   )_fuse_modules_replace_reluquantize_model)QuantizableInception3Inception_V3_QuantizedWeightsinception_v3c                   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$ )QuantizableBasicConv2d   argskwargsreturnNc                 Z   > [         TU ]  " U0 UD6  [        R                  " 5       U l        g N)super__init__nnReLUreluselfr   r    	__class__s      h/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/models/quantization/inception.pyr%   QuantizableBasicConv2d.__init__   s"    $)&)GGI	    xc                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r#   convbnr(   )r*   r/   s     r,   forwardQuantizableBasicConv2d.forward   s.    IIaLGGAJIIaLr.   is_qatc                      [        U / SQUSS9  g )Nr1   T)inplace)r   )r*   r6   s     r,   
fuse_model!QuantizableBasicConv2d.fuse_model%   s    d2FDIr.   )r(   r#   )__name__
__module____qualname____firstlineno__r   r%   r   r4   r   boolr9   __static_attributes____classcell__r+   s   @r,   r   r      sP    c S T  F J$ J4 J Jr.   r   c                   J   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrS	rU =r	$ )
QuantizableInceptionA)   r   r    r!   Nc                 x   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        g N
conv_blockr$   r%   r   r&   	quantizedFloatFunctionalmyopr)   s      r,   r%   QuantizableInceptionA.__init__+   /    $L+ALVLLL002	r.   r/   c                 \    U R                  U5      nU R                  R                  US5      $ Nr   _forwardrL   catr*   r/   outputss      r,   r4   QuantizableInceptionA.forward/   %    --"yy}}Wa((r.   rL   
r;   r<   r=   r>   r   r%   r   r4   r@   rA   rB   s   @r,   rD   rD   )   5    3c 3S 3T 3) )F ) )r.   rD   c                   J   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrS	rU =r	$ )
QuantizableInceptionB4   r   r    r!   Nc                 x   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        g rG   rI   r)   s      r,   r%   QuantizableInceptionB.__init__6   rN   r.   r/   c                 \    U R                  U5      nU R                  R                  US5      $ rP   rQ   rT   s      r,   r4   QuantizableInceptionB.forward:   rW   r.   rX   rY   rB   s   @r,   r\   r\   4   rZ   r.   r\   c                   J   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrS	rU =r	$ )
QuantizableInceptionC?   r   r    r!   Nc                 x   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        g rG   rI   r)   s      r,   r%   QuantizableInceptionC.__init__A   rN   r.   r/   c                 \    U R                  U5      nU R                  R                  US5      $ rP   rQ   rT   s      r,   r4   QuantizableInceptionC.forwardE   rW   r.   rX   rY   rB   s   @r,   rc   rc   ?   rZ   r.   rc   c                   J   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrS	rU =r	$ )
QuantizableInceptionDJ   r   r    r!   Nc                 x   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        g rG   rI   r)   s      r,   r%   QuantizableInceptionD.__init__L   rN   r.   r/   c                 \    U R                  U5      nU R                  R                  US5      $ rP   rQ   rT   s      r,   r4   QuantizableInceptionD.forwardP   rW   r.   rX   rY   rB   s   @r,   rj   rj   J   rZ   r.   rj   c                   b   ^  \ rS rSrS\S\SS4U 4S jjrS\S\\   4S jrS\S\4S	 jr	S
r
U =r$ )QuantizableInceptionEU   r   r    r!   Nc                   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        [        R                  R                  5       U l        [        R                  R                  5       U l        g rG   )	r$   r%   r   r&   rJ   rK   myop1myop2myop3r)   s      r,   r%   QuantizableInceptionE.__init__W   sW    $L+ALVL\\113
\\113
\\113
r.   r/   c                    U R                  U5      nU R                  U5      nU R                  U5      U R                  U5      /nU R                  R                  US5      nU R                  U5      nU R                  U5      nU R                  U5      U R                  U5      /nU R                  R                  US5      n[        R                  " USSSS9nU R                  U5      nX#XE/nU$ )Nr   r   )kernel_sizestridepadding)	branch1x1branch3x3_1branch3x3_2abranch3x3_2brt   rS   branch3x3dbl_1branch3x3dbl_2branch3x3dbl_3abranch3x3dbl_3bru   F
avg_pool2dbranch_pool)r*   r/   r|   	branch3x3branch3x3dblr   rU   s          r,   rR   QuantizableInceptionE._forward]   s    NN1%	$$Q'	&&y143D3DY3OP	JJNN9a0	**1-**<8  .  .
 zz~~lA6ll1!AqI&&{3Cr.   c                 \    U R                  U5      nU R                  R                  US5      $ rP   )rR   rv   rS   rT   s      r,   r4   QuantizableInceptionE.forwardr   s%    --"zz~~gq))r.   )rt   ru   rv   )r;   r<   r=   r>   r   r%   r   r   rR   r4   r@   rA   rB   s   @r,   rq   rq   U   sL    4c 4S 4T 4& T&\ ** *F * *r.   rq   c                   8   ^  \ rS rSrS\S\SS4U 4S jjrSrU =r$ )QuantizableInceptionAuxw   r   r    r!   Nc                 2   > [         TU ]  " US[        0UD6  g rG   )r$   r%   r   r)   s      r,   r%    QuantizableInceptionAux.__init__y   s    $L+ALVLr.    )r;   r<   r=   r>   r   r%   r@   rA   rB   s   @r,   r   r   w   s'    Mc MS MT M Mr.   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   }   r   r    r!   Nc                 $  > [         TU ]  " US[        [        [        [
        [        [        [        /0UD6  [        R                  R                  R                  5       U l        [        R                  R                  R                  5       U l        g )Ninception_blocks)r$   r%   r   rD   r\   rc   rj   rq   r   torchaoquantization	QuantStubquantDeQuantStubdequantr)   s      r,   r%   QuantizableInception3.__init__~   st    	
 '%%%%%'	
 	
 XX**446
xx,,88:r.   r/   c                    U R                  U5      nU R                  U5      nU R                  U5      u  pU R                  U5      nU R                  =(       a    U R
                  n[        R                  R                  5       (       a(  U(       d  [        R                  " S5        [        X5      $ U R                  X5      $ )NzIScripted QuantizableInception3 always returns QuantizableInception3 Tuple)_transform_inputr   rR   r   training
aux_logitsr   jitis_scriptingwarningswarnr   eager_outputs)r*   r/   auxaux_defineds       r,   r4   QuantizableInception3.forward   s    !!!$JJqMq!LLOmm799!!##ij#A++%%a--r.   r6   c                 |    U R                  5        H(  n[        U5      [        L d  M  UR                  U5        M*     g)zFuse conv/bn/relu modules in inception model

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
N)modulestyper   r9   )r*   r6   ms      r,   r9    QuantizableInception3.fuse_model   s-     AAw00V$  r.   )r   r   r#   )r;   r<   r=   r>   r   r%   r   r   r4   r   r?   r9   r@   rA   rB   s   @r,   r   r   }   sM    ;c ;S ;T ;". .$4 .
%$ 
%4 
% 
%r.   r   c                   h    \ rS rSr\" S\" \SSS9SS\SS	\R                  S
SSS.0SSSS.
S9r
\
rSrg)r      zUhttps://download.pytorch.org/models/quantized/inception_v3_google_fbgemm-a2837893.pthi+  iV  )	crop_sizeresize_sizeir)K   r   fbgemmzdhttps://github.com/pytorch/vision/tree/main/references/classification#post-training-quantized-modelszImageNet-1Kg%CKS@g-VW@)zacc@1zacc@5g'1@gL7A`%7@z
                These weights were produced by doing Post Training Quantization (eager mode) on top of the unquantized
                weights listed below.
            )

num_paramsmin_size
categoriesbackendrecipeunquantized_metrics_ops
_file_size_docs)url
transformsmetar   N)r;   r<   r=   r>   r   r   r   r   r
   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULTr@   r   r.   r,   r   r      sa    "c.#3O" .|/==##   
0 #Gr.   r   quantized_inception_v3)name
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ )NquantizeF)getr   r   r
   r   )r    s    r,   <lambda>r      s1    ::j%(( 5II 0!//0r.   )weightsTF)r   progressr   r   r   r   r    r!   c                 v   U(       a  [         O[        R                  U 5      n UR                  SS5      nU bm  SU;  a  [	        USS5        [	        USS5        [	        US[        U R                  S   5      5        SU R                  ;   a  [	        USU R                  S   5        UR                  SS	5      n[        S0 UD6n[        U5        U(       a  [        Xe5        U bW  U(       a  U(       d  SUl        SUl        UR                  U R                  USS
95        U(       d  U(       d  SUl        SUl        U$ )a6  Inception v3 model architecture from
`Rethinking the Inception Architecture for Computer Vision <http://arxiv.org/abs/1512.00567>`__.

.. note::
    **Important**: In contrast to the other models the inception_v3 expects tensors with a size of
    N x 3 x 299 x 299, so ensure your images are sized accordingly.

.. 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.Inception_V3_QuantizedWeights` or :class:`~torchvision.models.Inception_V3_Weights`, optional): The pretrained
        weights for the model. See
        :class:`~torchvision.models.quantization.Inception_V3_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.QuantizableInception3``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/inception.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.Inception_V3_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.Inception_V3_Weights
    :members:
    :noindex:
r   FNtransform_inputTnum_classesr   r   r   )r   
check_hashr   )r   r
   verifyr   r   lenr   popr   r   r   r   	AuxLogitsload_state_dictget_state_dict)r   r   r   r    original_aux_logitsr   models          r,   r   r      s   d 19,>RZZ[bcG **\59F*!&*;TBflD9fmSl9S5TU$!&)W\\)5LMjjH-G!+F+E%u&/$E"EOg44hSW4XY 3$E"EOLr.   )8r   	functoolsr   typingr   r   r   r   r   torch.nnr&   torch.nn.functional
functionalr   r   torchvision.modelsr	   inception_moduletorchvision.models.inceptionr
   r   transforms._presetsr   _apir   r   r   _metar   _utilsr   r   utilsr   r   r   __all__BasicConv2dr   
InceptionArD   
InceptionBr\   
InceptionCrc   
InceptionDrj   
InceptionErq   InceptionAuxr   
Inception3r   r   r?   r   r   r.   r,   <module>r      su     - -      < O 6 7 7 ( C ? ?J-99 J),77 )),77 )),77 )),77 )*,77 *DM.;; M)%,77 )%X#K #8 -.	0 UY	Ce9;OOPQC C 	C
 C C /Cr.   