
    h                        S SK r 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  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Jr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 S\5      r' " S S\5      r(\" SS9\" SS 4S9SSS S!.S"\\\(\4      S#\)S$\)S%\S&\'4
S' jj5       5       rg)(    N)partial)AnyOptionalUnion)Tensor)
functional   )ImageClassification   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)BasicConv2d	GoogLeNetGoogLeNet_WeightsGoogLeNetOutputs	InceptionInceptionAux   )_fuse_modules_replace_reluquantize_model)QuantizableGoogLeNetGoogLeNet_QuantizedWeights	googlenetc                   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      a/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/quantization/googlenet.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-   r2   s     r/   forwardQuantizableBasicConv2d.forward   s.    IIaLGGAJIIaLr1   is_qatc                      [        U / SQUSS9  g )Nr4   T)inplace)r   )r-   r:   s     r/   
fuse_model!QuantizableBasicConv2d.fuse_model$   s    d2FDIr1   r+   r&   )__name__
__module____qualname____firstlineno__r   r(   r   r8   r   boolr=   __static_attributes____classcell__r.   s   @r/   r    r       sP    c S T  F J$ J4 J Jr1   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	$ )
QuantizableInception(   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catr,   s      r/   r(   QuantizableInception.__init__)   s/    $L+ALVL<<//1r1   r2   c                 \    U R                  U5      nU R                  R                  US5      $ )Nr   )_forwardrP   )r-   r2   outputss      r/   r8   QuantizableInception.forward-   s%    --"xx||GQ''r1   )rP   
r@   rA   rB   rC   r   r(   r   r8   rE   rF   rG   s   @r/   rI   rI   (   s5    2c 2S 2T 2( (F ( (r1   rI   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	$ )
QuantizableInceptionAux2   r"   r#   r$   Nc                 f   > [         TU ]  " US[        0UD6  [        R                  " 5       U l        g rL   )r'   r(   r    r)   r*   r+   r,   s      r/   r(    QuantizableInceptionAux.__init__4   s(    $L+ALVLGGI	r1   r2   c                    [         R                  " US5      nU R                  U5      n[        R                  " US5      nU R                  U R                  U5      5      nU R                  U5      nU R                  U5      nU$ )N)   r]   r   )	Fadaptive_avg_pool2dr5   torchflattenr+   fc1dropoutfc2r7   s     r/   r8   QuantizableInceptionAux.forward8   sh    !!!V,IIaLMM!QIIdhhqk"LLOHHQK r1   r?   rV   rG   s   @r/   rX   rX   2   s5    c S T  F  r1   rX   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   J   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blocks)r'   r(   r    rI   rX   r`   aoquantization	QuantStubquantDeQuantStubdequantr,   s      r/   r(   QuantizableGoogLeNet.__init__L   sb    	
13GI`a	
ek	
 XX**446
xx,,88:r1   r2   c                    U R                  U5      nU R                  U5      nU R                  U5      u  pnU R                  U5      nU R                  =(       a    U R
                  n[        R                  R                  5       (       a)  U(       d  [        R                  " S5        [        XU5      $ U R                  XU5      $ )NzCScripted QuantizableGoogleNet always returns GoogleNetOutputs Tuple)_transform_inputrm   rS   ro   training
aux_logitsr`   jitis_scriptingwarningswarnr   eager_outputs)r-   r2   aux1aux2aux_defineds        r/   r8   QuantizableGoogLeNet.forwardS   s    !!!$JJqMa(LLOmm799!!##cd#AT22%%at44r1   r:   c                 |    U R                  5        H(  n[        U5      [        L d  M  UR                  U5        M*     g)zFuse conv/bn/relu modules in googlenet 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    r=   )r-   r:   ms      r/   r=   QuantizableGoogLeNet.fuse_model`   s-     AAw00V$  r1   )ro   rm   r&   )r@   rA   rB   rC   r   r(   r   r   r8   r   rD   r=   rE   rF   rG   s   @r/   r   r   J   sM    ;c ;S ;T ;5 5$4 5
%$ 
%4 
% 
%r1   r   c                   f    \ rS rSr\" 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   m   zKhttps://download.pytorch.org/models/quantized/googlenet_fbgemm-c81f6644.pth   )	crop_sizeie )   r   fbgemmzdhttps://github.com/pytorch/vision/tree/main/references/classification#post-training-quantized-modelszImageNet-1Kg/tQ@g`"YV@)zacc@1zacc@5g+?g#~j<)@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meta N)r@   rA   rB   rC   r   r   r
   r   r   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULTrE   r   r1   r/   r   r   m   s_    "Y.#>! .|,::##   
0 #Gr1   r   quantized_googlenet)name
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ )NquantizeF)getr   r   r   r   )r#   s    r/   <lambda>r      s1    zz*e,, ';; 1"001r1   )weightsTF)r   progressr   r   r   r   r#   r$   c                    U(       a  [         O[        R                  U 5      n UR                  SS5      nU bz  SU;  a  [	        USS5        [	        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 bS  UR                  U R                  USS95        U(       d  SUl        SUl        SUl        U$ [         R"                  " S5        U$ )a\  GoogLeNet (Inception v1) model architecture from `Going Deeper with Convolutions <http://arxiv.org/abs/1409.4842>`__.

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

.. autoclass:: torchvision.models.quantization.GoogLeNet_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.GoogLeNet_Weights
    :members:
    :noindex:
rt   FNtransform_inputTinit_weightsnum_classesr   r   r   )r   
check_hashz`auxiliary heads in the pretrained googlenet model are NOT pretrained, so make sure to train themr   )r   r   verifyr   r   lenr   popr   r   r   load_state_dictget_state_dictrt   rz   r{   rw   rx   )r   r   r   r#   original_aux_logitsr   models          r/   r   r      s(   \ .6);LTTU\]G **\59F*!&*;TBflD9fne<fmSl9S5TU$!&)W\\)5LMjjH-G *6*E%u&g44hSW4XY"$EEJEJ L	 MMr Lr1   )*rw   	functoolsr   typingr   r   r   r`   torch.nnr)   r   r   r^   transforms._presetsr
   _apir   r   r   _metar   _utilsr   r   r   r   r   r   r   r   r   utilsr   r   r   __all__r    rI   rX   r   r   rD   r   r1   r/   <module>r      s     ' '    $ 6 7 7 ( C l l ? ?J[ J(9 (l 0 %9  %F# #8 *+	
	 OS	@e68IIJK@ @ 	@
 @ @	 ,@r1   