
    RЦi                        S r SSKrSSKJrJrJrJrJrJrJ	r	J
r
  SSKrSSKJr  SSKJs  Jr  SSKJrJr  SSKJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJ r   SS
K!J"r"J#r#  S/r$ " S S\RJ                  5      r& " S S\RJ                  5      r' " S S\RJ                  5      r( " S S\RJ                  5      r) " S S\RJ                  5      r* " S S\RJ                  5      r+S\,S\S\RJ                  4S jr-SYS\\.S4   S\/S\.S\\.\.\.\.4   4S  jjr0 " S! S"\RJ                  5      r1 " S# S$\RJ                  5      r2          SZS%\S&\.S'\.S(\\.   S)\.S*\.S+\.S,\.S-\/S.\3S/\/S0\/S\S\Rh                  4S1 jjr5    S[S%\S&\.S'\.S(\\.   S)\.S-\/S.\3S/\/S0\/S\S\Rh                  4S2 jjr6 " S3 S\RJ                  5      r7S\S4\,S5\3S\S\74S6 jjr8S]S7\,S\S\\,\4   4S8 jjr9\#" \9" S9S:S;S<9\9" S9S=S>S?S@9\9" S9SAS;S<9\9" S9SBS>S?S@9\9" S9SCS;S<9\9" S9SDS>SES@9\9" S9SFS;S<9\9" S9SGSHSES@9\9" S9SIS;S<9\9" S9SJSHSES@9\9" S9SKSHSLS@9SM.5      r:\"S\S5\3S\S\74SN jj5       r;\"S\S5\3S\S\74SO jj5       r<\"S\S5\3S\S\74SP jj5       r=\"S\S5\3S\S\74SQ jj5       r>\"S\S5\3S\S\74SR jj5       r?\"S\S5\3S\S\74SS jj5       r@\"S\S5\3S\S\74ST jj5       rA\"S\S5\3S\S\74SU jj5       rB\"S\S5\3S\S\74SV jj5       rC\"S\S5\3S\S\74SW jj5       rD\"S\S5\3S\S\74SX jj5       rEg)^a4  Vision OutLOoker (VOLO) implementation

Paper: `VOLO: Vision Outlooker for Visual Recognition` - https://arxiv.org/abs/2106.13112

Code adapted from official impl at https://github.com/sail-sg/volo, original copyright in comment below

Modifications and additions for timm by / Copyright 2022, Ross Wightman
    N)AnyCallableDictListOptionalTupleUnionTypeIMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STD)DropPathMlp	to_2tuple	to_ntupletrunc_normal_use_fused_attn   )build_model_with_cfg)feature_take_indices)
checkpoint)register_modelgenerate_default_cfgsVOLOc                      ^  \ rS rSrSr        SS\S\S\S\S\S\S	\S
\4U 4S jjjrS\	R                  S\	R                  4S jrSrU =r$ )OutlookAttention'   z,Outlook attention mechanism for VOLO models.dim	num_headskernel_sizepaddingstrideqkv_bias	attn_drop	proj_dropc                   > XS.n[         TU ]  5         X-  nX l        X0l        X@l        XPl        US-  U l        [        R                  " X4SU0UD6U l	        [        R                  " XS-  U-  40 UD6U l
        [        R                  " U5      U l        [        R                  " X40 UD6U l        [        R                  " U5      U l        [        R                  " X4US9U l        [        R"                  " XUSS9U l        g)	a  Initialize OutlookAttention.

Args:
    dim: Input feature dimension.
    num_heads: Number of attention heads.
    kernel_size: Kernel size for attention computation.
    padding: Padding for attention computation.
    stride: Stride for attention computation.
    qkv_bias: Whether to use bias in linear layers.
    attn_drop: Attention dropout rate.
    proj_drop: Projection dropout rate.
devicedtype      bias   )r    r!   r"   T)r    r"   	ceil_modeN)super__init__r   r    r!   r"   scalennLinearvattnDropoutr$   projr%   Unfoldunfold	AvgPool2dpool)selfr   r   r    r!   r"   r#   r$   r%   r(   r)   ddhead_dim	__class__s                O/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/models/volo.pyr/   OutlookAttention.__init__*   s    2 /#"&%
39(9b9IIc!#3i#?F2F	I.IIc-"-	I.iiKQWXLLVdS	    xreturnc                    UR                   u  p#pEU R                  U5      R                  SSSS5      n[        R                  " X0R
                  -  5      [        R                  " X@R
                  -  5      pU R                  U5      R                  X R                  XPR                  -  U R                  U R                  -  Xx-  5      R                  SSSSS5      nU R                  UR                  SSSS5      5      R                  SSSS5      n	U R                  U	5      R                  X'U-  U R                  U R                  U R                  -  U R                  U R                  -  5      R                  SSSSS5      n	XR                  -  n	U	R                  SS9n	U R                  U	5      n	X-  R                  SSSSS5      R                  X%U R                  -  U R                  -  Xx-  5      n[        R                   " XU4U R                  U R"                  U R
                  S9nU R%                  UR                  SSSS5      5      nU R'                  U5      nU$ )	sForward pass.

Args:
    x: Input tensor of shape (B, H, W, C).

Returns:
    Output tensor of shape (B, H, W, C).
r      r      r,   r   )output_sizer    r!   r"   )shaper3   permutemathceilr"   r8   reshaper   r    r:   r4   r0   softmaxr$   Ffoldr!   r6   r%   )
r;   rB   BHWCr3   hwr4   s
             r?   forwardOutlookAttention.forwardV   s    WW
aFF1IaAq)yy[[)499Q_+E1KKN""~~qNN2t///88?1aA8N 	
 yy1aA./771aCyy&&1udnnd&6&69I9I&It///118Aq!Q1G 	 jj |||#~~d#Xq!Q1-55aT=M=M9MPTP`P`9`bcbghFF1a&d6F6FPTP\P\eiepepqIIaii1a+,NN1rA   )r4   r$   r    r   r!   r:   r6   r%   r0   r"   r8   r3   )rF   r   r   F        r[   NN)__name__
__module____qualname____firstlineno____doc__intboolfloatr/   torchTensorrY   __static_attributes____classcell__r>   s   @r?   r   r   '   s    6  !"!!*T*T *T 	*T
 *T *T *T *T *T *TX   %,,    rA   r   c                   
  ^  \ rS rSrSrSSSSS\R                  \R                  SSS4
S\S	\S
\S\S\S\	S\	S\	S\
\R                     S\
\R                     S\4U 4S jjjrS\R                  S\R                  4S jrSrU =r$ )	Outlookery   z9Outlooker block that combines outlook attention with MLP.r         @r[   FNr   r    r!   r"   r   	mlp_ratior$   	drop_path	act_layer
norm_layerr#   c           	        > XS.n[         TU ]  5         U
" U40 UD6U l        [        UU4UUUUUS.UD6U l        US:  a  [        U5      O[        R                  " 5       U l        U
" U40 UD6U l	        [        SU[        X-  5      U	S.UD6U l        US:  a  [        U5      U l        g[        R                  " 5       U l        g)a  Initialize Outlooker block.

Args:
    dim: Input feature dimension.
    kernel_size: Kernel size for outlook attention.
    padding: Padding for outlook attention.
    stride: Stride for outlook attention.
    num_heads: Number of attention heads.
    mlp_ratio: Ratio for MLP hidden dimension.
    attn_drop: Attention dropout rate.
    drop_path: Stochastic depth drop rate.
    act_layer: Activation layer type.
    norm_layer: Normalization layer type.
    qkv_bias: Whether to use bias in linear layers.
r'   )r    r!   r"   r#   r$   r[   in_featureshidden_featuresro   N )r.   r/   norm1r   r4   r   r1   Identity
drop_path1norm2r   ra   mlp
drop_path2)r;   r   r    r!   r"   r   rm   r$   rn   ro   rp   r#   r(   r)   r<   r>   s                  r?   r/   Outlooker.__init__|   s    > /*r*
$	
 $	
 	
	 2;R(9-R[[]*r*
 
0
 	
 2;R(9-R[[]rA   rB   rC   c                     XR                  U R                  U R                  U5      5      5      -   nXR                  U R	                  U R                  U5      5      5      -   nU$ zGForward pass.

Args:
    x: Input tensor.

Returns:
    Output tensor.
rx   r4   rv   r{   rz   ry   r;   rB   s     r?   rY   Outlooker.forward   M     		$**Q- 899A 788rA   r4   rx   r{   rz   rv   ry   )r\   r]   r^   r_   r`   r1   GELU	LayerNormra   rc   r
   Modulerb   r/   rd   re   rY   rf   rg   rh   s   @r?   rj   rj   y   s    C !!!)+*,,,"5S5S 5S 	5S
 5S 5S 5S 5S 5S BII5S RYY5S 5S 5Sn %,,  rA   rj   c                      ^  \ rS rSr% Sr\R                  R                  \   \	S'         SS\
S\
S\S\S\4
U 4S	 jjjrS
\R                  S\R                  4S jrSrU =r$ )	Attention   z!Multi-head self-attention module.
fused_attnr   r   r#   r$   r%   c                 V  > XgS.n[         T
U ]  5         X l        X-  n	U	S-  U l        [	        5       U l        [        R                  " XS-  4SU0UD6U l        [        R                  " U5      U l
        [        R                  " X40 UD6U l        [        R                  " U5      U l        g)zInitialize Attention module.

Args:
    dim: Input feature dimension.
    num_heads: Number of attention heads.
    qkv_bias: Whether to use bias in QKV projection.
    attn_drop: Attention dropout rate.
    proj_drop: Projection dropout rate.
r'   r*   rF   r+   N)r.   r/   r   r0   r   r   r1   r2   qkvr5   r$   r6   r%   )r;   r   r   r#   r$   r%   r(   r)   r<   r=   r>   s             r?   r/   Attention.__init__   s    & /"#%
(*99S'??B?I.IIc-"-	I.rA   rB   rC   c                    UR                   u  p#pEU R                  U5      R                  X#U-  SU R                  XPR                  -  5      R	                  SSSSS5      nUR                  S5      u  pxn	U R                  (       a>  [        R                  " XxU	U R                  (       a  U R                  R                  OSS9nOFXpR                  -  nXxR                  SS	5      -  n
U
R                  S	S
9n
U R                  U
5      n
X-  nUR                  SS5      R                  X#XE5      nU R                  U5      nU R!                  U5      nU$ )rE   rF   rG   r   r   r,   r[   )	dropout_prH   rI   )rK   r   rO   r   rL   unbindr   rQ   scaled_dot_product_attentiontrainingr$   pr0   	transposerP   r6   r%   )r;   rB   rS   rT   rU   rV   r   qkr3   r4   s              r?   rY   Attention.forward   s    WW
ahhqk!!!UAt~~qNN?RS[[\]_`bcefhij**Q-a??..a.2mm$..**A
 JJA{{2r**D<<B<'D>>$'DAKK1%%aA1IIaLNN1rA   )r$   r   r   r6   r%   r   r0   )   Fr[   r[   NN)r\   r]   r^   r_   r`   rd   jitFinalrb   __annotations__ra   rc   r/   re   rY   rf   rg   rh   s   @r?   r   r      s    +		%%
 "!!// / 	/
 / / /> %,,  rA   r   c                      ^  \ rS rSrSrSSSS\R                  \R                  SS4S\S\S	\	S
\
S\	S\	S\\R                     S\\R                     4U 4S jjjrS\R                  S\R                  4S jrSrU =r$ )Transformeri  z9Transformer block with multi-head self-attention and MLP.      @Fr[   Nr   r   rm   r#   r$   rn   ro   rp   c                   > XS.n[         TU ]  5         U" U40 UD6U l        [        U4X$US.UD6U l        US:  a  [        U5      O[        R                  " 5       U l        U" U40 UD6U l	        [        SU[        X-  5      US.UD6U l        US:  a  [        U5      U l        g[        R                  " 5       U l        g)aw  Initialize Transformer block.

Args:
    dim: Input feature dimension.
    num_heads: Number of attention heads.
    mlp_ratio: Ratio for MLP hidden dimension.
    qkv_bias: Whether to use bias in QKV projection.
    attn_drop: Attention dropout rate.
    drop_path: Stochastic depth drop rate.
    act_layer: Activation layer type.
    norm_layer: Normalization layer type.
r'   )r   r#   r$   r[   rr   Nru   )r.   r/   rv   r   r4   r   r1   rw   rx   ry   r   ra   rz   r{   )r;   r   r   rm   r#   r$   rn   ro   rp   r(   r)   r<   r>   s               r?   r/   Transformer.__init__  s    2 /*r*
ceYU^ebde	1:R(9-R[[]*r*
h3CO8LXahegh1:R(9-R[[]rA   rB   rC   c                     XR                  U R                  U R                  U5      5      5      -   nXR                  U R	                  U R                  U5      5      5      -   nU$ r~   r   r   s     r?   rY   Transformer.forward+  r   rA   r   )r\   r]   r^   r_   r`   r1   r   r   ra   rc   rb   r
   r   r/   rd   re   rY   rf   rg   rh   s   @r?   r   r     s    C  ""!!)+*,,,!S!S !S 	!S
 !S !S !S BII!S RYY!S !SF %,,  rA   r   c                      ^  \ rS rSrSr       SS\S\S\\   S\S\S\4U 4S	 jjjr	S
\
R                  S\
R                  4S jrSrU =r$ )ClassAttentioni9  z6Class attention mechanism for class token interaction.r   r   r=   r#   r$   r%   c	                    > XxS.n	[         T
U ]  5         X l        Ub  X0l        O
X-  nX0l        US-  U l        [
        R                  " XR                  U R                  -  S-  4SU0U	D6U l        [
        R                  " XR                  U R                  -  4SU0U	D6U l        [
        R                  " U5      U l
        [
        R                  " U R                  U R                  -  U40 U	D6U l        [
        R                  " U5      U l        g)a;  Initialize ClassAttention.

Args:
    dim: Input feature dimension.
    num_heads: Number of attention heads.
    head_dim: Dimension per head. If None, computed as dim // num_heads.
    qkv_bias: Whether to use bias in QKV projection.
    attn_drop: Attention dropout rate.
    proj_drop: Projection dropout rate.
r'   Nr*   rG   r+   )r.   r/   r   r=   r0   r1   r2   kvr   r5   r$   r6   r%   )r;   r   r   r=   r#   r$   r%   r(   r)   r<   r>   s             r?   r/   ClassAttention.__init__<  s    * /"$M'H$M%
))C!?!!CY(YVXY3 >TXTQSTI.IIdmmdnn<cHRH	I.rA   rB   rC   c                    UR                   u  p#nU R                  U5      R                  X#SU R                  U R                  5      R                  SSSSS5      nUR                  S5      u  pgU R                  USS2SS2SS24   5      R                  X R                  SU R                  5      U R                  -  nXR                  SS5      -  n	U	R                  SS	9n	U R                  U	5      n	X-  R                  SS5      R                  USU R                  U R                  -  5      n
U R                  U
5      n
U R                  U
5      n
U
$ )
zForward pass.

Args:
    x: Input tensor of shape (B, N, C) where first token is class token.

Returns:
    Class token output of shape (B, 1, C).
rG   r   rF   r   r,   Nr   rH   rI   )rK   r   rO   r   r=   rL   r   r   r0   r   rP   r$   r6   r%   )r;   rB   rS   NrV   r   r   r3   r   r4   	cls_embeds              r?   rY   ClassAttention.forwarda  s    ''aWWQZaGOOPQSTVWYZ\]^yy|FF1QAX;''>>1dmmLtzzY;;r2&&|||#~~d#X((A.66q!T]]T^^=[\	IIi(	NN9-	rA   )r$   r=   r   r   r6   r%   r   r0   )r   NFr[   r[   NN)r\   r]   r^   r_   r`   ra   r   rb   rc   r/   rd   re   rY   rf   rg   rh   s   @r?   r   r   9  s    @
 &*"!!#/#/ #/ sm	#/
 #/ #/ #/ #/J %,,  rA   r   c                     ^  \ rS rSrSrSSSSSS\R                  \R                  SS4
S\S\S	\	\   S
\
S\S\
S\
S\
S\\R                     S\\R                     4U 4S jjjrS\R                   S\R                   4S jrSrU =r$ )
ClassBlockiz  z3Class block that combines class attention with MLP.Nr   Fr[   r   r   r=   rm   r#   dropr$   rn   ro   rp   c           	        > XS.n[         TU ]  5         U
" U40 UD6U l        [        U4UUUUUS.UD6U l        US:  a  [        U5      O[        R                  " 5       U l        U
" U40 UD6U l	        [        SU[        X-  5      U	US.UD6U l        US:  a  [        U5      U l        g[        R                  " 5       U l        g)a  Initialize ClassBlock.

Args:
    dim: Input feature dimension.
    num_heads: Number of attention heads.
    head_dim: Dimension per head. If None, computed as dim // num_heads.
    mlp_ratio: Ratio for MLP hidden dimension.
    qkv_bias: Whether to use bias in QKV projection.
    drop: Dropout rate.
    attn_drop: Attention dropout rate.
    drop_path: Stochastic depth drop rate.
    act_layer: Activation layer type.
    norm_layer: Normalization layer type.
r'   )r   r=   r#   r$   r%   r[   )rs   rt   ro   r   Nru   )r.   r/   rv   r   r4   r   r1   rw   rx   ry   r   ra   rz   r{   )r;   r   r   r=   rm   r#   r   r$   rn   ro   rp   r(   r)   r<   r>   s                 r?   r/   ClassBlock.__init__}  s    : /*r*
"

 
	 2;R(9-R[[]*r*
 
0	

 
 2;R(9-R[[]rA   rB   rC   c                    USS2SS24   nX R                  U R                  U R                  U5      5      5      -   nX R                  U R	                  U R                  U5      5      5      -   n[        R                  " X!SS2SS24   /SS9$ )zForward pass.

Args:
    x: Input tensor of shape (B, N, C) where first token is class token.

Returns:
    Output tensor with updated class token.
Nr   rI   )rx   r4   rv   r{   rz   ry   rd   cat)r;   rB   r   s      r?   rY   ClassBlock.forward  sx     a!eH			$**Q-0H II	I9N0O PP	yy)q!"uX.A66rA   r   )r\   r]   r^   r_   r`   r1   r   r   ra   r   rc   rb   r
   r   r/   rd   re   rY   rf   rg   rh   s   @r?   r   r   z  s    = '+!"!!)+*,,,3S3S 3S sm	3S
 3S 3S 3S 3S 3S BII3S RYY3S 3Sj7 7%,, 7 7rA   r   
block_typekwargsrC   c                 8    U S:X  a  [        S0 UD6$  SU  35       e)zGet block based on type.

Args:
    block_type: Type of block ('ca' for ClassBlock).
    **kwargs: Additional keyword arguments for block.

Returns:
    The requested block module.
cazInvalid block type: ru   )r   )r   r   s     r?   	get_blockr     s,     T#F##9,ZL99urA   size.lamr0   c                    U S   U-  nU S   U-  n[         R                  " U[         R                  S9n[         R                  " U[         R                  S9n[         R                  " SU-
  5      nXW-  R	                  5       nXg-  R	                  5       n	[         R
                  " SUS5      n
[         R
                  " SUS5      n[         R                  " XS-  -
  SU5      n[         R                  " XS-  -
  SU5      n[         R                  " XS-  -   SU5      n[         R                  " XS-  -   SU5      nUR                  5       UR                  5       UR                  5       UR                  5       4$ )a  Get random bounding box for token labeling.

Reference: https://github.com/zihangJiang/TokenLabeling

Args:
    size: Input tensor size tuple.
    lam: Lambda parameter for cutmix.
    scale: Scaling factor.

Returns:
    Bounding box coordinates (bbx1, bby1, bbx2, bby2).
r   rG   )r)         ?r   r   )rd   tensorfloat32sqrtra   randintclampitem)r   r   r0   rU   rT   W_tH_tcut_ratcut_wcut_hcxcybbx1bby1bbx2bby2s                   r?   	rand_bboxr     s'    	Q5AQ5A
,,q
.C
,,q
.Cjjc"G]!E]!E 
q!T	"B	q!T	"B;;rQJ1-D;;rQJ1-D;;rQJ1-D;;rQJ1-D99;		TYY[$))+==rA   c                      ^  \ rS rSrSr         SS\S\S\S\S\S\S	\4U 4S
 jjjrS\R                  S\R                  4S jr
SrU =r$ )
PatchEmbedi  z6Image to patch embedding with multi-layer convolution.img_size	stem_convstem_stride
patch_sizein_chans
hidden_dim	embed_dimc
                   > XS.n
[         TU ]  5         US;   d   eU(       a  [        R                  " [        R                  " XV4SUSSS.U
D6[        R
                  " U40 U
D6[        R                  " SS9[        R                  " Xf4SS	S	SS.U
D6[        R
                  " U40 U
D6[        R                  " SS9[        R                  " Xf4SS	S	SS.U
D6[        R
                  " U40 U
D6[        R                  " SS95	      U l        OS
U l        [        R                  " UU4XC-  XC-  S.U
D6U l        X-  X-  -  U l	        g
)a  Initialize PatchEmbed.

Different from ViT which uses 1 conv layer, VOLO uses multiple conv layers for patch embedding.

Args:
    img_size: Input image size.
    stem_conv: Whether to use stem convolution layers.
    stem_stride: Stride for stem convolution.
    patch_size: Patch size (must be 4, 8, or 16).
    in_chans: Number of input channels.
    hidden_dim: Hidden dimension for stem convolution.
    embed_dim: Output embedding dimension.
r'   )r,   r         rF   F)r    r"   r!   r+   T)inplacer   Nr    r"   )
r.   r/   r1   
SequentialConv2dBatchNorm2dReLUconvr6   num_patches)r;   r   r   r   r   r   r   r   r(   r)   r<   r>   s              r?   r/   PatchEmbed.__init__  s>   2 /Z'''		(oAk[\cholnoz0R0%		*gaST[`gdfgz0R0%		*gaST[`gdfgz0R0%
DI DIII
 #1,	

 
	 %2x7MNrA   rB   rC   c                 d    U R                   b  U R                  U5      nU R                  U5      nU$ )z}Forward pass.

Args:
    x: Input tensor of shape (B, C, H, W).

Returns:
    Output tensor of shape (B, embed_dim, H', W').
)r   r6   r   s     r?   rY   PatchEmbed.forward)  s-     99 		!AIIaLrA   )r   r   r6   )	   Fr   r   rF   @     NN)r\   r]   r^   r_   r`   ra   rb   r/   rd   re   rY   rf   rg   rh   s   @r?   r   r     s    @  #   2O2O 2O 	2O
 2O 2O 2O 2O 2Oh %,,  rA   r   c                      ^  \ rS rSrSr   SS\S\S\4U 4S jjjrS\R                  S\R                  4S	 jr	S
r
U =r$ )
Downsamplei8  z#Downsampling module between stages.in_embed_dimout_embed_dimr   c                 f   > [         TU ]  5         XES.n[        R                  " X4X3S.UD6U l        g)zInitialize Downsample.

Args:
    in_embed_dim: Input embedding dimension.
    out_embed_dim: Output embedding dimension.
    patch_size: Patch size for downsampling.
r'   r   N)r.   r/   r1   r   r6   )r;   r   r   r   r(   r)   r<   r>   s          r?   r/   Downsample.__init__;  s3     	/IIlkzkhjk	rA   rB   rC   c                 x    UR                  SSSS5      nU R                  U5      nUR                  SSSS5      nU$ )zvForward pass.

Args:
    x: Input tensor of shape (B, H, W, C).

Returns:
    Output tensor of shape (B, H', W', C').
r   rF   r   rG   )rL   r6   r   s     r?   rY   Downsample.forwardN  s>     IIaAq!IIaLIIaAq!rA   )r6   )rG   NN)r\   r]   r^   r_   r`   ra   r/   rd   re   rY   rf   rg   rh   s   @r?   r   r   8  s\    -  ll l 	l l& %,,  rA   r   block_fnindexr   layersr   r    r!   r"   rm   r#   r$   drop_path_ratec                     / n[        X1   5       HI  nUU[        USU 5      -   -  [        U5      S-
  -  nUR                  U " U4UUUUUU	U
UUUS.
UD65        MK     [        R                  " U6 nU$ )a  Generate outlooker layers for stage 1.

Args:
    block_fn: Block function to use (typically Outlooker).
    index: Index of current stage.
    dim: Feature dimension.
    layers: List of layer counts for each stage.
    num_heads: Number of attention heads.
    kernel_size: Kernel size for outlook attention.
    padding: Padding for outlook attention.
    stride: Stride for outlook attention.
    mlp_ratio: Ratio for MLP hidden dimension.
    qkv_bias: Whether to use bias in QKV projection.
    attn_drop: Attention dropout rate.
    drop_path_rate: Stochastic depth drop rate.
    **kwargs: Additional keyword arguments.

Returns:
    Sequential module containing outlooker blocks.
Nr   )
r    r!   r"   r   rm   r#   r$   rn   r(   r)   rangesumappendr1   r   )r   r   r   r   r   r    r!   r"   rm   r#   r$   r   r(   r)   r   blocks	block_idx	block_dprs                     r?   outlooker_blocksr   ]  s    J F6=)	"i#fVen2E&EF#f+XY/Z	h
#
 
 	 *  ]]F#FMrA   c	                     / n
[        X1   5       HC  nX[        USU 5      -   -  [        U5      S-
  -  nU
R                  U " UU4UUUUS.U	D65        ME     [        R                  " U
6 n
U
$ )a-  Generate transformer layers for stage 2.

Args:
    block_fn: Block function to use (typically Transformer).
    index: Index of current stage.
    dim: Feature dimension.
    layers: List of layer counts for each stage.
    num_heads: Number of attention heads.
    mlp_ratio: Ratio for MLP hidden dimension.
    qkv_bias: Whether to use bias in QKV projection.
    attn_drop: Attention dropout rate.
    drop_path_rate: Stochastic depth drop rate.
    **kwargs: Additional keyword arguments.

Returns:
    Sequential module containing transformer blocks.
Nr   )rm   r#   r$   rn   r   )r   r   r   r   r   rm   r#   r$   r   r   r   r   r   s                r?   transformer_blocksr    s    : F6=)	"#fVen2E&EF#f+XY/Z	h
  
 
 	 * ]]F#FMrA   c            -       B  ^  \ rS rSrSrSSSSSSS	S	S
S
SSSSSS\R                  SSSSS	S	4S\\   S\S\S\S\	S\S\S\
\\      S\
\\      S\\S4   S\\S4   S\S\S\S \S!\S"\S#\\R                     S$\
\\	S4      S%\S&\S'\4,U 4S( jjjrS)\R                  S*S	4S+ jr\R&                  R(                  S*\4S, j5       r\R&                  R(                  SES-\S*\\	\4   4S. jj5       r\R&                  R(                  SFS/\S*S	4S0 jj5       r\R&                  R(                  S*\R                  4S1 j5       rSGS\S\
\	   S*S	4S2 jjrS3\R:                  S*\R:                  4S4 jrS3\R:                  S*\R:                  4S5 jrS3\R:                  S*\ \R:                  \\R:                  \R:                  \\\\\4   4   4   4S6 jr!     SHS3\R:                  S7\
\ \\\   4      S8\S9\S:\	S;\S*\ \\R:                     \\R:                  \\R:                     4   4   4S< jjr"   SIS7\ \\\   4   S=\S>\S*\\   4S? jjr#S3\R:                  S*\R:                  4S@ jr$SES3\R:                  SA\S*\R:                  4SB jjr%S3\R:                  S*\R:                  4SC jr&SDr'U =r($ )Jr   i  zVision Outlooker (VOLO) model.r   rF     tokenr   r   N)TFFFrl   Fr[   )r   r   TrG   r   r   r   num_classesglobal_poolr   stem_hidden_dim
embed_dimsr   downsamples.outlook_attentionrm   r#   	drop_ratepos_drop_rateattn_drop_rater   rp   post_layersuse_aux_headuse_mix_tokenpooling_scalec                   > [         T!U ]  5         UUS.n[        U5      n[        U5      " U5      n[	        U5      nX@l        X0l        XPl        UU l        UU l	        US   =U l
        U l        U(       a  SU l        US:X  d   S5       eSU l        [        SSSUUUUS	   S
.UD6U l        UnUS	   U-  U-  US   U-  U-  4n[         R"                  " [$        R&                  " SUS	   US   US   40 UD65      U l        [         R*                  " US9U l        / U l        / U l        / nS	n[3        [        U5      5       H  nUU   (       a#  [5        [6        UUU   UU	U   4UU   UUUS.UD6n O#[9        [:        UUU   UU	U   4UU   UUUUS.UD6n UR=                  U 5        U R.                  R=                  U5        U R0                  R=                  [?        UU   USU 3S95        US-  nU
U   (       d  M  UR=                  [A        UU   UUS-      S40 UD65        US-  nUS-  nM     [         RB                  " U5      U l"        SU l#        Ub  [         RB                  " [3        [        U5      5       Vs/ s H#  n[I        UU   4US   U	S   US   UUSUS.UD6PM%     sn5      U l#        [         R"                  " [$        R&                  " SSUS   40 UD65      U l%        [M        U RJ                  SS9  U(       aC  US	:  a"  [         RN                  " U R                  U40 UD6O[         RP                  " 5       U l)        OSU l)        U" U R                  40 UD6U l*        [         R*                  " U5      U l+        US	:  a"  [         RN                  " U R                  U40 UD6O[         RP                  " 5       U l,        [M        U R(                  SS9  U R[                  U R\                  5        gs  snf )ao  Initialize VOLO model.

Args:
    layers: Number of blocks in each stage.
    img_size: Input image size.
    in_chans: Number of input channels.
    num_classes: Number of classes for classification.
    global_pool: Global pooling type ('token', 'avg', or '').
    patch_size: Patch size for patch embedding.
    stem_hidden_dim: Hidden dimension for stem convolution.
    embed_dims: List of embedding dimensions for each stage.
    num_heads: List of number of attention heads for each stage.
    downsamples: Whether to downsample between stages.
    outlook_attention: Whether to use outlook attention in each stage.
    mlp_ratio: Ratio for MLP hidden dimension.
    qkv_bias: Whether to use bias in QKV projection.
    drop_rate: Dropout rate.
    pos_drop_rate: Position embedding dropout rate.
    attn_drop_rate: Attention dropout rate.
    drop_path_rate: Stochastic depth drop rate.
    norm_layer: Normalization layer type.
    post_layers: Post-processing layer types.
    use_aux_head: Whether to use auxiliary head.
    use_mix_token: Whether to use token mixing for training.
    pooling_scale: Pooling scale factor.
r'   rH   r   r  z)return all tokens if mix_token is enabledFTrG   r   )r   r   r   r   r   r   r   )r   )rm   r#   r$   rp   )rm   r#   r   r$   rp   znetwork.)num_chs	reductionmoduleNr[   )r   r   rm   r#   r$   rn   rp   {Gz?stdru   )/r.   r/   lenr   r   r  r   r  	mix_tokenr  num_featureshead_hidden_sizebetagrad_checkpointingr   patch_embedr1   	Parameterrd   zeros	pos_embedr5   pos_drop
stage_endsfeature_infor   r   rj   r  r   r   dictr   
ModuleListnetworkpost_networkr   	cls_tokenr   r2   rw   aux_headnorm	head_dropheadapply_init_weights)"r;   r   r   r   r  r  r   r  r  r   r	  r
  rm   r#   r  r  r  r   rp   r  r  r  r  r(   r)   r<   
num_layersr
patch_gridr(  r   istager>   s"                                    r?   r/   VOLO.__init__  s    j 	/[
j))4	X&& &&*4>rNBD1DI')V+VV)"'% 
!& m
 
  qkZ/=@(1+Q[B[_lBlm
ekk!Z]JqMS]^`Sa&heg&hi

]3 	s6{#A #(qMaL (l%,)  +qMaL (l%#1,)  NN5!OO""9-$$T*Q-1W_`i_jUk%lmNI1~~z*Q-AE9JATQSTUQQ	M $P }}W- !" " s;/0/ 1A N
"2'm'm%, )
 
 1/ !D  \\%++aJrN*Qb*QRDN$..c2 OZ]^BIId&7&7KKdfdododqDM DMt007B7	 I.GRUVBIId//CC\^\g\g\i	dnn#.

4%%&;/s   5*O*mrC   c                    [        U[        R                  5      (       am  [        UR                  SS9  [        U[        R                  5      (       a9  UR
                  b+  [        R                  R                  UR
                  S5        gggg)zDInitialize weights for modules.

Args:
    m: Module to initialize.
r  r  Nr   )
isinstancer1   r2   r   weightr+   init	constant_)r;   r7  s     r?   r0  VOLO._init_weightsn  sb     a##!((,!RYY''AFF,>!!!&&!, -?' $rA   c                 
    SS1$ )z_Get set of parameters that should not have weight decay.

Returns:
    Set of parameter names.
r"  r*  ru   r;   s    r?   no_weight_decayVOLO.no_weight_decayy  s     [))rA   coarsec                      [        SSS// SQS9$ )zGet parameter grouping for optimizer.

Args:
    coarse: Whether to use coarse grouping.

Returns:
    Parameter grouping dictionary.
z ^cls_token|pos_embed|patch_embed)z^network\.(\d+)\.(\d+)N)z^network\.(\d+)r   ))z
^cls_tokenrD  )z^post_network\.(\d+)N)z^norm)i )stemr   blocks2)r&  )r;   rB  s     r?   group_matcherVOLO.group_matcher  s$     41*
 	
rA   enablec                     Xl         g)zYSet gradient checkpointing.

Args:
    enable: Whether to enable gradient checkpointing.
N)r  )r;   rI  s     r?   set_grad_checkpointingVOLO.set_grad_checkpointing  s
     #)rA   c                     U R                   $ )zAGet classifier module.

Returns:
    The classifier head module.
)r.  r?  s    r?   get_classifierVOLO.get_classifier  s     yyrA   c                 2   Xl         Ub  X l        [        U R                  S5      (       a   U R                  R                  R
                  OSn[        U R                  S5      (       a   U R                  R                  R                  OSnUS:  a   [        R                  " U R                  XUS9O[        R                  " 5       U l        U R                  bA  US:  a   [        R                  " U R                  XUS9O[        R                  " 5       U l        gg)z{Reset classifier head.

Args:
    num_classes: Number of classes for new classifier.
    global_pool: Global pooling type.
Nr:  r   r'   )r  r  hasattrr.  r:  r(   r)   r1   r2   r  rw   r+  )r;   r  r  r(   r)   s        r?   reset_classifierVOLO.reset_classifier  s     '"*,3DIIx,H,H!!((d*1$))X*F*F		  &&DKVYZ? II{H`b`k`k`m 		==$OZ]^ II!!;ULdfdododq M %rA   rB   c                 b   [        U R                  5       Hs  u  p#US:X  a  XR                  -   nU R                  U5      nU R                  (       a0  [
        R                  R                  5       (       d  [        X15      nMk  U" U5      nMu     UR                  u  pEpgUR                  USU5      nU$ )zForward pass through token processing stages.

Args:
    x: Input tensor of shape (B, H, W, C).

Returns:
    Token tensor of shape (B, N, C).
rG   rH   )	enumerater(  r"  r#  r  rd   r   is_scriptingr   rK   rO   )r;   rB   idxblockrS   rT   rU   rV   s           r?   forward_tokensVOLO.forward_tokens  s     $DLL1JCax&MM!$&&uyy/E/E/G/Gu(!H 2 WW
aIIaQrA   c                 B   UR                   u  p#nU R                  R                  USS5      n[        R                  " XQ/SS9nU R
                   HL  nU R                  (       a0  [        R                  R                  5       (       d  [        Xa5      nMD  U" U5      nMN     U$ )zForward pass through class attention blocks.

Args:
    x: Input token tensor of shape (B, N, C).

Returns:
    Output tensor with class token of shape (B, N+1, C).
rH   r   rI   )
rK   r*  expandrd   r   r)  r  r   rV  r   )r;   rB   rS   r   rV   
cls_tokensrX  s          r?   forward_clsVOLO.forward_cls  s     ''a^^**1b"5
IIzo1-&&E&&uyy/E/E/G/Gu(!H	 '
 rA   c                     U R                  U5      nUR                  SSSS5      nU R                  (       Ga(  U R                  (       Ga  [        R
                  R                  U R                  U R                  5      R                  5       nUR                  S   U R                  -  UR                  S   U R                  -  pC[        UR                  5       X R                  S9u  pVpxUR                  5       n	U R                  U-  U R                  U-  pU R                  U-  U R                  U-  pUR                  S5      SS2X2X2SS24   U	SS2X2X2SS24'   U	nOSu  pVpxU R                  U5      nU R                   b  U R#                  U5      nU R%                  U5      nU R&                  S:X  a  UR)                  SS	9nOU R&                  S
:X  a
  USS2S4   nOUnU R*                  c  U$ U R+                  USS2SS24   5      nU R                  (       d  USUR-                  S5      S   -  -   $ U R                  (       a  U R                  (       a  UR/                  UR                  S   WWUR                  S   5      nUR                  5       n	UR                  S5      SS2XW2Xh2SS24   U	SS2XW2Xh2SS24'   U	nUR/                  UR                  S   X4-  UR                  S   5      nXXVXx44$ )zForward pass for training with mix token support.

Args:
    x: Input tensor of shape (B, C, H, W).

Returns:
    If training with mix_token: tuple of (class_token, aux_tokens, bbox).
    Otherwise: class_token tensor.
r   rG   rF   r   )r0   N)r   r   r   r   avgrI   r        ?rH   )r  rL   r  r   rd   distributionsBetar  samplerK   r  r   r   clonefliprY  r)  r^  r,  r  meanr+  maxrO   )r;   rB   r   patch_hpatch_wr   r   r   r   temp_xsbbx1sbby1sbbx2sbby2x_clsx_auxs                   r?   forward_trainVOLO.forward_train  s   	 QIIaAq! >>>dmmm%%**499dii@GGIC wwqzT-?-??tOaOaAaW%.qvvxDVDV%W"DWWYF--4d6H6H46O5--4d6H6H46O556VVAYq%+u{\]?]5^F1ek5;12A%/"D " (  #AIIaLu$FFqFME(adGEE== La12h'}}31a000>>dmmMM%++a.'7EKKPROTE[[]F16Aq$)TYXY?Y1ZF1diA-.EMM%++a.'2CU[[QS_UE d$555rA   indicesr,  
stop_early
output_fmtintermediates_onlyc           	         US;   d   S5       e/ n[        [        U R                  5      U5      u  pU V
s/ s H  oR                  U
   PM     nn
U R                  U	   n	UR                  u  ppU R	                  U5      R                  SSSS5      n[        R                  R                  5       (       d  U(       d  U R                  nOU R                  SU	S-    n[        U5       H  u  nnUS:X  a  XR                  -   nU R                  U5      nU R                  (       a0  [        R                  R                  5       (       d  [        UU5      nOU" U5      nUU;   d  M|  U(       a  US:  a  U R                  U5      nOUnUR!                  UR                  SSSS5      5        M     U(       a  U$ UR                  u  nnnnUR#                  USU5      nU R$                  b  U R'                  U5      nU R                  U5      nX4$ s  sn
f )	a  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 all 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:

)NCHWzOutput format must be NCHW.r   rG   rF   r   NrH   )r   r  r$  rK   r  rL   rd   r   rV  r(  rU  r"  r#  r  r   r,  r   rO   r)  r^  )r;   rB   ru  r,  rv  rw  rx  intermediatestake_indices	max_indexr4  rS   _heightwidthr(  rW  rX  x_interrT   rU   rV   s                         r?   forward_intermediatesVOLO.forward_intermediates$  s   * Y&E(EE&"6s4??7KW"U4@ALq*LAOOI.	  ggfQ''1a3 99!!##:llGll>IM2G#G,JCax&MM!$&&uyy/E/E/G/Gua(!Hl"C1H"iilGG$$W__Q1a%@A -     WW
1aIIaQ(  #AIIaLO Bs   H
prune_norm
prune_headc                 >    [        [        U R                  5      U5      u  pEU R                  U   nU R                  SUS-    U l        U(       a  [        R
                  " 5       U l        U(       a,  [        R                  " 5       U l        U R                  SS5        U$ )a  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 classification head.

Returns:
    List of kept intermediate indices.
Nr   r    )
r   r  r$  r(  r1   rw   r,  r'  r)  rR  )r;   ru  r  r  r|  r}  s         r?   prune_intermediate_layersVOLO.prune_intermediate_layerse  sz     	"6s4??7KW"UOOI.	||NY]3DI "D!!!R(rA   c                     U R                  U5      R                  SSSS5      nU R                  U5      nU R                  b  U R	                  U5      nU R                  U5      nU$ )zyForward pass through feature extraction.

Args:
    x: Input tensor of shape (B, C, H, W).

Returns:
    Feature tensor.
r   rG   rF   r   )r  rL   rY  r)  r^  r,  r   s     r?   forward_featuresVOLO.forward_features  sg     Q''1a3 " (  #AIIaLrA   
pre_logitsc                 V   U R                   S:X  a  UR                  SS9nOU R                   S:X  a
  USS2S4   nOUnU R                  U5      nU(       a  U$ U R                  U5      nU R                  b4  U R	                  USS2SS24   5      nUSUR                  S5      S   -  -   nU$ )zForward pass through classification head.

Args:
    x: Input feature tensor.
    pre_logits: Whether to return pre-logits features.

Returns:
    Classification logits or pre-logits features.
ra  r   rI   r  Nr   rb  )r  rh  r-  r.  r+  ri  )r;   rB   r  outauxs        r?   forward_headVOLO.forward_head  s     u$&&Q&-C(AqD'CCNN1Jiin==$--!QR%)Ccggajm++C
rA   c                 L     U R                  U5      nU R                  U5      nU$ )zForward pass (simplified, without mix token training).

Args:
    x: Input tensor of shape (B, C, H, W).

Returns:
    Classification logits.
)r  r  r   s     r?   rY   VOLO.forward  s-     	@!!!$a rA   )r+  r  r*  r%  r  r  r.  r-  r  r   r  r(  r,  r  r  r  r  r#  r"  r)  r$  F)T)N)NFFrz  F)r   FT))r\   r]   r^   r_   r`   r1   r   r   ra   strr   r   rb   rc   r
   r   r/   r0  rd   r   ignoresetr@  r   r   rG  rK  rN  rR  re   rY  r^  r	   rs  r  r  r  r  rY   rf   rg   rh   s   @r?   r   r     sB   (
  #&#%.2-1,G2M""!#%$&$&*,,,5A!%"'!"3e'Ie' e' 	e'
 e' e' e' !e' !c+e'  S	*e' tSy)e'  %T3Y/e' e' e' e'  !!e'" "#e'$ "%e'& RYY'e'( "%S/2)e'* +e',  -e'. /e' e'N	-ryy 	-T 	- YY* * * YY
D 
T#s(^ 
 
, YY)T )T ) ) YY		  rC rhsm rW[ r$  .U\\ ell &;6u|| ;6ellE%,,X]XdXdfkloqtvy{~l~fJ  EA  7A  1B ;6@ 8<$$',? ||?  eCcN34?  	? 
 ?  ?  !%?  
tELL!5tELL7I)I#JJ	K? F ./$#	3S	>*  	
 
c8%,, 5<< (ell   4 %,,  rA   variant
pretrainedc           	      ^    UR                  SS5      n[        [        U U4S[        USS90UD6$ )zCreate VOLO model.

Args:
    variant: Model variant name.
    pretrained: Whether to load pretrained weights.
    **kwargs: Additional model arguments.

Returns:
    VOLO model instance.
out_indicesrF   feature_cfggetter)r  feature_cls)popr   r   r&  )r  r  r   r  s       r?   _create_volor    sE     **]A.K [hG	
  rA   urlc                 4    U SSSSSS[         [        SSS	S
.UE$ )zCreate model configuration.

Args:
    url: URL for pretrained weights.
    **kwargs: Additional configuration options.

Returns:
    Model configuration dictionary.
r  )rF   r   r   NQ?bicubicTzpatch_embed.conv.0)r.  r+  z
apache-2.0)r  r  
input_size	pool_sizecrop_pctinterpolationfixed_input_sizerh  r  
first_conv
classifierlicenser   )r  r   s     r?   _cfgr    s8     =t)%.B*:N  rA   ztimm/zLhttps://github.com/sail-sg/volo/releases/download/volo_1/d1_224_84.2.pth.tarr  )	hf_hub_idr  r  zLhttps://github.com/sail-sg/volo/releases/download/volo_1/d1_384_85.2.pth.tarr   )rF   r   r   )r  r  r  r  zLhttps://github.com/sail-sg/volo/releases/download/volo_1/d2_224_85.2.pth.tarzLhttps://github.com/sail-sg/volo/releases/download/volo_1/d2_384_86.0.pth.tarzLhttps://github.com/sail-sg/volo/releases/download/volo_1/d3_224_85.4.pth.tarzLhttps://github.com/sail-sg/volo/releases/download/volo_1/d3_448_86.3.pth.tar)rF     r  zLhttps://github.com/sail-sg/volo/releases/download/volo_1/d4_224_85.7.pth.tarzMhttps://github.com/sail-sg/volo/releases/download/volo_1/d4_448_86.79.pth.targffffff?zMhttps://github.com/sail-sg/volo/releases/download/volo_1/d5_224_86.10.pth.tarzLhttps://github.com/sail-sg/volo/releases/download/volo_1/d5_448_87.0.pth.tarzMhttps://github.com/sail-sg/volo/releases/download/volo_1/d5_512_87.07.pth.tar)rF      r  )zvolo_d1_224.sail_in1kzvolo_d1_384.sail_in1kzvolo_d2_224.sail_in1kzvolo_d2_384.sail_in1kzvolo_d3_224.sail_in1kzvolo_d3_448.sail_in1kzvolo_d4_224.sail_in1kzvolo_d4_448.sail_in1kzvolo_d5_224.sail_in1kzvolo_d5_448.sail_in1kzvolo_d5_512.sail_in1kc                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )VOLO-D1 model, Params: 27M.r,   r,   r   rG      r   r   r         r  r  r   r  r   r  ru   )volo_d1_224r&  r  r  r   
model_argsmodels       r?   r  r    4     p\6JVepiopJL:LLELrA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )r  r  r  r  r  r  ru   )volo_d1_384r  r  s       r?   r  r     r  rA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )VOLO-D2 model, Params: 59M.r  r,   
   r,      r  r  r  r   r   r   r   r  r  ru   )volo_d2_224r  r  s       r?   r  r  (  4     q]7KWfqjpqJL:LLELrA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )r  r  r  r  r  r  ru   )volo_d2_384r  r  s       r?   r  r  0  r  rA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )VOLO-D3 model, Params: 86M.r   r   r   r,   r  r  r  r  ru   )volo_d3_224r  r  s       r?   r  r  8  r  rA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )r  r  r  r  r  r  ru   )volo_d3_448r  r  s       r?   r  r  @  r  rA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )VOLO-D4 model, Params: 193M.r  r      r  r  r  r   r   r   r  r  ru   )volo_d4_224r  r  s       r?   r  r  H  4     r]7KWgrkqrJL:LLELrA   c                 >    [        SSSSS.UD6n[        SSU 0UD6nU$ )r  r  r  r  r  r  ru   )volo_d4_448r  r  s       r?   r  r  P  r  rA   c           	      B    [        SSSSSSS.UD6n[        S	SU 0UD6nU$ )
bVOLO-D5 model, Params: 296M.

stem_hidden_dim=128, the dim in patch embedding is 128 for VOLO-D5.
r  r     r,   r  r  r,      r   r  r   rm   r  r  ru   )volo_d5_224r  r  s       r?   r  r  X  B      4+?K[S4,24J L:LLELrA   c           	      B    [        SSSSSSS.UD6n[        S	SU 0UD6nU$ )
r  r  r  r  r,   r  r  r  ru   )volo_d5_448r  r  s       r?   r  r  e  r  rA   c           	      B    [        SSSSSSS.UD6n[        S	SU 0UD6nU$ )
r  r  r  r  r,   r  r  r  ru   )volo_d5_512r  r  s       r?   r  r  r  r  rA   r   )
r   rF   r   rG   rl   Fr   r[   NN)rl   Fr   r[   r  )r  )Fr`   rM   typingr   r   r   r   r   r   r	   r
   rd   torch.nnr1   torch.nn.functional
functionalrQ   	timm.datar   r   timm.layersr   r   r   r   r   r   _builderr   	_featuresr   _manipulater   	_registryr   r   __all__r   r   rj   r   r   r   r   r  r   ra   rc   r   r   r   rb   r   r   r  r   r  r  default_cfgsr  r  r  r  r  r  r  r  r  r  r  ru   rA   r?   <module>r     sm  *  J J J     A Z Z * + # <(Oryy OdE		 EPA		 AH1")) 1h>RYY >BD7 D7N:# : : : >E#s(O >% > >E#sTWY\J\D] >BC CL" "T  "777 7 S		7
 7 7 7 7 7 7 7 7 7  ]]!7@  "*** * S		*
 * * * * * * ]]*Zw299 wt# 4 3 4 *c # $sCx. * %!Z "Z0 "Z "Z0 "Z "Z0 "Z "[-1 "[ "Z-1 "[-1S-& -` D C D   D C D   D C D   D C D   D C D   D C D   D C D   D C D   	D 	C 	D 	 	 	D 	C 	D 	 	 	D 	C 	D 	 	rA   