a
    d                  `   @   s  d Z ddlmZ ddlmZ ddl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 ddlmZ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Z)G dd dej*Z+G dd dej*Z,G dd dej*Z-G dd dej*Z.dddZ/dd Z0dddZ1dddZ2dd d!Z3e&e2d"d#d$dd%e2d"d#d$dd%e2d&d"d$d#d'e2d(d"d$d#d'e2d)d"d$d#d'e2d*d"d$d#d'e2d+d"d$d#d'e2d,d"d#d$dd-e2d"d#d$dd%e2d.d"d#d$dd-e2d/d"d#d$dd-e2d0d"d#d$dd-e2d"d1d2dd3d4e2d"d1d2dd3d4e2d"d#d5d6e2d"d#d5d6e2d"d#d5d6e2d7d"d$dd'e2d8d"d$dd'e2d9d"d$dd'e2d:d"d$dd'e2d;d"d$dd'e2d<d"d$dd'e2d=d"d$dd'e2d>d"d$dd'e2d?d"d$dd'e2d@d"d1d2dd3dAe2dBd"d1d2dd3dAe2dCd"d1d2dd3dAe2dDd"d1d2dd3dAe2dEd"d1d2dd3dAe2dFd"dGdHe2dId"dGdHe2dJd"dGdHe2dKd"dGdHe2dLd"dGdHe3dMd"d$dd'e3dNd"d1d2dd3dAe3dOd"d$dd'e3dPd"d1d2dd3dAe3dQd"d$dd'e3dRd"d1d2dd3dAe3dSd"d$dd'e3dTd"d1d2dd3dAe3dUd"d1d2dd3dAe3dVd"dWdXdd3dAe3dYd"d$d#d'e3dZd"d$d#d'e3d[d"d$d#d'e3d\d"d$dd'e3d]d"d$dd'e3d^d"d$dd'e3d_d"d$dd'e3d`d"d$dd'e3dad"ddHe3dbd"ddHe3dcd"ddHe3ddd"ddHe3ded"ddHe3dfd"ddHe3dgd"ddHe3dhd"ddHe2 e2d"eedidjddke2d"eed1d2dd3dle2d"eedmdnddke2d"eed1d2dd3dle2d"eedidjddke2d"eed1d2ddke2d"eedidjddke2d"eed1d2dd3dle2d"eedidjddke2d"eed5didjddoe2d"eed5dmdnddoe2d"eed5d1d2dd3dpe2d"eed5d1d2dd3dpe2dqdreedidjddsdte2dudreedidjddsdte2dvdreedidjddsdte2dwdreedmdnddsdte2dxdreedmdnddsdte2dydreedidjddzdte2d{dreedmdnddzdte2d|dreedmdnddzdte2d}dreedidjdd~dte2ddreedidjdd~dtdVZ4e'de.dddZ5e'de.dddZ6e'de.dddZ7e'de.dddZ8e'de.dddZ9e'de.dddZ:e'de.dddZ;e'de.dddZ<e'de.dddZ=e'de.dddZ>e'de.dddZ?e'de.dddZ@e'de.dddZAe'de.dddZBe'de.dddZCe'de.dddZDe'de.dddZEe'de.dddZFe'de.dddZGe'de.dddZHe'de.dddZIe'de.dddZJe'de.dddZKe'de.dddZLe'de.dddZMe(eNddddddddddddddddÜ 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
    )OrderedDict)partial)CallableOptionalTupleUnionN)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDOPENAI_CLIP_MEANOPENAI_CLIP_STD)trunc_normal_AvgPool2dSameDropPathMlpGlobalResponseNormMlpLayerNorm2d	LayerNormcreate_conv2dget_act_layermake_divisible	to_ntuple)NormMlpClassifierHeadClassifierHead   )build_model_with_cfg)named_applycheckpoint_seq)generate_default_cfgsregister_modelregister_model_deprecationsConvNeXtc                       s&   e Zd Zd fdd	Zdd Z  ZS )
Downsampler   c                    s   t    |dkr|nd}|dks*|dkrX|dkr>|dkr>tntj}|d|ddd| _n
t | _||kr~t||ddd| _n
t | _d S )Nr      TF)Z	ceil_modeZcount_include_pad)stride)	super__init__r   nnZ	AvgPool2dpoolIdentityr   conv)selfin_chsout_chsr#   dilationZ
avg_strideZavg_pool_fn	__class__ ]/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/timm/models/convnext.pyr%   <   s    

zDownsample.__init__c                 C   s   |  |}| |}|S N)r'   r)   r*   xr0   r0   r1   forwardJ   s    

zDownsample.forward)r   r   __name__
__module____qualname__r%   r5   __classcell__r0   r0   r.   r1   r!   :   s   r!   c                       sl   e Zd ZdZdeee eeeeeeef f ee	e	e	ee ee
ef ee ed fddZdd Z  ZS )ConvNeXtBlockaa   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   r   r      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|}|s6|r2tnt}t|	r@tnt|d}|| _	t
|||||d d|d| _||| _||t|| |d| _|
durt|
t| nd| _||ks|dks|d |d krt||||d d	| _n
t | _|d
krt|n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"   )Zuse_convr   T)rB   r#   r-   Z	depthwisebias)rH   Nr   )r#   r-   rA   )r$   r%   r   r   r   r   r   r   r   use_conv_mlpr   conv_dwnormintmlpr&   	ParametertorchZonesgammar!   shortcutr(   r   rJ   )r*   r+   r,   rB   r#   r-   rC   rD   rE   rF   rG   rH   rI   rJ   Z	mlp_layerr.   r0   r1   r%   [   s0    !
	
" 
zConvNeXtBlock.__init__c                 C   s   |}|  |}| jr*| |}| |}n4|dddd}| |}| |}|dddd}| jd ur|| jdddd}| || 	| }|S )Nr   r"      r   )
rM   rL   rN   rP   ZpermuterS   mulreshaperJ   rT   )r*   r4   rT   r0   r0   r1   r5      s    




zConvNeXtBlock.forward)Nr<   r   r=   r>   FTFr?   r@   NrA   )r7   r8   r9   __doc__rO   r   r   r   floatboolstrr   r%   r5   r:   r0   r0   r.   r1   r;   P   s:               
;r;   c                       s&   e Zd Zd fd	d
	Zdd Z  ZS )ConvNeXtStager<   r"   r=   N      ?FTr@   c                    s  t    d| _||ks0|dks0|d |d kr|dksH|d |d krLdnd}|d dkr`dnd}t||t|||||d ||
d| _|}n
t | _|pdg| }g }t|D ]<}|	t
||||d || ||	|
|||	r|n|d |}qtj| | _d S )	NFr   r   r"   Zsame)rB   r#   r-   paddingrK   rA   )r+   r,   rB   r-   rJ   rG   rD   rE   rF   rH   rI   )r$   r%   grad_checkpointingr&   
Sequentialr   
downsampler(   rangeappendr;   blocks)r*   r+   r,   rB   r#   depthr-   drop_path_ratesrG   rD   rE   rF   rH   rI   norm_layer_clZds_kspadZstage_blocksir.   r0   r1   r%      sJ    
  

zConvNeXtStage.__init__c                 C   s6   |  |}| jr(tj s(t| j|}n
| |}|S r2   )rb   r`   rR   jitZis_scriptingr   re   r3   r0   r0   r1   r5      s
    

zConvNeXtStage.forward)r<   r"   r"   r=   Nr^   FTFr@   NNr6   r0   r0   r.   r1   r]      s               :r]   c                       s   e Zd ZdZd&eeeeeedf eedf eeeedf f ee	 eee	e
ee e
e
e
eeef eeeef  ee	 e	e	d fddZejjd'ddZejjd(ddZejjdd Zd)ddZdd  Zd*e
d!d"d#Zd$d% Z  ZS )+r    zl ConvNeXt
        A PyTorch impl of : `A ConvNet for the 2020s`  - https://arxiv.org/pdf/2201.03545.pdf
    rU     avg    rU   rU   	   rU   `           r<   r?   patchr>   r^   FNTr@   rA   .)in_chansnum_classesglobal_pooloutput_stridedepthsdimskernel_sizesrG   	stem_type
patch_sizehead_init_scalehead_norm_firsthead_hidden_sizerD   rE   rF   rH   rI   norm_eps	drop_ratedrop_path_ratec           "         s  t    |dv sJ td|}|du r\t}|r6|nt}|durt||d}t||d}n$|shJ d|}|durt||d}|| _|| _g | _|	dv sJ |	dkrt	
t	j||d |
|
|d	||d | _|
}ndd
|	v rt|d d n|d }t	
t	j||ddd|dt	j||d ddd|d||d | _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|rhJ || j| _t| j||| jd| _n&t	 | _t| j|||| j|dd| _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.
        )      rn   r>   N)ZepszcIf a norm_layer is specified, conv MLP must be used so all norm expect rank-4, channels-first input)rv   overlapoverlap_tieredrv   r   )rB   r#   rK   Ztieredr"   rU   r   )rB   r#   r_   rK   c                 S   s   g | ]}|  qS r0   )tolist).0r4   r0   r0   r1   
<listcomp>G      z%ConvNeXt.__init__.<locals>.<listcomp>)r   r"   )rB   r#   r-   rf   rg   rG   rD   rE   rF   rH   rI   rh   zstages.)Znum_chsZ	reductionmodule)	pool_typer   r@   )Zhidden_sizer   r   rI   rH   )r   )r$   r%   r   r   r   r   rx   r   Zfeature_infor&   ra   Conv2dstemr   stagesrR   Zlinspacesumsplitrc   rd   r]   dictZnum_featuresnorm_prer   headr(   r   r   _init_weights)"r*   rw   rx   ry   rz   r{   r|   r}   rG   r~   r   r   r   r   rD   rE   rF   rH   rI   r   r   r   rh   Zstem_strideZmid_chsZdp_ratesr   Zprev_chsZcurr_strider-   rj   r#   Zfirst_dilationr,   r.   r0   r1   r%      s    /

 

"$


	zConvNeXt.__init__c                 C   s   t d|rdng ddS )Nz^stemz^stages\.(\d+)))z^stages\.(\d+)\.downsample)r   )z^stages\.(\d+)\.blocks\.(\d+)N)z	^norm_pre)i )r   re   )r   )r*   Zcoarser0   r0   r1   group_matcher  s    zConvNeXt.group_matcherc                 C   s   | j D ]
}||_qd S r2   )r   r`   )r*   enablesr0   r0   r1   set_grad_checkpointing  s    
zConvNeXt.set_grad_checkpointingc                 C   s   | j jS r2   )r   Zfc)r*   r0   r0   r1   get_classifier  s    zConvNeXt.get_classifierr   c                 C   s   | j || d S r2   )r   reset)r*   rx   ry   r0   r0   r1   reset_classifier  s    zConvNeXt.reset_classifierc                 C   s"   |  |}| |}| |}|S r2   )r   r   r   r3   r0   r0   r1   forward_features  s    


zConvNeXt.forward_features
pre_logitsc                 C   s   |r| j |ddS |  |S )NTr   )r   )r*   r4   r   r0   r0   r1   forward_head  s    zConvNeXt.forward_headc                 C   s   |  |}| |}|S r2   )r   r   r3   r0   r0   r1   r5     s    

zConvNeXt.forward)rU   rl   rm   rn   ro   rq   r<   r?   rv   r>   r^   FNFTFr@   NNrA   rA   )F)T)r   N)F)r7   r8   r9   rY   rO   r\   r   r   r   rZ   r[   r   r%   rR   rk   ignorer   r   r   r   r   r   r5   r:   r0   r0   r.   r1   r       sp                        


 


r^   c                 C   s   t | tjr4t| jdd | jd urtj| j nPt | tjrt| jdd tj| j |rd|v r| jj	
| | jj	
| d S )Ng{Gz?)stdhead.)
isinstancer&   r   r   ZweightrK   initZzeros_ZLineardataZmul_)r   namer   r0   r0   r1   r     s    
r   c                 C   s  d| v sd| v r| S d| v r$| d } i }d| v rdd |   D }d| v rp| d |d< t| d jd	 |d
< nDd| v r| d |d< | d |d< | d |d< t| d jd	 |d
< |S d	dl}|   D ]\}}|dd}|dd|}|dd|}|dd}|dd}d|v rB|dd}|dd}||jd  }|d!d"}|d#rf|d$d%}|j	d&krd'|vr|
 | j}||}|||< q|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. )
startswithreplace)r   kvr0   r0   r1   
<dictcomp>  r   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.\2ZdwconvrM   Zpwconvzmlp.fcZgrnzgrn.betazmlp.grn.biasz	grn.gammazmlp.grn.weightrV   r   zhead.fc.znorm.rN   z	head.normr"   r   )itemsrR   zerosshaperer   subrX   r   ndim
state_dict)r   r   Zout_dictr   r   r   Zmodel_shaper0   r0   r1   checkpoint_filter_fn  sF    


r   Fc                 K   sB   | dddkr|dd tt| |fttdddd	|}|S )
NZpretrained_cfgr   ZfcmaeZpretrained_strictF)r   r   r"   rU   T)Zout_indicesZflatten_sequential)Zpretrained_filter_fnZfeature_cfg)get
setdefaultr   r    r   r   )variant
pretrainedkwargsr   r0   r0   r1   _create_convnext  s    
r   r   c                 K   s   | dddddt tddd
|S )	Nrl   rU      r   r<   r<         ?bicubicstem.0head.fc)
urlrx   
input_size	pool_sizecrop_pctinterpolationmeanr   
first_conv
classifierr   r	   r   r   r0   r0   r1   _cfg  s    r   c                 K   s&   | dddddt tdddd	d
dd|S )Nrl   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   rx   r   r   r   r   r   r   r   r   licenseZ	paper_idsZ
paper_nameZ
origin_urlr   r   r0   r0   r1   _cfgv2  s    	r   ztimm/gffffff?)rU      r   )	hf_hub_idr   test_input_sizetest_crop_pctzrhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_atto_d2-01bb0f51.pth)r   r   r   r   zvhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_atto_ols_a2-78d1c8f3.pthzshttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_femto_d1-d71d5b4c.pthzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_femto_ols_d1-246bf2ed.pthzrhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_pico_d1-10ad7f0d.pthzvhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_pico_ols_d1-611f0ca7.pth)r   r   r   r   r   zshttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_nano_d1h-7eb4bdea.pthzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_nano_ols_d1h-ae424a9a.pthzwhttps://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/convnext_tiny_hnf_a2h-ab7e9df2.pth)rU   rt   rt   )   r   Zsquash)r   r   r   r   	crop_modei-.  )r   r   rx   zDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_1k_224.pthzEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_1k_224.pthzDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_224.pthzEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_224.pthzJhttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_224_ema.pthzDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pthzEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_1k_224_ema.pthzDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_1k_224_ema.pthzEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_1k_224_ema.pthzDhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_1k_384.pth)r   r   r   r   r   r   zEhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_1k_384.pthzDhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_384.pthzEhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_384.pthzJhttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_384_ema.pthzAhttps://dl.fbaipublicfiles.com/convnext/convnext_tiny_22k_224.pthiQU  )r   r   rx   zBhttps://dl.fbaipublicfiles.com/convnext/convnext_small_22k_224.pthzAhttps://dl.fbaipublicfiles.com/convnext/convnext_base_22k_224.pthzBhttps://dl.fbaipublicfiles.com/convnext/convnext_large_22k_224.pthzChttps://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_224.pthzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_nano_22k_224_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_nano_22k_384_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_tiny_22k_224_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_tiny_22k_384_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_base_22k_224_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_base_22k_384_ema.ptzXhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_large_22k_224_ema.ptzXhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_large_22k_384_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_huge_22k_384_ema.ptzWhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im22k/convnextv2_huge_22k_512_ema.pt)rU      r   )   r   zUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_atto_1k_224_ema.ptzVhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_femto_1k_224_ema.ptzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_pico_1k_224_ema.ptzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_nano_1k_224_ema.ptzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_tiny_1k_224_ema.ptzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_base_1k_224_ema.ptzVhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_large_1k_224_ema.ptzUhttps://dl.fbaipublicfiles.com/convnext/convnextv2/im1k/convnextv2_huge_1k_224_ema.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_atto_1k_224_fcmae.ptz[https://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_femto_1k_224_fcmae.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_pico_1k_224_fcmae.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_nano_1k_224_fcmae.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_tiny_1k_224_fcmae.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_base_1k_224_fcmae.ptz[https://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_large_1k_224_fcmae.ptzZhttps://dl.fbaipublicfiles.com/convnext/convnextv2/pt_only/convnextv2_huge_1k_224_fcmae.pt)rU      r   )r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r   )rU   @  r   )
   r   )r   r   r   rx   r   r   r   )r   r   r   rx   r   r   r   r   z,laion/CLIP-convnext_base_w-laion2B-s13B-b82Kzopen_clip_pytorch_model.bin  )r   Zhf_hub_filenamer   r   r   r   r   rx   z3laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augregz4laion/CLIP-convnext_base_w-laion_aesthetic-s13B-b82Kz8laion/CLIP-convnext_base_w_320-laion_aesthetic-s13B-b82Kz?laion/CLIP-convnext_base_w_320-laion_aesthetic-s13B-b82K-augregz5laion/CLIP-convnext_large_d.laion2B-s26B-b102K-augregru   z5laion/CLIP-convnext_large_d_320.laion2B-s29B-b131K-ftz:laion/CLIP-convnext_large_d_320.laion2B-s29B-b131K-ft-soupz9laion/CLIP-convnext_xxlarge-laion2B-s34B-b82K-augreg-soup   z;laion/CLIP-convnext_xxlarge-laion2B-s34B-b82K-augreg-rewind)Vzconvnext_tiny.in12k_ft_in1kzconvnext_small.in12k_ft_in1kzconvnext_atto.d2_in1kzconvnext_atto_ols.a2_in1kzconvnext_femto.d1_in1kzconvnext_femto_ols.d1_in1kzconvnext_pico.d1_in1kzconvnext_pico_ols.d1_in1kzconvnext_nano.in12k_ft_in1kzconvnext_nano.d1h_in1kzconvnext_nano_ols.d1h_in1kzconvnext_tiny_hnf.a2h_in1kzconvnext_tiny.in12k_ft_in1k_384z convnext_small.in12k_ft_in1k_384zconvnext_nano.in12kzconvnext_tiny.in12kzconvnext_small.in12kconvnext_tiny.fb_in22k_ft_in1kconvnext_small.fb_in22k_ft_in1kconvnext_base.fb_in22k_ft_in1kconvnext_large.fb_in22k_ft_in1k convnext_xlarge.fb_in22k_ft_in1kzconvnext_tiny.fb_in1kzconvnext_small.fb_in1kzconvnext_base.fb_in1kzconvnext_large.fb_in1k"convnext_tiny.fb_in22k_ft_in1k_384#convnext_small.fb_in22k_ft_in1k_384"convnext_base.fb_in22k_ft_in1k_384#convnext_large.fb_in22k_ft_in1k_384$convnext_xlarge.fb_in22k_ft_in1k_384convnext_tiny.fb_in22kconvnext_small.fb_in22kconvnext_base.fb_in22kconvnext_large.fb_in22kconvnext_xlarge.fb_in22kz#convnextv2_nano.fcmae_ft_in22k_in1kz'convnextv2_nano.fcmae_ft_in22k_in1k_384z#convnextv2_tiny.fcmae_ft_in22k_in1kz'convnextv2_tiny.fcmae_ft_in22k_in1k_384z#convnextv2_base.fcmae_ft_in22k_in1kz'convnextv2_base.fcmae_ft_in22k_in1k_384z$convnextv2_large.fcmae_ft_in22k_in1kz(convnextv2_large.fcmae_ft_in22k_in1k_384z'convnextv2_huge.fcmae_ft_in22k_in1k_384z'convnextv2_huge.fcmae_ft_in22k_in1k_512zconvnextv2_atto.fcmae_ft_in1kzconvnextv2_femto.fcmae_ft_in1kzconvnextv2_pico.fcmae_ft_in1kzconvnextv2_nano.fcmae_ft_in1kzconvnextv2_tiny.fcmae_ft_in1kzconvnextv2_base.fcmae_ft_in1kzconvnextv2_large.fcmae_ft_in1kzconvnextv2_huge.fcmae_ft_in1kzconvnextv2_atto.fcmaezconvnextv2_femto.fcmaezconvnextv2_pico.fcmaezconvnextv2_nano.fcmaezconvnextv2_tiny.fcmaezconvnextv2_base.fcmaezconvnextv2_large.fcmaezconvnextv2_huge.fcmaezconvnextv2_small.untrainedz/convnext_base.clip_laion2b_augreg_ft_in12k_in1kz3convnext_base.clip_laion2b_augreg_ft_in12k_in1k_384z6convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_320z6convnext_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_in12kz1convnext_large_mlp.clip_laion2b_soup_ft_in12k_320z3convnext_large_mlp.clip_laion2b_augreg_ft_in12k_384z1convnext_large_mlp.clip_laion2b_soup_ft_in12k_384zconvnext_base.clip_laion2bz!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_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_rewind)returnc                 K   s0   t dddd}tdd| it |fi |}|S )Nr"   r"      r"   (   P      r   Tr{   r|   rD   convnext_attor   )r   r   r   r   r   Z
model_argsr   r0   r0   r1   r   v  s    r   c                 K   s2   t ddddd}tdd| it |fi |}|S )	Nr   r   Tr   r{   r|   rD   r~   convnext_atto_olsr   )r   r   r   r0   r0   r1   r   ~  s    r   c                 K   s0   t dddd}tdd| it |fi |}|S )Nr   0   rr   rs   rt   Tr   convnext_femtor   )r   r   r   r0   r0   r1   r     s    r   c                 K   s2   t ddddd}tdd| it |fi |}|S )	Nr   r   Tr   r   convnext_femto_olsr   )r   r   r   r0   r0   r1   r     s    r   c                 K   s0   t dddd}tdd| it |fi |}|S )Nr   @      r   r   Tr   convnext_picor   )r  r   r   r0   r0   r1   r    s    r  c                 K   s2   t ddddd}tdd| it |fi |}|S )	Nr   r  Tr   r   convnext_pico_olsr   )r  r   r   r0   r0   r1   r    s    r  c                 K   s0   t dddd}tdd| it |fi |}|S )Nr"   r"   r   r"   r   r   r   r   Tr   convnext_nanor   )r  r   r   r0   r0   r1   r    s    r  c                 K   s2   t ddddd}tdd| it |fi |}|S )	Nr  r  Tr   r   convnext_nano_olsr   )r	  r   r   r0   r0   r1   r	    s    r	  c                 K   s2   t ddddd}tdd| it |fi |}|S )Nro   rq   T)r{   r|   r   rD   convnext_tiny_hnfr   )r
  r   r   r0   r0   r1   r
    s    r
  c                 K   s.   t ddd}tdd| it |fi |}|S )Nro   rq   r{   r|   convnext_tinyr   )r  r   r   r0   r0   r1   r    s    r  c                 K   s6   t g dg dd}tdd| it |fi |}|S )NrU   rU      rU   rq   r  convnext_smallr   )r  r   r   r0   r0   r1   r    s    r  c                 K   s6   t g dg dd}tdd| it |fi |}|S )Nr  r  r   r   r   r  convnext_baser   )r  r   r   r0   r0   r1   r    s    r  c                 K   s6   t g dg dd}tdd| it |fi |}|S )Nr  rs   rt   ru      r  convnext_larger   )r  r   r   r0   r0   r1   r    s    r  c                 K   s8   t g dg ddd}tdd| it |fi |}|S )Nr  r  r  )r{   r|   r   convnext_large_mlpr   )r  r   r   r0   r0   r1   r    s    r  c                 K   s6   t g dg dd}tdd| it |fi |}|S )Nr  )r   r   r   i   r  convnext_xlarger   )r  r   r   r0   r0   r1   r    s    r  c                 K   s@   t g dg d|ddd}tdd| it |fi |}|S )	N)rU   r>      rU   )rt   ru   r  i   r   gh㈵>)r{   r|   r   convnext_xxlarger   )r  )r   popr   r   r0   r0   r1   r    s    r  c                 K   s4   t dddd dd}tdd| it |fi |}|S )Nr   r   Tr{   r|   rF   rG   rD   convnextv2_attor   )r  r   r   r0   r0   r1   r    s
    
r  c                 K   s4   t dddd dd}tdd| it |fi |}|S )Nr   r   Tr  convnextv2_femtor   )r  r   r   r0   r0   r1   r    s
    
r  c                 K   s4   t dddd dd}tdd| it |fi |}|S )Nr   r  Tr  convnextv2_picor   )r  r   r   r0   r0   r1   r    s
    
r  c                 K   s4   t dddd dd}tdd| it |fi |}|S )Nr  r  Tr  convnextv2_nanor   )r  r   r   r0   r0   r1   r  
  s
    
r  c                 K   s2   t dddd d}tdd| it |fi |}|S )Nro   rq   Tr{   r|   rF   rG   convnextv2_tinyr   )r   r   r   r0   r0   r1   r     s    r   c                 K   s:   t g dg ddd d}tdd| it |fi |}|S )Nr  rq   Tr  convnextv2_smallr   )r!  r   r   r0   r0   r1   r!    s    r!  c                 K   s:   t g dg ddd d}tdd| it |fi |}|S )Nr  r  Tr  convnextv2_baser   )r"  r   r   r0   r0   r1   r"  !  s    r"  c                 K   s:   t g dg ddd d}tdd| it |fi |}|S )Nr  r  Tr  convnextv2_larger   )r#  r   r   r0   r0   r1   r#  (  s    r#  c                 K   s:   t g dg ddd d}tdd| it |fi |}|S )Nr  )i`  i  i  i   Tr  convnextv2_huger   )r$  r   r   r0   r0   r1   r$  /  s    r$  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )Zconvnext_tiny_in22ft1kZconvnext_small_in22ft1kZconvnext_base_in22ft1kZconvnext_large_in22ft1kZconvnext_xlarge_in22ft1kZconvnext_tiny_384_in22ft1kZconvnext_small_384_in22ft1kZconvnext_base_384_in22ft1kZconvnext_large_384_in22ft1kZconvnext_xlarge_384_in22ft1kZconvnext_tiny_in22kZconvnext_small_in22kZconvnext_base_in22kZconvnext_large_in22kZconvnext_xlarge_in22k)Nr^   )F)r   )r   )F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)F)OrY   collectionsr   	functoolsr   typingr   r   r   r   rR   Ztorch.nnr&   Z	timm.datar   r	   r
   r   Ztimm.layersr   r   r   r   r   r   r   r   r   r   r   r   r   Z_builderr   Z_manipulater   r   	_registryr   r   r   __all__Moduler!   r;   r]   r    r   r   r   r   r   Zdefault_cfgsr   r   r   r   r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r7   r0   r0   r0   r1   <module>   s  '4XE =
*


    q