o
    پi                     @   sD  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  ddlm!Z!m"Z" ddl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.m/Z/ dgZ0G dd dej1Z2G dd dej1Z3G dd dej1Z4eefeefe!e"fe!e"feefeefdZ5de	ee6f de7de8fddZ9G dd dej1Z:ddej1dee6 de8d dfd!d"Z;d#d$ Z<dd&d'Z=d d)d*Z>d d+d,Z?e-i d-e>d.d/d0dd1d2e>d.d/d0dd1d3e>d.d4d4d5d6e>d.d4d4d7d8d9e>d:d.d0d/d;d<e>d=d.d0d/d;d>e>d?d/d@dAe>dBd.d0d/d;dCe>dDd.d0d/d;dEe>dFd.d0d/d;dGe>dHd.d/d0ddIdJe>d.d/d0dd1dKe>dLd.d/d0ddIdMe>dNd.d/d0ddIdOe>dPd.d/d0ddIdQe>d.dRdSddTdUe>d.dRdSddVdWi dXe>d.dRdSddVdWdYe>d.d/dZd[d\e>d.dRdSddZd]d^e>d.dRdSddZd]d_e>d.d/dZd[d`e>d.d/dZd[dae>dbd.d0dd;dce>ddd.d0dd;dee>dfd.d0dd;dge>dhd.d0dd;die>djd.d0dd;dke>dld.d0dd;dme>dnd.d0dd;doe>dpd.d0dd;dqe>drd.d0dd;dse>dtd.dRdSddVdudve>dwd.dRdSddVdui dxe>dyd.dRdSddVdudze>d{d.dRdSddVdud|e>d}d.dRdSddVdud~e>dd.ddde>dd.ddde>dd.ddde>dd.ddde>dd.ddde?dd.d0dd;de?dd.dRdSddVdude?dd.d0dd;de?dd.dRdSddVdude?dd.d0dd;de?dd.dRdSddVdude?dd.d0dd;de?dd.dRdSddVdude?dd.dRdSddVdui de?dd.ddddVdude?dd.d0d/d;de?dd.d0d/d;de?dd.d0d/d;de?dd.d0dd;de?dd.d0dd;de?dd.d0dd;de?dd.d0dd;de?dd.d0dd;de?dd.ddde?dd.ddde?dd.ddde?dd.ddde?dd.ddde?dd.ddde?dd.ddde?dd.ddi de> de>d.eed?dddÍde>d.eedRdSddVdōde>d.eeddddÍde>d.eedRdSddVdōde>d.eed?dddÍde>d.eedRdSddÍde>d.eed?dddÍde>d.eedRdSddVdōde>d.eed?dddÍde>d.eedZd?dddЍde>d.eedZddddЍde>d.eedZdRdSddVdӍde>d.eedZdRdSddVdӍde>d.eedZd?dddЍde>d.eed?dddd؍de>d.eed?dddd؍e>d.eed?dddd؍e>d.eeddddd؍e>d.eeddddd؍e>d.eed?dddd؍e>d.eeddddd؍e>d.eeddddd؍e>d.eed?dddd؍e>d.eed?dddd؍e>d.d4d4ddd/dÍe>d.d4d4ddd/dÍe>d.d4d4ddd/dÍdޜZ@e.dd e:fddZAe.dd e:fddZBe.dd e:fddZCe.dd e:fddZDe.dd e:fddZEe.dd e:fddZFe.dd e:fddZGe.dd e:fddZHe.dd e:fddZIe.dd e:fddZJe.dd e:fddZKe.dd e:fddZLe.dd e:fddZMe.dd e:fddZNe.dd e:fddZOe.dd e:fddZPe.dd e:fdd ZQe.dd e:fddZRe.dd e:fddZSe.dd e:fddZTe.dd e:fddZUe.dd e:fd	d
ZVe.dd e:fddZWe.dd e:fddZXe.dd e:fddZYe.dd e:fddZZe.dd e:fddZ[e.dd e:fddZ\e.dd e:fddZ]e.dd e:fddZ^e.dd e:fddZ_e/e`dadcdedgdidsdvdxdzd|d~ddddd dS (!  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MlpGlobalResponseNormMlpLayerNorm2d	LayerNorm	RmsNorm2dRmsNormcreate_conv2dget_act_layerget_norm_layermake_divisible	to_ntuple)SimpleNorm2d
SimpleNorm)NormMlpClassifierHeadClassifierHead   )build_model_with_cfg)feature_take_indices)named_applycheckpoint_seq)generate_default_cfgsregister_modelregister_model_deprecationsConvNeXtc                       sN   e Zd ZdZddededededdf
 fd	d
ZdejdejfddZ  Z	S )
DownsamplezDownsample module for ConvNeXt.r   in_chsout_chsstridedilationreturnNc                    s   t    |dkr|nd}|dks|dkr,|dkr|dkrtntj}|d|ddd| _nt | _||kr@t||ddd| _dS t | _dS )zInitialize Downsample module.

        Args:
            in_chs: Number of input channels.
            out_chs: Number of output channels.
            stride: Stride for downsampling.
            dilation: Dilation rate.
        r      TF)	ceil_modecount_include_pad)r+   N)	super__init__r   nn	AvgPool2dpoolIdentityr   conv)selfr)   r*   r+   r,   
avg_strideavg_pool_fn	__class__ H/home/ubuntu/.local/lib/python3.10/site-packages/timm/models/convnext.pyr2   >   s   
	
zDownsample.__init__xc                 C      |  |}| |}|S Forward pass.)r5   r7   r8   r?   r=   r=   r>   forwardT      

zDownsample.forwardr   r   )
__name__
__module____qualname____doc__intr2   torchTensorrD   __classcell__r=   r=   r;   r>   r(   ;   s    $r(   c                       s   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dZdejdejfddZ  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.
    N   r   rF      FTư>gelu        r)   r*   kernel_sizer+   r,   	mlp_ratioconv_mlp	conv_biasuse_grnls_init_value	act_layer
norm_layer	drop_pathc              	      s  t    |p|}td|}t|}|s|rtnt}t|	r tnt|d}|| _	t
|||||d d|d| _||| _||t|| |d| _|
durUt|
t| nd| _||ksh|dksh|d |d krtt||||d d	| _nt | _|d
krt|| _dS t | _dS )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.
        r.   )use_convr   T)rU   r+   r,   	depthwisebias)r[   Nr   )r+   r,   rT   )r1   r2   r   r   r   r   r   r   r   use_conv_mlpr   conv_dwnormrK   mlpr3   	ParameterrL   onesgammar(   shortcutr6   r   r]   )r8   r)   r*   rU   r+   r,   rV   rW   rX   rY   rZ   r[   r\   r]   	mlp_layerr;   r=   r>   r2   g   s0   
!
	" 
$zConvNeXtBlock.__init__r?   r-   c                 C   s   |}|  |}| jr| |}| |}n|dddd}| |}| |}|dddd}| jdur@|| jdddd}| || 	| }|S )rB   r   r.      r   N)
rb   ra   rc   rd   permuterg   mulreshaper]   rh   )r8   r?   rh   r=   r=   r>   rD      s   




zConvNeXtBlock.forward)NrP   r   rF   rQ   FTFrR   rS   NrT   )rG   rH   rI   rJ   rK   r   r   r   floatboolstrr   r2   rL   rM   rD   rN   r=   r=   r;   r>   rO   [   sT    	

;rO   c                       s   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dZdejdejfddZ  ZS )ConvNeXtStagez!ConvNeXt stage (multiple blocks).rP   r.   rF   N      ?FTrS   r)   r*   rU   r+   depthr,   drop_path_ratesrZ   rW   rX   rY   r[   r\   norm_layer_clr-   c                    s  t    d| _||ks|dks|d |d krI|dks$|d |d kr&dnd}|d dkr0dnd}t||t|||||d ||
d| _|}nt | _|pTdg| }g }t|D ]}|	t
||||d || ||	|
|||	rr|n|d |}q[tj| | _d	S )
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.
        Fr   r   r.   same)rU   r+   r,   paddingr`   rT   )r)   r*   rU   r,   r]   rZ   rW   rX   rY   r[   r\   N)r1   r2   grad_checkpointingr3   
Sequentialr   
downsampler6   rangeappendrO   blocks)r8   r)   r*   rU   r+   rt   r,   ru   rZ   rW   rX   rY   r[   r\   rv   ds_kspadstage_blocksir;   r=   r>   r2      sJ   
#  

zConvNeXtStage.__init__r?   c                 C   s8   |  |}| jrtj st| j|}|S | |}|S rA   )r{   ry   rL   jitis_scriptingr#   r~   rC   r=   r=   r>   rD     s   

zConvNeXtStage.forward)rP   r.   r.   rF   Nrs   FTFrS   NN)rG   rH   rI   rJ   rK   r   r   r   ro   rp   r   rq   r   r2   rL   rM   rD   rN   r=   r=   r;   r>   rr      s\    

	

Lrr   )	layernormlayernorm2d
simplenormsimplenorm2drmsnorm	rmsnorm2dr\   rW   norm_epsc                 C   s   | pd} | t v r0|rt |  d nt |  d }t |  d } |d ur,t| |d} t||d}| |fS |s6J dt| } | }|d urFt||d}| |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\   rW   r   rv   r=   r=   r>   _get_norm_layers  s    r   c                +       s:  e Zd ZdZ										
												dJd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(d)ZejjdKd*e
d+eeeeef f fd,d-ZejjdLd.e
d+dfd/d0Zejjd+ejfd1d2ZdMdedee d+dfd3d4Z				5	dNd6ejd7eeeee f  d8e
d9e
d:ed;e
d+eeej eejeej f f fd<d=Z	>		dOd7eeee f d?e
d@e
d+ee fdAdBZd6ejd+ejfdCdDZdKd6ejdEe
d+ejfdFdGZd6ejd+ejfdHdIZ  ZS )Pr'   z|ConvNeXt model architecture.

    A PyTorch impl of : `A ConvNet for the 2020s`  - https://arxiv.org/pdf/2201.03545.pdf
    rj     avg    rj   rj   	   rj   `           rP   rR   patchrQ   rs   FNTrS   rT   in_chansnum_classesglobal_pooloutput_stridedepths.dimskernel_sizesrZ   	stem_type
patch_sizehead_init_scalehead_norm_firsthead_hidden_sizerW   rX   rY   r[   r\   r   	drop_ratedrop_path_ratec           "         s  t    |dv sJ td|}t|||\}}t|}|| _|| _g | _|	dv s,J |	dkrHt	tj
||d |
|
|d||d | _|
}n>d|	v rTt|d d n|d }tj	td	tj
||d
dd|dd|	v rm| nd	tj
||d d
dd|d||d g | _d}t	 | _dd td|t||D }g }|d }|}d}tdD ][}|dks|dkrdnd}||kr|dkr||9 }d}||9 }|dv rdnd} || }!|t||!|| || |f|| || |||||||d |!}|  jt||d| dg7  _qtj	| | _| | _| _|r,|rJ || j| _t| j||| jd| _nt | _t| j|||| j|dd| _| jj| _ttt |d|  d	S )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.
        )      r   rQ   )r   overlapoverlap_tieredoverlap_actr   r   )rU   r+   r`   tieredr.   Nrj   r   )rU   r+   rx   r`   actc                 S   s   g | ]}|  qS r=   )tolist).0r?   r=   r=   r>   
<listcomp>|  s    z%ConvNeXt.__init__.<locals>.<listcomp>)r   r.   )rU   r+   r,   rt   ru   rZ   rW   rX   rY   r[   r\   rv   zstages.)num_chs	reductionmodule)	pool_typer   rS   )hidden_sizer   r   r\   r[   )r   )!r1   r2   r   r   r   r   r   feature_infor3   rz   Conv2dstemr   filterstagesrL   linspacesumsplitr|   r}   rr   dictnum_featuresr   norm_prer   headr6   r   r"   r   _init_weights)"r8   r   r   r   r   r   r   r   rZ   r   r   r   r   r   rW   rX   rY   r[   r\   r   r   r   rv   stem_stridemid_chsdp_ratesr   prev_chscurr_strider,   r   r+   first_dilationr*   r;   r=   r>   r2   0  s   
/
 


""



	zConvNeXt.__init__coarser-   c                 C   s   t d|rddS g d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   )r8   r   r=   r=   r>   group_matcher  s   
zConvNeXt.group_matcherenablec                 C   s   | j D ]}||_qdS )zEnable or disable gradient checkpointing.

        Args:
            enable: Whether to enable gradient checkpointing.
        N)r   ry   )r8   r   sr=   r=   r>   set_grad_checkpointing  s   
zConvNeXt.set_grad_checkpointingc                 C   s   | j jS )zGet the classifier module.)r   fc)r8   r=   r=   r>   get_classifier  s   zConvNeXt.get_classifierc                 C   s   || _ | j|| dS )zReset the classifier head.

        Args:
            num_classes: Number of classes for new classifier.
            global_pool: Global pooling type.
        N)r   r   reset)r8   r   r   r=   r=   r>   reset_classifier  s   zConvNeXt.reset_classifierNCHWr?   indicesrc   
stop_early
output_fmtintermediates_onlyc                 C   s   |dv sJ dg }t t| j|\}}	| |}t| jd }
tj s'|s+| j}n	| jd|	d  }t|D ] \}}||}||v rX|rS||
krS|| 	| q8|| q8|r]|S ||
krf| 	|}||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).
        )r   zOutput shape must be NCHW.r   N)
r!   lenr   r   rL   r   r   	enumerater}   r   )r8   r?   r   rc   r   r   r   intermediatestake_indices	max_indexlast_idxr   feat_idxstager=   r=   r>   forward_intermediates  s(   


zConvNeXt.forward_intermediatesr   
prune_norm
prune_headc                 C   sJ   t t| j|\}}| jd|d  | _|rt | _|r#| 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   r3   r6   r   r   )r8   r   r   r   r   r   r=   r=   r>   prune_intermediate_layers  s   
z"ConvNeXt.prune_intermediate_layersc                 C   s"   |  |}| |}| |}|S )z/Forward pass through feature extraction layers.)r   r   r   rC   r=   r=   r>   forward_features/  s   


zConvNeXt.forward_features
pre_logitsc                 C   s   |r	| j |ddS |  |S )zForward pass through classifier head.

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

        Returns:
            Output tensor.
        T)r   )r   )r8   r?   r   r=   r=   r>   forward_head6  s   
zConvNeXt.forward_headc                 C   r@   rA   )r   r   rC   r=   r=   r>   rD   B  rE   zConvNeXt.forward)rj   r   r   r   r   r   rP   rR   r   rQ   rs   FNFTFrS   NNrT   rT   F)T)N)NFFr   F)r   FT)rG   rH   rI   rJ   rK   rq   r   r   r   ro   rp   r   r2   rL   r   ignorer   r   r   r   r3   Moduler   r   rM   r   r   r   r   rD   rN   r=   r=   r;   r>   r'   *  s    

	

 
&	 
4
rs   r   namer   r-   c                 C   s   t | tjrt| jdd | jdurtj| j dS dS t | tjrGt| jdd tj| j |rId|v rK| jj	
| | jj	
| dS dS dS dS )zInitialize model weights.

    Args:
        module: Module to initialize.
        name: Module name.
        head_init_scale: Scale factor for head initialization.
    g{Gz?)stdNhead.)
isinstancer3   r   r   weightr`   initzeros_Lineardatamul_)r   r   r   r=   r=   r>   r   I  s   
r   c                 C   s  d| v sd| v r
| S d| v r| d } i }d| v r]dd |   D }d| v r9| d |d< t| d jd	 |d
< |S d| v r[| d |d< | d |d< | d |d< t| d jd	 |d
< |S d	dl}|   D ]f\}}|dd}|dd|}|dd|}|dd}|dd}d|v r|dd}|dd}||jd  }|d!d"}|d#r|d$d%}|j	d&krd'|vr|
 | j}||}|||< qe|S )(z Remap FB checkpoints -> timm zhead.norm.weightznorm_pre.weightmodelzvisual.trunk.stem.0.weightc                 S   s(   i | ]\}}| d r|d d|qS )zvisual.trunk.r   )
startswithreplace)r   kvr=   r=   r>   
<dictcomp>f  s   ( z(checkpoint_filter_fn.<locals>.<dictcomp>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.weightNz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dwconvrb   pwconvzmlp.fcgrnzgrn.betazmlp.grn.biasz	grn.gammazmlp.grn.weightrk   r   zhead.fc.znorm.rc   z	head.normr.   r   )itemsrL   zerosshaperer   subrn   r   ndim
state_dict)r  r   out_dictr  r   r   model_shaper=   r=   r>   checkpoint_filter_fn]  sH   


r  Fc                 K   sB   | dddkr|dd tt| |fttdddd	|}|S )
Npretrained_cfgr   fcmaepretrained_strictF)r   r   r.   rj   T)out_indicesflatten_sequential)pretrained_filter_fnfeature_cfg)get
setdefaultr    r'   r  r   )variant
pretrainedkwargsr   r=   r=   r>   _create_convnext  s   
r  r   c                 K   s   | dddddt tddd
|S )	Nr   rj      r  rP   rP         ?bicubicstem.0head.fc)
urlr   
input_size	pool_sizecrop_pctinterpolationmeanr   
first_conv
classifierr	   r
   r  r  r=   r=   r>   _cfg  s   r&  c                 K   s&   | dddddt tdddd	d
dd|S )Nr   r  r  r  r  r  r  zcc-by-nc-4.0zarXiv:2301.00808zGConvNeXt-V2: Co-designing and Scaling ConvNets with Masked Autoencodersz/https://github.com/facebookresearch/ConvNeXt-V2)r  r   r  r  r  r   r!  r   r"  r#  license	paper_ids
paper_name
origin_urlr$  r%  r=   r=   r>   _cfgv2  s   	r+  zconvnext_tiny.in12k_ft_in1kztimm/gffffff?)rj      r,  )	hf_hub_idr  test_input_sizetest_crop_pctzconvnext_small.in12k_ft_in1kz&convnext_zepto_rms.ra4_e3600_r224_in1k)      ?r0  r0  )r-  r!  r   z*convnext_zepto_rms_ols.ra4_e3600_r224_in1kg?)r-  r!  r   r  zconvnext_atto.d2_in1kzrhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_atto_d2-01bb0f51.pth)r  r-  r.  r/  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)rj      r1  )r.  r/  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)r  r-  r  r.  r/  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)rj   r   r   )   r2  )r-  r  r  r  zconvnext_tiny.in12k_ft_in1k_384squash)r-  r  r  r  	crop_modez convnext_small.in12k_ft_in1k_384zconvnext_nano.in12ki-.  )r-  r  r   zconvnext_nano.r384_in12k)r-  r  r  r  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)r  r-  r  r  r  r4  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  )r  r-  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)rj      r5  )   r6  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   )r-  r!  r   r  r  r  z3convnext_base.clip_laion2b_augreg_ft_in12k_in1k_384)r-  r!  r   r  r  r  r4  z6convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_320)rj   @  r7  )
   r8  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)r-  r!  r   r   r  r  r  z1convnext_large_mlp.clip_laion2b_soup_ft_in12k_320z3convnext_large_mlp.clip_laion2b_augreg_ft_in12k_384)r-  r!  r   r   r  r  r  r4  z1convnext_large_mlp.clip_laion2b_soup_ft_in12k_384z+convnext_xxlarge.clip_laion2b_soup_ft_in12kzconvnext_base.clip_laion2b  )r-  r!  r   r  r  r  r   z!convnext_base.clip_laion2b_augregr      )rj      r;  )   r<  )zconvnext_base.clip_laionazconvnext_base.clip_laiona_320z$convnext_base.clip_laiona_augreg_320z&convnext_large_mlp.clip_laion2b_augregz&convnext_large_mlp.clip_laion2b_ft_320z+convnext_large_mlp.clip_laion2b_ft_soup_320z"convnext_xxlarge.clip_laion2b_soupz$convnext_xxlarge.clip_laion2b_rewindztest_convnext.r160_in1kztest_convnext2.r160_in1kztest_convnext3.r160_in1kc                 K   2   t ddddd}tdd| it |fi |}|S )	Nr.   r.   rQ   r.   r   @      r1  Tr   r   r   rW   r\   convnext_zepto_rmsr  )rC  r   r  r  r  
model_argsr   r=   r=   r>   rC  8     rC  c                 K   s4   t dddddd}td	d| it |fi |}|S )
Nr>  r?  Tr   r   )r   r   rW   r\   r   convnext_zepto_rms_olsr  )rH  rD  rE  r=   r=   r>   rH  @  
   
rH  c                 K   0   t dddd}tdd| it |fi |}|S )Nr.   r.      r.   (   P   r;  r7  Tr   r   rW   convnext_attor  )rQ  rD  rE  r=   r=   r>   rQ  I     rQ  c                 K   r=  )	NrK  rM  Tr   r   r   rW   r   convnext_atto_olsr  )rT  rD  rE  r=   r=   r>   rT  Q  rG  rT  c                 K   r=  )	NrK  rM  Tr   rB  convnext_atto_rmsr  )rU  rD  rE  r=   r=   r>   rU  Y  rG  rU  c                 K   rJ  )NrK  0   r   r   r   TrP  convnext_femtor  )rX  rD  rE  r=   r=   r>   rX  a  rR  rX  c                 K   r=  )	NrK  rV  Tr   rS  convnext_femto_olsr  )rY  rD  rE  r=   r=   r>   rY  i  rG  rY  c                 K   rJ  )NrK  r@  rA  r1  r5  TrP  convnext_picor  )r[  rD  rE  r=   r=   r>   r[  q  rR  r[  c                 K   r=  )	NrK  rZ  Tr   rS  convnext_pico_olsr  )r\  rD  rE  r=   r=   r>   r\  y  rG  r\  c                 K   rJ  )Nr.   r.   r   r.   rO  r;  r7  r9  TrP  convnext_nanor  )r_  rD  rE  r=   r=   r>   r_    rR  r_  c                 K   r=  )	Nr]  r^  Tr   rS  convnext_nano_olsr  )r`  rD  rE  r=   r=   r>   r`    rG  r`  c                 K   s2   t ddddd}tdd| it |fi |}|S )Nr   r   T)r   r   r   rW   convnext_tiny_hnfr  )ra  rD  rE  r=   r=   r>   ra    rG  ra  c                 K   s.   t ddd}tdd| it |fi |}|S )Nr   r   r   r   convnext_tinyr  )rc  rD  rE  r=   r=   r>   rc    s   rc  c                 K   6   t g dg dd}tdd| it |fi |}|S )Nrj   rj      rj   r   rb  convnext_smallr  )rg  rD  rE  r=   r=   r>   rg       rg  c                 K   rd  )Nre  rA  r1  r5  r:  rb  convnext_baser  )rj  rD  rE  r=   r=   r>   rj    rh  rj  c                 K   rd  )Nre  r   r   r      rb  convnext_larger  )rm  rD  rE  r=   r=   r>   rm    rh  rm  c                 K   s8   t g dg ddd}tdd| it |fi |}|S )Nre  rk  rl  )r   r   r   convnext_large_mlpr  )rn  rD  rE  r=   r=   r>   rn    s   rn  c                 K   rd  )Nre  )r1  r5  r:  i   rb  convnext_xlarger  )ro  rD  rE  r=   r=   r>   ro    rh  ro  c                 K   s@   t g dg d|ddd}tdd| it |fi |}|S )	N)rj   rQ      rj   )r   r   rl  i   r   h㈵>)r   r   r   convnext_xxlarger  )rr  r   popr  rE  r=   r=   r>   rr    s   rr  c                 K   4   t dddd dd}tdd| it |fi |}|S )NrK  rM  Tr   r   rY   rZ   rW   convnextv2_attor  )rw  rD  rE  r=   r=   r>   rw    rI  rw  c                 K   ru  )NrK  rV  Trv  convnextv2_femtor  )rx  rD  rE  r=   r=   r>   rx    rI  rx  c                 K   ru  )NrK  rZ  Trv  convnextv2_picor  )ry  rD  rE  r=   r=   r>   ry    rI  ry  c                 K   ru  )Nr]  r^  Trv  convnextv2_nanor  )rz  rD  rE  r=   r=   r>   rz    rI  rz  c                 K   s2   t dddd d}tdd| it |fi |}|S )Nr   r   Tr   r   rY   rZ   convnextv2_tinyr  )r|  rD  rE  r=   r=   r>   r|    s   r|  c                 K   :   t g dg ddd d}tdd| it |fi |}|S )Nre  r   Tr{  convnextv2_smallr  )r~  rD  rE  r=   r=   r>   r~       r~  c                 K   r}  )Nre  ri  Tr{  convnextv2_baser  )r  rD  rE  r=   r=   r>   r    r  r  c                 K   r}  )Nre  rk  Tr{  convnextv2_larger  )r  rD  rE  r=   r=   r>   r    r  r  c                 K   r}  )Nre  )i`  i  i  i   Tr{  convnextv2_huger  )r  rD  rE  r=   r=   r>   r  
  r  r  c                 K   B   t g dg d|dddd}td	d| it |fi |}|S )
N)r   r.   rQ   r.   )   r   rW  r@  r   rq  	gelu_tanhr   r   r   r[   test_convnextr  )r  rs  rE  r=   r=   r>   r        r  c                 K   r  )
Nr   r   r   r   r   r@  r   rA  r   rq  r  r  test_convnext2r  )r  rs  rE  r=   r=   r>   r    r  r  c                 K   sD   t g dg d|ddddd}td
d	| it |fi |}|S )Nr  r  r   rq  )rP   r<  r<  rj   silu)r   r   r   r   r[   test_convnext3r  )r  rs  rE  r=   r=   r>   r    s
   r  )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)Nrs   r   )r   )arJ   	functoolsr   typingr   r   r   r   r   r   rL   torch.nnr3   	timm.datar	   r
   r   r   timm.layersr   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(   rO   rr   r   rq   rp   ro   r   r'   r   r  r  r&  r+  default_cfgsrC  rH  rQ  rT  rU  rX  rY  r[  r\  r_  r`  ra  rc  rg  rj  rm  rn  ro  rr  rw  rx  ry  rz  r|  r~  r  r  r  r  r  r  rG   r=   r=   r=   r>   <module>   sZ   ' @ ZZ
  $!*	#'+.26:>AEHKNQUY]aejnrv{               !  &  *  .  2  6  :  >  B  F  J  O  S  W  [  _  c  g  k  p  t  x  |           	                        !    &    *    .    3    8    =    A    E    I    M    S    W    [   
   