
    hA                        S SK r S SKJ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
s  Jr  S SKJs  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 S\
R@                  5      r! " S S\
RD                  5      r# " S S\
RH                  5      r% " S S\
R@                  5      r&S\
R@                  S\S\'SS4S jr(S\)S\*\)\)\)\)4   S\)S\\   S\'S\S\&4S jr+S \S!S"S#.r, " S$ S%\5      r- " S& S'\5      r. " S( S)\5      r/ " S* S+\5      r0\" 5       \" S,\-Rb                  4S-9SS.S/.S\\-   S\'S\S\&4S0 jj5       5       r2\" 5       \" S,\.Rb                  4S-9SS.S/.S\\.   S\'S\S\&4S1 jj5       5       r3\" 5       \" S,\/Rb                  4S-9SS.S/.S\\/   S\'S\S\&4S2 jj5       5       r4\" 5       \" S,\0Rb                  4S-9SS.S/.S\\0   S\'S\S\&4S3 jj5       5       r5g)4    N)OrderedDict)partial)AnyOptional)Tensor   )ImageClassification)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)	DenseNetDenseNet121_WeightsDenseNet161_WeightsDenseNet169_WeightsDenseNet201_Weightsdensenet121densenet161densenet169densenet201c                   d  ^  \ rS rSr SS\S\S\S\S\SS4U 4S	 jjjrS
\\	   S\	4S jr
S\\	   S\4S jr\R                  R                  S\\	   S\	4S j5       r\R                  R                   S\\	   S\	4S j5       r\R                  R                   S\	S\	4S j5       rS\	S\	4S jrSrU =r$ )_DenseLayer   num_input_featuresgrowth_ratebn_size	drop_ratememory_efficientreturnNc           	        > [         TU ]  5         [        R                  " U5      U l        [        R
                  " SS9U l        [        R                  " XU-  SSSS9U l        [        R                  " X2-  5      U l	        [        R
                  " SS9U l
        [        R                  " X2-  USSSSS9U l        [        U5      U l        XPl        g )NTinplacer   Fkernel_sizestridebias   r(   r)   paddingr*   )super__init__nnBatchNorm2dnorm1ReLUrelu1Conv2dconv1norm2relu2conv2floatr!   r"   )selfr   r   r    r!   r"   	__class__s         S/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/densenet.pyr/   _DenseLayer.__init__    s     	^^$67
WWT*
YY1[3HVW`ahmn
^^G$9:
WWT*
YYw4kqYZdelqr
y) 0    inputsc                     [         R                  " US5      nU R                  U R                  U R	                  U5      5      5      nU$ Nr   )torchcatr6   r4   r2   )r;   r@   concated_featuresbottleneck_outputs       r=   bn_function_DenseLayer.bn_function/   s;    !IIfa0 JJtzz$**=N2O'PQ  r?   inputc                 <    U H  nUR                   (       d  M    g   g)NTF)requires_grad)r;   rI   tensors      r=   any_requires_grad_DenseLayer.any_requires_grad5   s     F###  r?   c                 D   ^  U 4S jn[         R                  " U/UQ7SS06$ )Nc                  &   > TR                  U 5      $ N)rG   )r@   r;   s    r=   closure7_DenseLayer.call_checkpoint_bottleneck.<locals>.closure=   s    ##F++r?   use_reentrantF)cp
checkpoint)r;   rI   rR   s   `  r=   call_checkpoint_bottleneck&_DenseLayer.call_checkpoint_bottleneck;   s#    	, }}WBuBEBBr?   c                     g rQ    r;   rI   s     r=   forward_DenseLayer.forwardB       r?   c                     g rQ   rZ   r[   s     r=   r\   r]   F   r^   r?   c                    [        U[        5      (       a  U/nOUnU R                  (       aV  U R                  U5      (       a@  [        R
                  R                  5       (       a  [        S5      eU R                  U5      nOU R                  U5      nU R                  U R                  U R                  U5      5      5      nU R                  S:  a)  [        R                  " X@R                  U R                   S9nU$ )Nz%Memory Efficient not supported in JITr   )ptraining)
isinstancer   r"   rM   rC   jitis_scripting	ExceptionrW   rG   r9   r8   r7   r!   Fdropoutrb   )r;   rI   prev_featuresrF   new_featuress        r=   r\   r]   L   s    eV$$"GM!M  T%;%;M%J%Jyy%%'' GHH $ ? ? N $ 0 0 ?zz$**TZZ8I-J"KL>>A99\^^dmm\Lr?   )r6   r9   r!   r"   r2   r7   r4   r8   F)__name__
__module____qualname____firstlineno__intr:   boolr/   listr   rG   rM   rC   rd   unusedrW   _overload_methodr\   __static_attributes____classcell__r<   s   @r=   r   r      s   rw1"%1471BE1RW1ko1	1 1!$v, !6 !tF|   YYCV C C C YYT&\ f    YYV    
V   r?   r   c                   d   ^  \ rS 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$ )_DenseBlock`   r   
num_layersr   r    r   r!   r"   r#   Nc           	         > [         T	U ]  5         [        U5       H-  n[        X'U-  -   UUUUS9nU R	                  SUS-   -  U5        M/     g )N)r   r    r!   r"   zdenselayer%dr   )r.   r/   ranger   
add_module)
r;   r{   r   r    r   r!   r"   ilayerr<   s
            r=   r/   _DenseBlock.__init__c   sX     	z"A"_4'#!1E OONa!e4e< #r?   init_featuresc                     U/nU R                  5        H  u  p4U" U5      nUR                  U5        M      [        R                  " US5      $ rB   )itemsappendrC   rD   )r;   r   featuresnamer   rj   s         r=   r\   _DenseBlock.forwardw   sC    !?::<KD ?LOOL) ( yy1%%r?   rZ   rk   )rl   rm   rn   ro   _versionrp   r:   rq   r/   r   r\   ru   rv   rw   s   @r=   ry   ry   `   ss    H "'==  = 	=
 = = = 
= =(&V & & &r?   ry   c                   8   ^  \ rS rSrS\S\SS4U 4S jjrSrU =r$ )_Transition   r   num_output_featuresr#   Nc                    > [         TU ]  5         [        R                  " U5      U l        [        R
                  " SS9U l        [        R                  " XSSSS9U l        [        R                  " SSS9U l
        g )NTr%   r   Fr'   r   )r(   r)   )r.   r/   r0   r1   normr3   relur5   conv	AvgPool2dpool)r;   r   r   r<   s      r=   r/   _Transition.__init__   s[    NN#56	GGD)	II0ST]^ejk	LLQq9	r?   )r   r   r   r   )rl   rm   rn   ro   rp   r/   ru   rv   rw   s   @r=   r   r      s"    :3 :S :T : :r?   r   c                      ^  \ rS rSrSr       SS\S\\\\\4   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$ )r      a  Densenet-BC model class, based on
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.

Args:
    growth_rate (int) - how many filters to add each layer (`k` in paper)
    block_config (list of 4 ints) - how many layers in each pooling block
    num_init_features (int) - the number of filters to learn in the first convolution layer
    bn_size (int) - multiplicative factor for number of bottle neck layers
      (i.e. bn_size * k features in the bottleneck layer)
    drop_rate (float) - dropout rate after each dense layer
    num_classes (int) - number of classification classes
    memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient,
      but slower. Default: *False*. See `"paper" <https://arxiv.org/pdf/1707.06990.pdf>`_.
r   block_confignum_init_featuresr    r!   num_classesr"   r#   Nc                 >  > [         TU ]  5         [        U 5        [        R                  " [        S[        R                  " SUSSSSS94S[        R                  " U5      4S[        R                  " S	S
94S[        R                  " SSSS94/5      5      U l
        Un[        U5       H  u  p[        U
UUUUUS9nU R                  R                  SU	S-   -  U5        XU-  -   nU	[        U5      S-
  :w  d  MP  [        XS-  S9nU R                  R                  SU	S-   -  U5        US-  nM     U R                  R                  S[        R                  " U5      5        [        R                   " X5      U l        U R%                  5        GH  n['        U[        R                  5      (       a+  [        R(                  R+                  UR,                  5        MN  ['        U[        R                  5      (       aV  [        R(                  R/                  UR,                  S5        [        R(                  R/                  UR0                  S5        M  ['        U[        R                   5      (       d  M  [        R(                  R/                  UR0                  S5        GM     g )Nconv0r+      r   Fr,   norm0relu0Tr%   pool0r   )r(   r)   r-   )r{   r   r    r   r!   r"   zdenseblock%d)r   r   ztransition%dnorm5r   )r.   r/   r
   r0   
Sequentialr   r5   r1   r3   	MaxPool2dr   	enumeratery   r~   lenr   Linear
classifiermodulesrc   initkaiming_normal_weight	constant_r*   )r;   r   r   r   r    r!   r   r"   num_featuresr   r{   blocktransmr<   s                 r=   r/   DenseNet.__init__   s    	D! bii+<!TU_`glmnbnn->?@bggd34bllqANO		
 )&|4MA%#/'#!1E MM$$^q1u%=uE'{*BBLC%))#|ijYjk((1q5)A5I+q0 5" 	  "..*FG ))L> A!RYY''''1Ar~~..!!!((A.!!!&&!,Aryy))!!!&&!,  r?   xc                     U R                  U5      n[        R                  " USS9n[        R                  " US5      n[        R
                  " US5      nU R                  U5      nU$ )NTr%   )r   r   r   )r   rg   r   adaptive_avg_pool2drC   flattenr   )r;   r   r   outs       r=   r\   DenseNet.forward   sU    ==#ffXt,##C0mmC#ooc"
r?   )r   r   )                @      r   i  F)rl   rm   rn   ro   __doc__rp   tupler:   rq   r/   r   r\   ru   rv   rw   s   @r=   r   r      s    " 2A!#!&:-:- Cc3./:- 	:-
 :- :- :- :- 
:- :-x F  r?   r   modelweightsprogressr#   c                 <   [         R                  " S5      nUR                  USS9n[        UR	                  5       5       HH  nUR                  U5      nU(       d  M  UR                  S5      UR                  S5      -   nXE   XG'   XE	 MJ     U R                  U5        g )Nz]^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$T)r   
check_hashr   r   )recompileget_state_dictrr   keysmatchgroupload_state_dict)r   r   r   pattern
state_dictkeyresnew_keys           r=   _load_state_dictr      s    
 jjhG ''d'KJJOO%&mmC 3iilSYYq\1G",/J ' 
*%r?   r   r   r   kwargsc                     Ub#  [        US[        UR                  S   5      5        [        XU40 UD6nUb
  [	        XcUS9  U$ )Nr   
categories)r   r   r   )r   r   metar   r   )r   r   r   r   r   r   r   s          r=   	_densenetr      sK     fmSl9S5TU[0ALVLEuILr?   )   r   z*https://github.com/pytorch/vision/pull/116z'These weights are ported from LuaTorch.)min_sizer   recipe_docsc            
       N    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SS.ES9r\r	Sr
g)r   i  z<https://download.pytorch.org/models/densenet121-a639ec97.pth   	crop_sizeihy ImageNet-1KgƛR@g|?5V@zacc@1zacc@5gy&1@gQ>@
num_params_metrics_ops
_file_sizeurl
transformsr   rZ   Nrl   rm   rn   ro   r   r   r	   _COMMON_METAIMAGENET1K_V1DEFAULTru   rZ   r?   r=   r   r     sQ    J.#>

!##   
M  Gr?   r   c            
       N    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SS.ES9r\r	Sr
g)r   i  z<https://download.pytorch.org/models/densenet161-8d451a50.pthr   r   i(r   gFHS@gp=
cW@r   gx@gV-[@r   r   rZ   Nr   rZ   r?   r=   r   r     sQ    J.#>

"##  !
M  Gr?   r   c            
       N    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SS.ES9r\r	Sr
g)r   i3  z<https://download.pytorch.org/models/densenet169-b2777c0a.pthr   r   ih r   gfffffR@g$3W@r   gzG
@gvZK@r   r   rZ   Nr   rZ   r?   r=   r   r   3  sQ    J.#>

"##   
M  Gr?   r   c            
       N    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SS.ES9r\r	Sr
g)r   iG  z<https://download.pytorch.org/models/densenet201-c1103571.pthr   r   ihc1r   gMbX9S@gHzWW@r   gDl)@gZd;WS@r   r   rZ   Nr   rZ   r?   r=   r   r   G  sQ    J.#>

"##   
M  Gr?   r   
pretrained)r   T)r   r   c                 J    [         R                  U 5      n [        SSSX40 UD6$ )a?  Densenet-121 model from
`Densely Connected Convolutional Networks <https://arxiv.org/abs/1608.06993>`_.

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

.. autoclass:: torchvision.models.DenseNet121_Weights
    :members:
r   r   r   )r   verifyr   r   r   r   s      r=   r   r   [  *    * "((1GR"gJ6JJr?   c                 J    [         R                  U 5      n [        SSSX40 UD6$ )a?  Densenet-161 model from
`Densely Connected Convolutional Networks <https://arxiv.org/abs/1608.06993>`_.

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

.. autoclass:: torchvision.models.DenseNet161_Weights
    :members:
0   )r   r   $   r   rz   )r   r   r   r   s      r=   r   r   u  r   r?   c                 J    [         R                  U 5      n [        SSSX40 UD6$ )a?  Densenet-169 model from
`Densely Connected Convolutional Networks <https://arxiv.org/abs/1608.06993>`_.

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

.. autoclass:: torchvision.models.DenseNet169_Weights
    :members:
r   )r   r   r   r   r   )r   r   r   r   s      r=   r   r     r   r?   c                 J    [         R                  U 5      n [        SSSX40 UD6$ )a?  Densenet-201 model from
`Densely Connected Convolutional Networks <https://arxiv.org/abs/1608.06993>`_.

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

.. autoclass:: torchvision.models.DenseNet201_Weights
    :members:
r   )r   r   r   r   r   )r   r   r   r   s      r=   r   r     r   r?   )6r   collectionsr   	functoolsr   typingr   r   rC   torch.nnr0   torch.nn.functional
functionalrg   torch.utils.checkpointutilsrV   rU   r   transforms._presetsr	   r
   _apir   r   r   _metar   _utilsr   r   __all__Moduler   
ModuleDictry   r   r   r   rq   r   rp   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r?   r=   <module>r
     s   	 #        # #  5 ' 6 6 ' B
>")) >B&"-- &>:"-- :Rryy Rj&BII & &t &PT &&S#s*+  k"	
   ( &::	+ (+ (+ (+ ( ,0C0Q0Q!RS<@SW KH%89 KD Kcf Kks K T K0 ,0C0Q0Q!RS<@SW KH%89 KD Kcf Kks K T K0 ,0C0Q0Q!RS<@SW KH%89 KD Kcf Kks K T K0 ,0C0Q0Q!RS<@SW KH%89 KD Kcf Kks K T Kr?   