
    ^j                        d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
Z
ddlmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' dd	l(m)Z) dd
l*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0 dgZ1 G d dejd                        Z3 G d dejd                        Z4 G d dejd                        Z5eefeefeefeefeefeefdZ6de	ee7f   de8de9fdZ: G d dejd                        Z;d
dejd                  dee7   de9ddfdZ<d Z=dd Z>dd!Z?dd"Z@ e.i d# e?d$d%d&d'      d( e?d$d%d&d'      d) e?d$d*d*+      d, e?d$d*d*d-.      d/ e?d0d$d&d%1      d2 e?d3d$d&d%1      d4 e?d5d%6      d7 e?d8d$d&d%1      d9 e?d:d$d&d%1      d; e?d<d$d&d%1      d= e?d>d$d%d&d?      d@ e?d$d%d&d'      dA e?dBd$d%d&d?      dC e?dDd$d%d&d?      dE e?dFd$d%d&d?      dG e?d$dHdIdJ      dK e?d$dHdIddLM      i dN e?d$dHdIddLM      dO e?d$d%dPQ      dR e?d$dHdIddPS      dT e?d$dHdIddPS      dU e?d$d%dPQ      dV e?d$d%dPQ      dW e?dXd$d&d1      dY e?dZd$d&d1      d[ e?d\d$d&d1      d] e?d^d$d&d1      d_ e?d`d$d&d1      da e?dbd$d&d1      dc e?ddd$d&d1      de e?dfd$d&d1      dg e?dhd$d&d1      di e?djd$dHdIddLk      dl e?dmd$dHdIddLk      i dn e?dod$dHdIddLk      dp e?dqd$dHdIddLk      dr e?dsd$dHdIddLk      dt e?dud$dvw      dx e?dyd$dvw      dz e?d{d$dvw      d| e?d}d$dvw      d~ e?dd$dvw      d e@dd$d&d1      d e@dd$dHdIddLk      d e@dd$d&d1      d e@dd$dHdIddLk      d e@dd$d&d1      d e@dd$dHdIddLk      d e@dd$d&d1      d e@dd$dHdIddLk      d e@dd$dHdIddLk      i d e@dd$ddddLk      d e@dd$d&d%1      d e@dd$d&d%1      d e@dd$d&d%1      d e@dd$d&d1      d e@dd$d&d1      d e@dd$d&d1      d e@dd$d&d1      d e@dd$d&d1      d e@dd$dw      d e@dd$dw      d e@dd$dw      d e@dd$dw      d e@dd$dw      d e@dd$dw      d e@dd$dw      d e@dd$dw      i d e?       d e?d$eed5dd      d e?d$eedHdIddL      d e?d$eeddd      d e?d$eedHdIddL      d e?d$eed5dd      d e?d$eedHdId      d e?d$eed5dd      d e?d$eedHdIddL      d e?d$eed5dd      d e?d$eedPd5ddƫ      d e?d$eedPdddƫ      d e?d$eedPdHdIddLɫ      d e?d$eedPdHdIddLɫ      d e?d$eedPd5ddƫ      d e?d$eed5dddͬΫ      d e?d$eed5dddͬΫ      i d e?d$eed5dddͬΫ      d e?d$eeddddͬΫ      d e?d$eeddddͬΫ      d e?d$eed5dddԬΫ      d e?d$eeddddԬΫ      d e?d$eeddddԬΫ      d e?d$eed5dddجΫ      d e?d$eed5dddجΫ      d e?d$ddd۬ܫ      d e?d$ddd۬ܫ      d e?d$ddd۬ܫ      d e?d$ddd۬ܫ      d e?d$d5dddd      d e?d$d5dddd      d e?d$d5dddd      d e?d$d*d*ddd%      d e?d$d*d*ddd%      d e?d$d*d*ddd%      i      ZAe/dde;fd       ZBe/dde;fd       ZCe/dde;fd       ZDe/dde;fd       ZEe/dde;fd       ZFe/dde;fd       ZGe/dde;fd       ZHe/dde;fd       ZIe/dde;fd       ZJe/dde;fd       ZKe/dde;fd       ZLe/dde;fd       ZMe/dde;fd       ZNe/dde;fd       ZOe/dde;fd       ZPe/dde;fd       ZQe/dde;fd       ZRe/dde;fd       ZSe/dde;fd       ZTe/dde;fd       ZUe/dde;fd       ZVe/dde;fd       ZWe/dde;fd        ZXe/dde;fd       ZYe/dde;fd       ZZe/dde;fd       Z[e/dde;fd       Z\e/dde;fd       Z]e/dde;fd       Z^e/dde;fd       Z_e/dde;fd       Z` e0eadWdYd[d]d_didldndpdrdtdxdzd|d~d	       y(  ax   ConvNeXt

Papers:
* `A ConvNet for the 2020s` - https://arxiv.org/pdf/2201.03545.pdf
@Article{liu2022convnet,
  author  = {Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie},
  title   = {A ConvNet for the 2020s},
  journal = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year    = {2022},
}

* `ConvNeXt-V2 - Co-designing and Scaling ConvNets with Masked Autoencoders` - https://arxiv.org/abs/2301.00808
@article{Woo2023ConvNeXtV2,
  title={ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders},
  author={Sanghyun Woo, Shoubhik Debnath, Ronghang Hu, Xinlei Chen, Zhuang Liu, In So Kweon and Saining Xie},
  year={2023},
  journal={arXiv preprint arXiv:2301.00808},
}

Original code and weights from:
* https://github.com/facebookresearch/ConvNeXt, original copyright below
* https://github.com/facebookresearch/ConvNeXt-V2, original copyright below

Model defs atto, femto, pico, nano and _ols / _hnf variants are timm originals.

Modifications and additions for timm hacked together by / Copyright 2022, Ross Wightman
    )partial)CallableDictListOptionalTupleUnionN)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDOPENAI_CLIP_MEANOPENAI_CLIP_STD)trunc_normal_AvgPool2dSameDropPathcalculate_drop_path_ratesMlpGlobalResponseNormMlpLayerNorm2d	LayerNorm	RmsNorm2dRmsNormSimpleNorm2d
SimpleNormcreate_conv2dget_act_layerget_norm_layermake_divisible	to_ntupleNormMlpClassifierHeadClassifierHead   )build_model_with_cfg)feature_take_indices)named_applycheckpoint_seq)generate_default_cfgsregister_modelregister_model_deprecationsConvNeXtc                   z     e Zd ZdZ	 	 	 	 ddededededdf
 fdZd	ej                  dej                  fd
Z xZ	S )
DownsamplezDownsample module for ConvNeXt.Nin_chsout_chsstridedilationreturnc                 P   ||d}t         
|           |dk(  r|nd}|dkD  s|dkD  r2|dk(  r|dkD  rt        nt        j                  }	 |	d|dd      | _        nt        j                         | _        ||k7  rt        ||dfddi|| _        yt        j                         | _        y)	zInitialize Downsample module.

        Args:
            in_chs: Number of input channels.
            out_chs: Number of output channels.
            stride: Stride for downsampling.
            dilation: Dilation rate.
        devicedtyper!      TF)	ceil_modecount_include_padr.   N)	super__init__r   nn	AvgPool2dpoolIdentityr   conv)selfr,   r-   r.   r/   r3   r4   dd
avg_strideavg_pool_fn	__class__s             _/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/models/convnext.pyr9   zDownsample.__init__O   s    " /'1}V!
A:A+5?x!|-QSQ]Q]K#AzTUZ[DIDIW%fgqIIbIDIDI    xc                 J    | j                  |      }| j                  |      }|S Forward pass.)r<   r>   r?   rF   s     rD   forwardzDownsample.forwardn   s!    IIaLIIaLrE   )r!   r!   NN)
__name__
__module____qualname____doc__intr9   torchTensorrK   __classcell__rC   s   @rD   r+   r+   L   sd    ) && & 	&
 & 
&> %,, rE   r+   c                        e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddedee   dededeeeeef   f   dede	d	e	d
e	dee   dee
ef   dee   def fdZdej                  dej                  fdZ xZS )ConvNeXtBlockab  ConvNeXt Block.

    There are two equivalent implementations:
      (1) DwConv -> LayerNorm (channels_first) -> 1x1 Conv -> GELU -> 1x1 Conv; all in (N, C, H, W)
      (2) DwConv -> Permute to (N, H, W, C); LayerNorm (channels_last) -> Linear -> GELU -> Linear; Permute back

    Unlike the official impl, this one allows choice of 1 or 2, 1x1 conv can be faster with appropriate
    choice of LayerNorm impl, however as model size increases the tradeoffs appear to change and nn.Linear
    is a better choice. This was observed with PyTorch 1.10 on 3090 GPU, it could change over time & w/ different HW.
    r,   r-   kernel_sizer.   r/   	mlp_ratioconv_mlp	conv_biasuse_grnls_init_value	act_layer
norm_layer	drop_pathc           	         ||d}t         |           |xs |} t        d      |      }t        |      }|s|rt        nt
        }t        |	rt        nt        |      }|| _	        t        ||f|||d   d|d|| _         ||fi || _         ||t        ||z        fd|i|| _        |
,t        j                   |
t#        j$                  |fi |z        nd| _        ||k7  s|d	k7  s|d   |d	   k7  rt)        ||f||d   d
|| _        nt        j,                         | _        |dkD  rt/        |      | _        yt        j,                         | _        y)a[  

        Args:
            in_chs: Block input channels.
            out_chs: Block output channels (same as in_chs if None).
            kernel_size: Depthwise convolution kernel size.
            stride: Stride of depthwise convolution.
            dilation: Tuple specifying input and output dilation of block.
            mlp_ratio: MLP expansion ratio.
            conv_mlp: Use 1x1 convolutions for MLP and a NCHW compatible norm layer if True.
            conv_bias: Apply bias for all convolution (linear) layers.
            use_grn: Use GlobalResponseNorm in MLP (from ConvNeXt-V2)
            ls_init_value: Layer-scale init values, layer-scale applied if not None.
            act_layer: Activation layer.
            norm_layer: Normalization layer (defaults to LN if not specified).
            drop_path: Stochastic depth probability.
        r2   r5   )use_convr   T)rW   r.   r/   	depthwisebiasr]   Nr!   )r.   r/           )r8   r9   r   r   r   r   r   r   r   use_conv_mlpr   conv_dwnormrP   mlpr:   	ParameterrQ   onesgammar+   shortcutr=   r   r_   )r?   r,   r-   rW   r.   r/   rX   rY   rZ   r[   r\   r]   r^   r_   r3   r4   r@   	mlp_layerrC   s                     rD   r9   zConvNeXtBlock.__init__   sw   F /#V9Q<)!),	(0iJW1#PXY	$$	
 $a[	
 	
 w-"-		G#$
  
 	
 Q^PiR\\-%**W2K2K"KLos
W!x{hqk/I&vwbvPXYZP[b_abDMKKMDM09B),BKKMrE   rF   r0   c                    |}| j                  |      }| j                  r#| j                  |      }| j                  |      }nJ|j	                  dddd      }| j                  |      }| j                  |      }|j	                  dddd      }| j
                  -|j                  | j
                  j                  dddd            }| j                  |      | j                  |      z   }|S )rI   r   r5      r!   )
rf   re   rg   rh   permuterk   mulreshaper_   rl   )r?   rF   rl   s      rD   rK   zConvNeXtBlock.forward   s    LLO		!AA		!Q1%A		!AA		!Q1%A::!djj((B156ANN1h 77rE   )N   r!   r!   r!      FTFư>geluNrd   NN)rL   rM   rN   rO   rP   r   r	   r   floatboolstrr   r9   rQ   rR   rK   rS   rT   s   @rD   rV   rV   u   s   	 &* 4: ""!-1.4-1!!BRBR c]BR 	BR
 BR CsCx01BR BR BR BR BR $E?BR S(]+BR !*BR BRH %,, rE   rV   c                        e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddedededededeeef   d	eee      d
ede	de	de	de
eef   dee   dee   ddf fdZdej                  dej                  fdZ xZS )ConvNeXtStagez!ConvNeXt stage (multiple blocks).Nr,   r-   rW   r.   depthr/   drop_path_ratesr\   rY   rZ   r[   r]   r^   norm_layer_clr0   c                    ||d}t         |           d| _        ||k7  s|dkD  s|d   |d   k7  rY|dkD  s|d   |d   k7  rdnd}|d   dkD  rdnd}t        j                   ||fi |t        ||f|||d   ||
d|      | _        |}nt        j                         | _        |xs dg|z  }g }t        |      D ]4  }|j                  t        d||||d   ||   ||	|
|||	r|n|d	|       |}6 t        j                  | | _        y
)a  Initialize ConvNeXt stage.

        Args:
            in_chs: Number of input channels.
            out_chs: Number of output channels.
            kernel_size: Kernel size for depthwise convolution.
            stride: Stride for downsampling.
            depth: Number of blocks in stage.
            dilation: Dilation rates.
            drop_path_rates: Drop path rates for each block.
            ls_init_value: Initial value for layer scale.
            conv_mlp: Use convolutional MLP.
            conv_bias: Use bias in convolutions.
            use_grn: Use global response normalization.
            act_layer: Activation layer.
            norm_layer: Normalization layer.
            norm_layer_cl: Normalization layer for channels last.
        r2   Fr!   r   r5   same)rW   r.   r/   paddingrc   rd   )r,   r-   rW   r/   r_   r\   rY   rZ   r[   r]   r^   N )r8   r9   grad_checkpointingr:   
Sequentialr   
downsampler=   rangeappendrV   blocks)r?   r,   r-   rW   r.   r~   r/   r   r\   rY   rZ   r[   r]   r^   r   r3   r4   r@   ds_kspadstage_blocksirC   s                         rD   r9   zConvNeXtStage.__init__   sc   J /"'W
hqkXa[.H!x{hqk'AAqE$QK!O&C mm6(R(	 !&!%a["	 	DO F kkmDO)9bTE\u 	A !'!!)!,+!##)1:}! !  F	  mm\2rE   rF   c                     | j                  |      }| j                  r6t        j                  j	                         st        | j                  |      }|S | j                  |      }|S rH   )r   r   rQ   jitis_scriptingr%   r   rJ   s     rD   rK   zConvNeXtStage.forward,  sS    OOA""599+A+A+Ct{{A.A  AArE   )rt   r5   r5   ru   N      ?FTFrx   NNNN)rL   rM   rN   rO   rP   r   r   r   ry   rz   r	   r{   r   r9   rQ   rR   rK   rS   rT   s   @rD   r}   r}      s   +  !(.59#&""!.4-104#O3O3 O3 	O3
 O3 O3 CHoO3 &d5k2O3 !O3 O3 O3 O3 S(]+O3 !*O3 $H-O3$ 
%O3b %,, rE   r}   )	layernormlayernorm2d
simplenormsimplenorm2drmsnorm	rmsnorm2dr^   rY   norm_epsc                     | xs d} | t         v rF|rt         |    d   nt         |    d   }t         |    d   } |t        | |      } t        ||      }| |fS |sJ d       t        |       } | }|t        ||      }| |fS )Nr   r   r!   )epszcIf a norm_layer is specified, conv MLP must be used so all norm expect rank-4, channels-first input)	_NORM_MAPr   r   )r^   rY   r   r   s       rD   _get_norm_layersr   @  s    *{JY4<	*-a0)JBWXYBZz*1-
 :J#Mx@M }$$  	rq	rx#J/
"#Mx@M}$$rE   c            +           e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dededededeedf   d	eedf   d
eeeedf   f   dee	   dedede	de
dee   de
de
de
deeef   deeeef      dee	   de	de	f* fdZej                  j                  d0de
deeeeef   f   fd       Zej                  j                  d1de
ddfd       Zej                  j                  dej*                  fd       Zd2dedee   ddfd Z	 	 	 	 	 d3d!ej0                  d"eeeee   f      d#e
d$e
d%ed&e
deeej0                     eej0                  eej0                     f   f   fd'Z	 	 	 d4d"eeee   f   d(e
d)e
dee   fd*Zd!ej0                  dej0                  fd+Zd0d!ej0                  d,e
dej0                  fd-Zd!ej0                  dej0                  fd.Z xZS )5r)   z|ConvNeXt model architecture.

    A PyTorch impl of : `A ConvNet for the 2020s`  - https://arxiv.org/pdf/2201.03545.pdf
    Nin_chansnum_classesglobal_pooloutput_stridedepths.dimskernel_sizesr\   	stem_type
patch_sizehead_init_scalehead_norm_firsthead_hidden_sizerY   rZ   r[   r]   r^   r   	drop_ratedrop_path_ratec                    t         %|           ||d}|dv sJ  t        d      |      }t        |||      \  }}t	        |      }|| _        || _        || _        g | _        |	dv sJ |	dk(  rDt        j                  t        j                  ||d   f|
|
|d| ||d   fi |      | _        |
}nd|	v rt        |d   d	z        n|d   }t        j                  t        d
t        j                  ||fdd	d|d|d|	v r |       nd
t        j                  ||d   fdd	d|d| ||d   fi |g       | _        d}t        j                         | _        t!        ||d      }g }|d   }|}d} t#        d      D ]  }!|d	k(  s|!dkD  rd	nd}"||k\  r|"dkD  r| |"z  } d}"||"z  }| dv rdnd	}#||!   }$|j%                  t'        ||$f||!   |"|#| f||!   ||!   |||||||d|       |$}| xj                  t)        ||d|!       gz  c_         t        j                  | | _        |x| _        | _        |rF|rJ  || j*                  fi || _        t1        | j*                  |f|| j                  d|| _        n`t        j4                         | _        t7        | j*                  |f||| j                  |dd|| _        | j2                  j*                  | _        t9        t;        t<        |      |        y
)a  
        Args:
            in_chans: Number of input image channels.
            num_classes: Number of classes for classification head.
            global_pool: Global pooling type.
            output_stride: Output stride of network, one of (8, 16, 32).
            depths: Number of blocks at each stage.
            dims: Feature dimension at each stage.
            kernel_sizes: Depthwise convolution kernel-sizes for each stage.
            ls_init_value: Init value for Layer Scale, disabled if None.
            stem_type: Type of stem.
            patch_size: Stem patch size for patch stem.
            head_init_scale: Init scaling value for classifier weights and biases.
            head_norm_first: Apply normalization before global pool + head.
            head_hidden_size: Size of MLP hidden layer in head if not None and head_norm_first == False.
            conv_mlp: Use 1x1 conv in MLP, improves speed for small networks w/ chan last.
            conv_bias: Use bias layers w/ all convolutions.
            use_grn: Use Global Response Norm (ConvNeXt-V2) in MLP.
            act_layer: Activation layer type.
            norm_layer: Normalization layer type.
            drop_rate: Head pre-classifier dropout rate.
            drop_path_rate: Stochastic depth drop rate.
        r2   )          rv   )patchoverlapoverlap_tieredoverlap_actr   r   )rW   r.   rc   tieredr5   Nro   r!   )rW   r.   r   rc   actT)	stagewise)r!   r5   )rW   r.   r/   r~   r   r\   rY   rZ   r[   r]   r^   r   zstages.)num_chs	reductionmodule)	pool_typer   rx   )hidden_sizer   r   r^   r]   )r   )r8   r9   r   r   r   r   r   r   feature_infor:   r   Conv2dstemr   filterstagesr   r   r   r}   dictnum_featuresr   norm_prer    headr=   r   r$   r   _init_weights)&r?   r   r   r   r   r   r   r   r\   r   r   r   r   r   rY   rZ   r[   r]   r^   r   r   r   r3   r4   r@   r   stem_stridemid_chsdp_ratesr   prev_chscurr_strider/   r   r.   first_dilationr-   rC   s&                                        rD   r9   zConvNeXt.__init__X  s   b 	/+++#y|L1$4Z8$T!
M!),	& "QQQQ		(DGmJ]fmjlm47)b)DI %K6>)6KnT!W\2QUVWQXGvd		(Gf1aV_fcef$	1	t		'47e!QU^ebde47)b)	5 ( DI Kmmo,^VtT7!q 	gA%*a!eQFm+
F"6!K"*f"4Q!N1gGMM- )O((3Qi (+!##%+  " H$x;Y`ab`cWd"e!ff7	g8 mmV,4<<D1 '''&t'8'8?B?DM&!! &..	
 DI KKMDM-!!	 -%..% 	 	DI %)II$:$:D!GM?KTRrE   coarser0   c                 2    t        d|rd      S g d      S )zCreate regex patterns for parameter grouping.

        Args:
            coarse: Use coarse grouping.

        Returns:
            Dictionary mapping group names to regex patterns.
        z^stemz^stages\.(\d+)))z^stages\.(\d+)\.downsample)r   )z^stages\.(\d+)\.blocks\.(\d+)N)z	^norm_pre)i )r   r   )r   )r?   r   s     rD   group_matcherzConvNeXt.group_matcher  s)     (.$
 	
5
 	
rE   enablec                 4    | j                   D ]	  }||_         y)zEnable or disable gradient checkpointing.

        Args:
            enable: Whether to enable gradient checkpointing.
        N)r   r   )r?   r   ss      rD   set_grad_checkpointingzConvNeXt.set_grad_checkpointing  s      	*A#)A 	*rE   c                 .    | j                   j                  S )zGet the classifier module.)r   fc)r?   s    rD   get_classifierzConvNeXt.get_classifier  s     yy||rE   c                 J    || _         | j                  j                  ||       y)zReset the classifier head.

        Args:
            num_classes: Number of classes for new classifier.
            global_pool: Global pooling type.
        N)r   r   reset)r?   r   r   s      rD   reset_classifierzConvNeXt.reset_classifier
  s     '		[1rE   rF   indicesrg   
stop_early
output_fmtintermediates_onlyc                    |dv sJ d       g }t        t        | j                        |      \  }}	| j                  |      }t        | j                        dz
  }
t        j
                  j                         s|s| j                  }n| j                  d|	dz    }t        |      D ]K  \  }} ||      }||v s|r&||
k(  r!|j                  | j                  |             ;|j                  |       M |r|S |
k(  r| j                  |      }||fS )aK  Forward features that returns intermediates.

        Args:
            x: Input image tensor.
            indices: Take last n blocks if int, all if None, select matching indices if sequence.
            norm: Apply norm layer to compatible intermediates.
            stop_early: Stop iterating over blocks when last desired intermediate hit.
            output_fmt: Shape of intermediate feature outputs.
            intermediates_only: Only return intermediate features.

        Returns:
            List of intermediate features or tuple of (final features, intermediates).
        )NCHWzOutput shape must be NCHW.r!   N)
r#   lenr   r   rQ   r   r   	enumerater   r   )r?   rF   r   rg   r   r   r   intermediatestake_indices	max_indexlast_idxr   feat_idxstages                 rD   forward_intermediateszConvNeXt.forward_intermediates  s   , Y&D(DD&"6s4;;7G"Qi IIaLt{{#a'99!!#:[[F[[)a-0F(0 	,OHeaA<'H0!((q)9:!((+	,   xa A-rE   
prune_norm
prune_headc                     t        t        | j                        |      \  }}| j                  d|dz    | _        |rt        j                         | _        |r| j                  dd       |S )aE  Prune layers not required for specified intermediates.

        Args:
            indices: Indices of intermediate layers to keep.
            prune_norm: Whether to prune normalization layer.
            prune_head: Whether to prune the classifier head.

        Returns:
            List of indices that were kept.
        Nr!   r    )r#   r   r   r:   r=   r   r   )r?   r   r   r   r   r   s         rD   prune_intermediate_layersz"ConvNeXt.prune_intermediate_layersF  s]      #7s4;;7G"Qikk.9q=1KKMDM!!!R(rE   c                 l    | j                  |      }| j                  |      }| j                  |      }|S )z/Forward pass through feature extraction layers.)r   r   r   rJ   s     rD   forward_featureszConvNeXt.forward_features^  s/    IIaLKKNMM!rE   
pre_logitsc                 N    |r| j                  |d      S | j                  |      S )zForward pass through classifier head.

        Args:
            x: Feature tensor.
            pre_logits: Return features before final classifier.

        Returns:
            Output tensor.
        T)r   )r   )r?   rF   r   s      rD   forward_headzConvNeXt.forward_heade  s&     1;tyyty,L		!LrE   c                 J    | j                  |      }| j                  |      }|S rH   )r   r   rJ   s     rD   rK   zConvNeXt.forwardq  s'    !!!$a rE   )ro     avgr   ro   ro   	   ro   `           rt   rw   r   rv   r   FNFTFrx   NNrd   rd   NNF)T)N)NFFr   F)r!   FT)rL   rM   rN   rO   rP   r{   r   r	   r   ry   rz   r   r9   rQ   r   ignorer   r   r   r   r:   Moduler   r   rR   r   r   r   r   rK   rS   rT   s   @rD   r)   r)   R  s    #$!#&2$789-1$%'$).2""!.49=(,!$&1NSNS NS 	NS
 NS #s(ONS S/NS  U38_ 45NS $E?NS NS NS #NS "NS 'smNS NS  !NS" #NS$ S(]+%NS& !sH}!56'NS( uo)NS* +NS, "-NS` YY
D 
T#uS$Y?O:O5P 
 
$ YY*T *T * * YY		  2C 2hsm 2W[ 2 8<$$',0 ||0  eCcN340  	0 
 0  0  !%0  
tELL!5tELL7I)I#JJ	K0 h ./$#	3S	>*  	
 
c0%,, 5<< 
Mell 
M 
M 
M %,, rE   r   r   namer   r0   c                 .   t        | t        j                        rNt        | j                  d       | j
                  *t        j                  j                  | j
                         yyt        | t        j                        rt        | j                  d       t        j                  j                  | j
                         |rPd|v rK| j                  j                  j                  |       | j
                  j                  j                  |       yyyy)zInitialize model weights.

    Args:
        module: Module to initialize.
        name: Module name.
        head_init_scale: Scale factor for head initialization.
    g{Gz?)stdNhead.)
isinstancer:   r   r   weightrc   initzeros_Lineardatamul_)r   r   r   s      rD   r   r   x  s     &"))$fmm-;;"GGNN6;;' #	FBII	&fmm-
v{{#GtOMM##O4KK!!/2 $4 
'rE   c                 `   d| v sd| v r| S d| v r| d   } i }d| v r| j                         D ci c]*  \  }}|j                  d      s|j                  dd      |, }}}d| v r2| d   |d<   t        j                  | d   j
                  d	         |d
<   |S d| v r@| d   |d<   | d   |d<   | d   |d<   t        j                  | d   j
                  d	         |d
<   |S d	dl}| j                         D ]5  \  }}|j                  d      r|j                  dd      }|j                  dd|      }|j                  dd|      }|j                  dd      }|j                  dd      }d|v rB|j                  dd      }|j                  dd       }|j                  |j
                  d!         }|j                  d"d#      }|j                  d$      r|j                  d%d&      }|j                  d'k(  r2d(|vr.|j                         |   j
                  }|j                  |      }|||<   8 |S c c}}w ))z Remap FB checkpoints -> timm zhead.norm.weightznorm_pre.weightmodelzvisual.trunk.stem.0.weightzvisual.trunk.r   zvisual.head.proj.weightzhead.fc.weightr   zhead.fc.biaszvisual.head.mlp.fc1.weightzhead.pre_logits.fc.weightzvisual.head.mlp.fc1.biaszhead.pre_logits.fc.biaszvisual.head.mlp.fc2.weightN)zprojectors.znorms.zdownsample_layers.0.zstem.zstages.([0-9]+).([0-9]+)zstages.\1.blocks.\2z#downsample_layers.([0-9]+).([0-9]+)zstages.\1.downsample.\2dwconvrf   pwconvzmlp.fcgrnzgrn.betazmlp.grn.biasz	grn.gammazmlp.grn.weightrp   r  zhead.fc.znorm.rg   z	head.normr5   r   )items
startswithreplacerQ   zerosshaperesubrs   ndim
state_dict)r  r  out_dictkvr  model_shapes          rD   checkpoint_filter_fnr    sd   Z'+<
+J*(
H#z1BLBRBRBTv$!QXYXdXdetXuAIIor2A5vv$
2)34M)NH%&',{{:>W3X3^3^_`3a'bH^$  *Z74>?[4\H012<=W2XH./)34P)QH%&',{{:>Z3[3a3abc3d'eH^$  " 1<<12II,g6FF.0FJFF9;UWXYIIh	*IIh)A:		*n5A		+'78A		!''"+&AIIgz*<< 		&+.A66Q;6?**,Q/55K		+&A'* OC ws   H*H*c                     |j                  dd      dk(  r|j                  dd       t        t        | |ft        t        dd      d	|}|S )
Npretrained_cfgr   fcmaepretrained_strictF)r   r!   r5   ro   T)out_indicesflatten_sequential)pretrained_filter_fnfeature_cfg)get
setdefaultr"   r)   r  r   )variant
pretrainedkwargsr  s       rD   _create_convnextr+    s]    zz"B'72 	-u5 ':1\dK 	E
 LrE   c                 2    | dddddt         t        dddd	|S )
Nr   ro      r.  rt   rt         ?bicubicstem.0head.fcz
apache-2.0)urlr   
input_size	pool_sizecrop_pctinterpolationmeanr  
first_conv
classifierlicenser
   r   r4  r*  s     rD   _cfgr?    s3    =vI%.Bi $* rE   c                 8    | dddddt         t        dddd	d
dd|S )Nr   r-  r/  r0  r1  r2  r3  zcc-by-nc-4.0zarXiv:2301.00808zGConvNeXt-V2: Co-designing and Scaling ConvNets with Masked Autoencodersz/https://github.com/facebookresearch/ConvNeXt-V2)r4  r   r5  r6  r7  r8  r9  r  r:  r;  r<  	paper_ids
paper_name
origin_urlr=  r>  s     rD   _cfgv2rD    s<    =vI%.Bi!0B_G
 
 
rE   zconvnext_tiny.in12k_ft_in1kztimm/gffffff?)ro      rE  )	hf_hub_idr7  test_input_sizetest_crop_pctzconvnext_small.in12k_ft_in1kz&convnext_zepto_rms.ra4_e3600_r224_in1k)      ?rI  rI  )rF  r9  r  z*convnext_zepto_rms_ols.ra4_e3600_r224_in1kg?)rF  r9  r  r7  zconvnext_atto.d2_in1kzrhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_atto_d2-01bb0f51.pth)r4  rF  rG  rH  zconvnext_atto_ols.a2_in1kzvhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_atto_ols_a2-78d1c8f3.pthzconvnext_atto_rms.untrained)ro      rJ  )rG  rH  zconvnext_femto.d1_in1kzshttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_femto_d1-d71d5b4c.pthzconvnext_femto_ols.d1_in1kzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_femto_ols_d1-246bf2ed.pthzconvnext_pico.d1_in1kzrhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_pico_d1-10ad7f0d.pthzconvnext_pico_ols.d1_in1kzvhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_pico_ols_d1-611f0ca7.pth)r4  rF  r7  rG  rH  zconvnext_nano.in12k_ft_in1kzconvnext_nano.d1h_in1kzshttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_nano_d1h-7eb4bdea.pthzconvnext_nano_ols.d1h_in1kzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_nano_ols_d1h-ae424a9a.pthzconvnext_tiny_hnf.a2h_in1kzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_tiny_hnf_a2h-ab7e9df2.pthz convnext_nano.r384_in12k_ft_in1k)ro   r   r   )   rK  )rF  r5  r6  r7  zconvnext_tiny.in12k_ft_in1k_384squash)rF  r5  r6  r7  	crop_modez convnext_small.in12k_ft_in1k_384zconvnext_nano.in12ki-.  )rF  r7  r   zconvnext_nano.r384_in12k)rF  r5  r6  r7  r   zconvnext_nano.r384_ad_in12kzconvnext_tiny.in12kzconvnext_small.in12kzconvnext_tiny.fb_in22k_ft_in1kzDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_1k_224.pthzconvnext_small.fb_in22k_ft_in1kzEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_1k_224.pthzconvnext_base.fb_in22k_ft_in1kzDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_224.pthzconvnext_large.fb_in22k_ft_in1kzEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_224.pthz convnext_xlarge.fb_in22k_ft_in1kzJhttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_224_ema.pthzconvnext_tiny.fb_in1kzDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pthzconvnext_small.fb_in1kzEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_1k_224_ema.pthzconvnext_base.fb_in1kzDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_1k_224_ema.pthzconvnext_large.fb_in1kzEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_1k_224_ema.pthz"convnext_tiny.fb_in22k_ft_in1k_384zDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_1k_384.pth)r4  rF  r5  r6  r7  rM  z#convnext_small.fb_in22k_ft_in1k_384zEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_1k_384.pthz"convnext_base.fb_in22k_ft_in1k_384zDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_384.pthz#convnext_large.fb_in22k_ft_in1k_384zEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_384.pthz$convnext_xlarge.fb_in22k_ft_in1k_384zJhttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_384_ema.pthzconvnext_tiny.fb_in22kzAhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_224.pthiQU  )r4  rF  r   zconvnext_small.fb_in22kzBhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_224.pthzconvnext_base.fb_in22kzAhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_224.pthzconvnext_large.fb_in22kzBhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_224.pthzconvnext_xlarge.fb_in22kzChttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_224.pthz#convnextv2_nano.fcmae_ft_in22k_in1kzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_nano_22k_224_ema.ptz'convnextv2_nano.fcmae_ft_in22k_in1k_384zWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_nano_22k_384_ema.ptz#convnextv2_tiny.fcmae_ft_in22k_in1kzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_tiny_22k_224_ema.ptz'convnextv2_tiny.fcmae_ft_in22k_in1k_384zWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_tiny_22k_384_ema.ptz#convnextv2_base.fcmae_ft_in22k_in1kzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_base_22k_224_ema.ptz'convnextv2_base.fcmae_ft_in22k_in1k_384zWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_base_22k_384_ema.ptz$convnextv2_large.fcmae_ft_in22k_in1kzXhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_large_22k_224_ema.ptz(convnextv2_large.fcmae_ft_in22k_in1k_384zXhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_large_22k_384_ema.ptz'convnextv2_huge.fcmae_ft_in22k_in1k_384zWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_huge_22k_384_ema.ptz'convnextv2_huge.fcmae_ft_in22k_in1k_512zWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_huge_22k_512_ema.pt)ro      rN  )   rO  zconvnextv2_atto.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_atto_1k_224_ema.ptzconvnextv2_femto.fcmae_ft_in1kzVhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_femto_1k_224_ema.ptzconvnextv2_pico.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_pico_1k_224_ema.ptzconvnextv2_nano.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_nano_1k_224_ema.ptzconvnextv2_tiny.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_tiny_1k_224_ema.ptzconvnextv2_base.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_base_1k_224_ema.ptzconvnextv2_large.fcmae_ft_in1kzVhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_large_1k_224_ema.ptzconvnextv2_huge.fcmae_ft_in1kzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_huge_1k_224_ema.ptzconvnextv2_atto.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_atto_1k_224_fcmae.ptzconvnextv2_femto.fcmaez[https://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_femto_1k_224_fcmae.ptzconvnextv2_pico.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_pico_1k_224_fcmae.ptzconvnextv2_nano.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_nano_1k_224_fcmae.ptzconvnextv2_tiny.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_tiny_1k_224_fcmae.ptzconvnextv2_base.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_base_1k_224_fcmae.ptzconvnextv2_large.fcmaez[https://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_large_1k_224_fcmae.ptzconvnextv2_huge.fcmaezZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_huge_1k_224_fcmae.ptzconvnextv2_small.untrainedz/convnext_base.clip_laion2b_augreg_ft_in12k_in1k)r   r   )rF  r9  r  r5  r6  r7  z3convnext_base.clip_laion2b_augreg_ft_in12k_in1k_384)rF  r9  r  r5  r6  r7  rM  z6convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_320)ro   @  rP  )
   rQ  z6convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_384z)convnext_base.clip_laion2b_augreg_ft_in1kz,convnext_base.clip_laiona_augreg_ft_in1k_384z.convnext_large_mlp.clip_laion2b_augreg_ft_in1kz2convnext_large_mlp.clip_laion2b_augreg_ft_in1k_384z*convnext_xxlarge.clip_laion2b_soup_ft_in1kz*convnext_base.clip_laion2b_augreg_ft_in12k)rF  r9  r  r   r5  r6  r7  z1convnext_large_mlp.clip_laion2b_soup_ft_in12k_320z3convnext_large_mlp.clip_laion2b_augreg_ft_in12k_384)rF  r9  r  r   r5  r6  r7  rM  z1convnext_large_mlp.clip_laion2b_soup_ft_in12k_384z+convnext_xxlarge.clip_laion2b_soup_ft_in12kzconvnext_base.clip_laion2b  )rF  r9  r  r5  r6  r7  r   z!convnext_base.clip_laion2b_augregzconvnext_base.clip_laionazconvnext_base.clip_laiona_320z$convnext_base.clip_laiona_augreg_320z&convnext_large_mlp.clip_laion2b_augregr   z&convnext_large_mlp.clip_laion2b_ft_320z+convnext_large_mlp.clip_laion2b_ft_soup_320z"convnext_xxlarge.clip_laion2b_soup   z$convnext_xxlarge.clip_laion2b_rewindzconvnext_tiny.dinov3_lvd1689mzdinov3-license)rF  r7  r   r<  zconvnext_small.dinov3_lvd1689mzconvnext_base.dinov3_lvd1689mzconvnext_large.dinov3_lvd1689mzconvnext_tiny.eupe_lvd1689mz#fair-noncommercial-research-license)rF  r5  r6  r7  r   r<  zconvnext_small.eupe_lvd1689mzconvnext_base.eupe_lvd1689mztest_convnext.r160_in1k)ro      rT  )   rU  ztest_convnext2.r160_in1kztest_convnext3.r160_in1kc           	      R    t        dddd      }t        dd| it        |fi |}|S )Nr5   r5   rv   r5   r   @      rJ  Tr   r   r   rY   r^   r)  )convnext_zepto_rmsr   r+  r)  r*  
model_argsr  s       rD   r\  r\    s9     \0BT^jkJgjgDQ[Lf_eLfgELrE   c           	      T    t        ddddd      }t        dd| it        |fi |}|S )	NrW  rX  Tr   r   )r   r   rY   r^   r   r)  )convnext_zepto_rms_olsr]  r^  s       rD   ra  ra    sA     "4tP\huwJk*kPTU_PjciPjkELrE   c           	      P    t        ddd      }t        dd| it        |fi |}|S )Nr5   r5      r5   (   P   rT  rP  Tr   r   rY   r)  )convnext_attor]  r^  s       rD   ri  ri    s5     \0BTRJbbtJGaZ`GabELrE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nrc  re  Tr   r   r   rY   r   r)  )convnext_atto_olsr]  r^  s       rD   rl  rl    s9     \0BT]mnJfZf4PZKe^dKefELrE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nrc  re  Tr   r[  r)  )convnext_atto_rmsr]  r^  s       rD   rn  rn    s9     \0BT^ijJfZf4PZKe^dKefELrE   c           	      P    t        ddd      }t        dd| it        |fi |}|S )Nrc  0   r   r   r   Trh  r)  )convnext_femtor]  r^  s       rD   rr  rr    s5     \0BTRJc*cZHb[aHbcELrE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nrc  rp  Tr   rk  r)  )convnext_femto_olsr]  r^  s       rD   rt  rt    s9     \0BT]mnJgjgDQ[Lf_eLfgELrE   c           	      P    t        ddd      }t        dd| it        |fi |}|S )Nrc  rY  rZ  rJ  rN  Trh  r)  )convnext_picor]  r^  s       rD   rw  rw    5     \0CdSJbbtJGaZ`GabELrE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nrc  rv  Tr   rk  r)  )convnext_pico_olsr]  r^  s       rD   rz  rz    s9     \0Cd_opJfZf4PZKe^dKefELrE   c           	      P    t        ddd      }t        dd| it        |fi |}|S )Nr5   r5   r   r5   rg  rT  rP  rR  Trh  r)  )convnext_nanor]  r^  s       rD   r~  r~    rx  rE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nr|  r}  Tr   rk  r)  )convnext_nano_olsr]  r^  s       rD   r  r    s9     \0Cd^ghJfZf4PZKe^dKefELrE   c           	      R    t        dddd      }t        dd| it        |fi |}|S )Nr   r   T)r   r   r   rY   r)  )convnext_tiny_hnfr]  r^  s       rD   r  r    s:     \0CUYdhiJfZf4PZKe^dKefELrE   c           	      N    t        dd      }t        dd| it        |fi |}|S )Nr   r   r   r   r)  )convnext_tinyr]  r^  s       rD   r  r    s1    \0CDJbbtJGaZ`GabELrE   c           	      V    t        g dg d      }t        dd| it        |fi |}|S )Nro   ro      ro   r   r  r)  )convnext_smallr]  r^  s       rD   r  r    s1    ]1DEJc*cZHb[aHbcELrE   c           	      V    t        g dg d      }t        dd| it        |fi |}|S )Nr  rZ  rJ  rN  rS  r  r)  )convnext_baser]  r^  s       rD   r  r    s1    ]1FGJbbtJGaZ`GabELrE   c           	      V    t        g dg d      }t        dd| it        |fi |}|S )Nr  r   r   r      r  r)  )convnext_larger]  r^  s       rD   r  r    s1    ]1FGJc*cZHb[aHbcELrE   c           	      X    t        g dg dd      }t        dd| it        |fi |}|S )Nr  r  r  )r   r   r   r)  )convnext_large_mlpr]  r^  s       rD   r  r    s5    ]1FY]^JgjgDQ[Lf_eLfgELrE   c           	      V    t        g dg d      }t        dd| it        |fi |}|S )Nr  )rJ  rN  rS  i   r  r)  )convnext_xlarger]  r^  s       rD   r  r  !  s1    ]1GHJd:djIc\bIcdELrE   c           	      x    t        g dg d|j                  dd            }t        dd| it        |fi |}|S )N)ro   rv      ro   )r   r   r  i   r   h㈵>)r   r   r   r)  )convnext_xxlarger   popr+  r^  s       rD   r  r  (  sC    ]1GRXR\R\]gimRnoJeJe$zJd]cJdeELrE   c           	      T    t        dddd d      }t        dd| it        |fi |}|S )Nrc  re  Tr   r   r[   r\   rY   r)  )convnextv2_attor]  r^  s       rD   r  r  /  s?     "4dRVaegJd:djIc\bIcdELrE   c           	      T    t        dddd d      }t        dd| it        |fi |}|S )Nrc  rp  Tr  r)  )convnextv2_femtor]  r^  s       rD   r  r  8  s?     "4dRVaegJeJe$zJd]cJdeELrE   c           	      T    t        dddd d      }t        dd| it        |fi |}|S )Nrc  rv  Tr  r)  )convnextv2_picor]  r^  s       rD   r  r  A  ?     "5tSWbfhJd:djIc\bIcdELrE   c           	      T    t        dddd d      }t        dd| it        |fi |}|S )Nr|  r}  Tr  r)  )convnextv2_nanor]  r^  s       rD   r  r  J  r  rE   c           	      R    t        dddd       }t        dd| it        |fi |}|S )Nr   r   Tr   r   r[   r\   r)  )convnextv2_tinyr]  r^  s       rD   r  r  S  s6    \0CTaefJd:djIc\bIcdELrE   c           	      Z    t        g dg ddd       }t        dd| it        |fi |}|S )Nr  r   Tr  r)  )convnextv2_smallr]  r^  s       rD   r  r  Z  s6    ]1DdbfgJeJe$zJd]cJdeELrE   c           	      Z    t        g dg ddd       }t        dd| it        |fi |}|S )Nr  r  Tr  r)  )convnextv2_baser]  r^  s       rD   r  r  a  s7    ]1FPTdhiJd:djIc\bIcdELrE   c           	      Z    t        g dg ddd       }t        dd| it        |fi |}|S )Nr  r  Tr  r)  )convnextv2_larger]  r^  s       rD   r  r  h  s7    ]1FPTdhiJeJe$zJd]cJdeELrE   c           	      Z    t        g dg ddd       }t        dd| it        |fi |}|S )Nr  )i`  i  i  i   Tr  r)  )convnextv2_huger]  r^  s       rD   r  r  o  s7    ]1GQUeijJd:djIc\bIcdELrE   c           	      z    t        g dg d|j                  dd      d      }t        dd| it        |fi |}|S )	N)r!   r5   rv   r5   )   r   rq  rY  r   r  	gelu_tanhr   r   r   r]   r)  )test_convnextr  r^  s       rD   r  r  v  sC    \0@6::V`bfKgs~JbbtJGaZ`GabELrE   c           	      z    t        g dg d|j                  dd      d      }t        dd| it        |fi |}|S )	Nr!   r!   r!   r!   r   rY  r   rZ  r   r  r  r  r)  )test_convnext2r  r^  s       rD   r  r  }  sF    \0AFJJWacgLht  AJc*cZHb[aHbcELrE   c           	      |    t        g dg d|j                  dd      dd      }t        d	d| it        |fi |}|S )
Nr  r  r   r  )rt   rU  rU  ro   silu)r   r   r   r   r]   r)  )test_convnext3r  r^  s       rD   r  r    sM    "3fjjUY>Ziu  BHIJc*cZHb[aHbcELrE   )convnext_tiny_in22ft1kconvnext_small_in22ft1kconvnext_base_in22ft1kconvnext_large_in22ft1kconvnext_xlarge_in22ft1kconvnext_tiny_384_in22ft1kconvnext_small_384_in22ft1kconvnext_base_384_in22ft1kconvnext_large_384_in22ft1kconvnext_xlarge_384_in22ft1kconvnext_tiny_in22kconvnext_small_in22kconvnext_base_in22kconvnext_large_in22kconvnext_xlarge_in22k)Nr   r   )r   )brO   	functoolsr   typingr   r   r   r   r   r	   rQ   torch.nnr:   	timm.datar
   r   r   r   timm.layersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    _builderr"   	_featuresr#   _manipulater$   r%   	_registryr&   r'   r(   __all__r   r+   rV   r}   r   r{   rz   ry   r   r)   r   r  r+  r?  rD  default_cfgsr\  ra  ri  rl  rn  rr  rt  rw  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rL   r   rE   rD   <module>r     s3  N  ? ?   d d     * + + 4 Y Y,& &R`BII `F[BII [~ y)+,!:.7#W%	%x}!5 % %QV %$cryy cL	3")) 38C= 3RW 3bf 3(*Z % z&!4}C$Iz&
 #D}C%Iz& -d//3z& 1$/3z&  T A%T;!z&(   E%T";)z&0 "4%T$;1z&6 d B%T;7z&> !$ F%T#;?z&F T A%T;Gz&N   E}C"IOz&V "4}C$IWz&\ d B}CI]z&d !$ F}C#Iez&l !$ F}C#Imz&t ' Hs)Duz&| &t8sh(X}z&B ' Hsx)YCz&J 45*Kz&P  HsPU!WQz&V "4 HsPU$WWz&\ 45*]z&b D5*cz&j %dR%S':kz&r &tS%S(:sz&z %dR%S':{z&B &tS%S(:Cz&J 'X%S):Kz&T TR%S:Uz&\ dS%S:]z&d TR%S:ez&l dS%S:mz&v )$R Hsh+Xwz&~ *4S Hsh,Xz&F )$R Hsh+XGz&N *4S Hsh,XOz&V +DX Hsh-XWz&` dOaz&h tP iz&p dOqz&x tP yz&@ Q!Az&J *6e%S,:Kz&R .ve Hsh0XSz&Z *6e%S,:[z&b .ve Hsh0Xcz&j *6e%S,:kz&r .ve Hsh0Xsz&z +Ff%S-:{z&B /f Hsh1XCz&J .ve Hsh0XKz&R .ve Hsh0XSz&\ $Vc%T&;]z&d %fd%T';ez&l $Vc%T&;mz&t $Vc%S&:uz&| $Vc%S&:}z&D $Vc%S&:Ez&L %fd%S':Mz&T $Vc%S&:Uz&^ Vh_z&f figz&n Vhoz&v Vhwz&~ Vhz&F VhGz&N fiOz&V VhWz&` !$&az&f 6t? FS8Bgz&n :4? Hsh<Xoz&v =d? Hs?Dwz&~ =d? Hsh?Xz&H	 0? FS2BI	z&P	 3D? Hs5DQ	z&X	 5d? FS7Y	z&b	 9$? Hsh;c	z&l	 1$? FS3Bm	z&v	 1$? FS3Bw	z&~	 8? Hs:D	z&F
 :4? Hsh<XG
z&N
 8? Hsh:XO
z&V
 24? FS4BW
z&b
 !$? FSc#Sc
z&j
 (? FSc*Sk
z&r
  ? FSc"Ss
z&z
 $T? HsPS&U{
z&B +D? HsPS-UCz&J -d? FSc/SKz&R -d? HsPS/USz&Z 24? HsPS4U[z&b )$? FSd+Tcz&j +D? FSd-Tkz&x $T 	&yz&D %d 	'Ez&P $T 	&Qz&\ %d 	']z&h "4 5$iz&x #D 5%yz&H "4 5$Iz&Z t/ FT C[z&b / FT!Ccz&j / FT!Ckz& zz h   (      X   X   (   h      X      X   X      (      (   h   8   H   8   H   8   8   8   H   8   H   8      (   (   H>@>@ B"F#H"F#H$J35357' rE   