
    sgk                    (   d Z ddlmZ ddlmZmZmZmZ ddl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 dd	lmZ dd
lmZmZm Z m!Z! ddl"m#Z#  e!jH                  e%      Z&dZ'dZ(g dZ)dZ*dZ+ G d dejX                  jZ                        Z. G d dejX                  jZ                        Z/ G d dejX                  jZ                        Z0 G d dejX                  jZ                        Z1 G d dejX                  jZ                        Z2 G d dejX                  jZ                        Z3e G d dejX                  jZ                               Z4 G d d e      Z5d!Z6d"Z7 ed#e6       G d$ d%e5             Z8 ed&e6       G d' d(e5e             Z9y))zTF 2.0 ConvNextV2 model.    )annotations)ListOptionalTupleUnionN   )get_tf_activation) TFBaseModelOutputWithNoAttentionTFBaseModelOutputWithPooling*TFBaseModelOutputWithPoolingAndNoAttention&TFImageClassifierOutputWithNoAttention)TFModelInputTypeTFPreTrainedModelTFSequenceClassificationLossget_initializerkeraskeras_serializableunpack_inputs)
shape_list)add_code_sample_docstringsadd_start_docstrings%add_start_docstrings_to_model_forwardlogging   )ConvNextV2Configr   zfacebook/convnextv2-tiny-1k-224)r   i      r   ztabby, tabby catc                  .     e Zd ZdZd fdZdddZ xZS )TFConvNextV2DropPathzDrop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
    References:
        (1) github.com:rwightman/pytorch-image-models
    c                2    t        |   di | || _        y N )super__init__	drop_path)selfr$   kwargs	__class__s      h/var/www/html/venv/lib/python3.12/site-packages/transformers/models/convnextv2/modeling_tf_convnextv2.pyr#   zTFConvNextV2DropPath.__init__G   s    "6""    c                &   |rd| j                   z
  }t        j                  |      d   fdt        t        j                  |            dz
  z  z   }|t        j                  j                  |dd      z   }t        j                  |      }||z  |z  S |S )Nr   r   )r   )r$   tfshapelenrandomuniformfloor)r%   xtraining	keep_probr,   random_tensors         r(   callzTFConvNextV2DropPath.callK   s    DNN*IXXa[^%BHHQK0@10D(EEE%		(9(9%A(FFMHH]3M	M]22r)   )r$   floatN)r1   	tf.Tensor)__name__
__module____qualname____doc__r#   r5   __classcell__r'   s   @r(   r   r   A   s    
# r)   r   c                  :     e Zd ZdZd fdZdd fdZddZ xZS )	TFConvNextV2GRNz)GRN (Global Response Normalization) layerc                2    t        |   di | || _        y r    )r"   r#   dim)r%   configrB   r&   r'   s       r(   r#   zTFConvNextV2GRN.__init__X   s    "6"r)   c                .   | j                  dddd| j                  ft        j                  j	                               | _        | j                  dddd| j                  ft        j                  j	                               | _        t        | !  |      S )Nweightr   )namer,   initializerbias)	
add_weightrB   r   initializersZerosrE   rH   r"   build)r%   input_shaper'   s     r(   rL   zTFConvNextV2GRN.build\   s    ooaDHH%**002 & 

 OOaDHH%**002 $ 
	
 w}[))r)   c                    t        j                  |ddd      }|t        j                  |dd      dz   z  }| j                  ||z  z  | j                  z   |z   }|S )N	euclidean)r      T)ordaxiskeepdims)rR   rS   ư>)r+   normreduce_meanrE   rH   )r%   hidden_statesglobal_featuresnorm_featuress       r(   r5   zTFConvNextV2GRN.callj   s^    ''-[vX\]'2>>/PR]a+bei+ij}}'DE		QTaar)   )rC   r   rB   intr7   )rM   ztf.TensorShape)rX   r8   )r9   r:   r;   r<   r#   rL   r5   r=   r>   s   @r(   r@   r@   U   s    3*r)   r@   c                  2     e Zd ZdZd fdZd ZddZ xZS )TFConvNextV2EmbeddingszThis class is comparable to (and inspired by) the SwinEmbeddings class
    found in src/transformers/models/swin/modeling_swin.py.
    c           	        t        |   di | t        j                  j	                  |j
                  d   |j                  |j                  dt        |j                        t        j                  j                               | _        t        j                  j                  dd      | _        |j                  | _        || _        y )Nr   patch_embeddings)filterskernel_sizestridesrF   kernel_initializerbias_initializerrU   	layernormepsilonrF   r!   )r"   r#   r   layersConv2Dhidden_sizes
patch_sizer   initializer_rangerJ   rK   r_   LayerNormalizationre   num_channelsrC   r%   rC   r&   r'   s      r(   r#   zTFConvNextV2Embeddings.__init__w   s    "6" % 3 3''*))%%#.v/G/GH"//557 !4 !
 88K8X"//r)   c                   t        |t              r|d   }t        j                  j	                  t        |      d   | j                  d       t        j                  |d      }| j                  |      }| j                  |      }|S )Npixel_valuesr   zeMake sure that the channel dimension of the pixel values match with the one set in the configuration.)message)r   rP   r   r   perm)

isinstancedictr+   	debuggingassert_equalr   rn   	transposer_   re   )r%   rq   
embeddingss      r(   r5   zTFConvNextV2Embeddings.call   s|    lD)'7L
!!|$Q'{ 	" 	
 ||L|D**<8
^^J/
r)   c                ,   | j                   ry d| _         t        | dd       et        j                  | j                  j
                        5  | j                  j                  d d d | j                  j                  g       d d d        t        | dd       it        j                  | j                  j
                        5  | j                  j                  d d d | j                  j                  d   g       d d d        y y # 1 sw Y   xY w# 1 sw Y   y xY w)NTr_   re   r   )builtgetattrr+   
name_scoper_   rF   rL   rC   rn   re   rj   r%   rM   s     r(   rL   zTFConvNextV2Embeddings.build   s    ::
4+T2>t4499: Z%%++T4t{{?W?W,XYZ4d+7t~~223 V$$dD$8P8PQR8S%TUV V 8Z ZV Vs   4C>=7D
>D
DrC   r   r7   r9   r:   r;   r<   r#   r5   rL   r=   r>   s   @r(   r]   r]   r   s    &	Vr)   r]   c                  6     e Zd ZdZdd fdZddZddZ xZS )	TFConvNextV2Layera  This corresponds to the `Block` class in the original implementation.

    There are two equivalent implementations: [DwConv, LayerNorm (channels_first), 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

    The authors used (2) as they find it slightly faster in PyTorch. Since we already permuted the inputs to follow
    NHWC ordering, we can just apply the operations straight-away without the permutation.

    Args:
        config (`ConvNextV2Config`):
            Model configuration class.
        dim (`int`):
            Number of input channels.
        drop_path (`float`, *optional*, defaults to 0.0):
            Stochastic depth rate.
    c           	        t        |   di | || _        || _        t        j
                  j                  |dd|t        |j                        t        j                  j                         d      | _        t        j
                  j                  dd      | _        t        j
                  j                  d|z  t        |j                        t        j                  j                         d	
      | _        t!        |j"                        | _        t'        |d|z  t(        j*                  d      | _        t        j
                  j                  |t        |j                        t        j                  j                         d
      | _        |dkD  rt1        |d      | _        y t        j
                  j3                  dd      | _        y )Nr   samedwconv)r`   ra   paddinggroupsrc   rd   rF   rU   re   rf      pwconv1unitsrc   rd   rF   grn)dtyperF   pwconv2        r$   rF   linearr!   )r"   r#   rB   rC   r   rh   ri   r   rl   rJ   rK   r   rm   re   Denser   r	   
hidden_actactr@   r+   float32r   r   r   
Activationr$   )r%   rC   rB   r$   r&   r'   s        r(   r#   zTFConvNextV2Layer.__init__   s   "6"ll)).v/G/GH"//557 * 
 88 9 
 ||))c'.v/G/GH"//557	 * 
 %V%6%67"61s7"**5Q||)).v/G/GH"//557	 * 
 3 != 	 (((D 	r)   c                   |}| j                  |      }| j                  |      }| j                  |      }| j                  |      }| j	                  |      }| j                  |      }| j                  ||      }||z   }|S )Nr2   )r   re   r   r   r   r   r$   )r%   rX   r2   inputr1   s        r(   r5   zTFConvNextV2Layer.call   sw    KK&NN1LLOHHQKHHQKLLONN1xN0AIr)   c                n   | j                   ry d| _         t        | dd       [t        j                  | j                  j
                        5  | j                  j                  d d d | j                  g       d d d        t        | dd       [t        j                  | j                  j
                        5  | j                  j                  d d d | j                  g       d d d        t        | dd       Zt        j                  | j                  j
                        5  | j                  j                  d d | j                  g       d d d        t        | dd       Mt        j                  | j                  j
                        5  | j                  j                  d        d d d        t        | dd       ]t        j                  | j                  j
                        5  | j                  j                  d d d| j                  z  g       d d d        t        | dd       Nt        j                  | j                  j
                        5  | j                  j                  d        d d d        y y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   DxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)	NTr   re   r   r   r   r   r$   )r|   r}   r+   r~   r   rF   rL   rB   re   r   r   r   r$   r   s     r(   rL   zTFConvNextV2Layer.build   s   ::
44(4t{{//0 @!!4tTXX">?@4d+7t~~223 C$$dD$%ABC4D)5t||001 ;""D$#9:;4%1txx}}- %t$%4D)5t||001 ?""D$DHH#=>?4d+7t~~223 +$$T*+ + 8@ @C C; ;% %? ?+ +sH   *I,3*I9)JJ,JJ+,I69JJJJ(+J4)r   )rC   r   rB   r[   r$   r6   )Fr7   r   r>   s   @r(   r   r      s    "%
N
+r)   r   c                  V     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd ZddZ xZS )TFConvNextV2Stagea  ConvNextV2 stage, consisting of an optional downsampling layer + multiple residual blocks.

    Args:
        config (`ConvNextV2V2Config`):
            Model configuration class.
        in_channels (`int`):
            Number of input channels.
        out_channels (`int`):
            Number of output channels.
        depth (`int`):
            Number of residual blocks.
        drop_path_rates(`List[float]`):
            Stochastic depth rates for each layer.
    c           
        t        
|   d
i | ||k7  s|dkD  r{t        j                  j	                  dd      t        j                  j                  |||t        |j                        t        j                  j                         d      g| _
        nt        j                  g| _
        |xs dg|z  }t        |      D 	cg c]  }	t        ||||	   d|	 	       c}	| _        || _        || _        || _        y c c}	w )Nr   rU   zdownsampling_layer.0rf   zdownsampling_layer.1)r`   ra   rb   rc   rd   rF   r   zlayers.)rB   r$   rF   r!   )r"   r#   r   rh   rm   ri   r   rl   rJ   rK   downsampling_layerr+   identityranger   in_channelsout_channelsstride)r%   rC   r   r   ra   r   depthdrop_path_ratesr&   jr'   s             r(   r#   zTFConvNextV2Stage.__init__  s    	"6",&&1*// / 0  ##( +"'6v7O7O'P%*%7%7%=%=%?/ $ 'D#( (*{{mD#):cUU] 5\
   )!,qc]	
 '(
s   C=c                j    | j                   D ]
  } ||      } | j                  D ]
  } ||      } |S r7   )r   rh   )r%   rX   layers      r(   r5   zTFConvNextV2Stage.callC  sD    ,, 	1E!-0M	1[[ 	1E!-0M	1r)   c                   | j                   ry d| _         t        | dd       J| j                  D ];  }t        j                  |j
                        5  |j                  d        d d d        = | j                  | j                  k7  s| j                  dkD  rt        j                  | j                  d   j
                        5  | j                  d   j                  d d d | j                  g       d d d        t        j                  | j                  d   j
                        5  | j                  d   j                  d d d | j                  g       d d d        y y # 1 sw Y   4xY w# 1 sw Y   yxY w# 1 sw Y   y xY w)NTrh   r   r   )r|   r}   rh   r+   r~   rF   rL   r   r   r   r   )r%   rM   r   s      r(   rL   zTFConvNextV2Stage.buildJ  sS   ::
44(4 &]]5::. &KK%& && t000DKK!Ot66q9>>? W''*00$dDDTDT1UVWt66q9>>? W''*00$dDDTDT1UVW W 5D& &W WW Ws$   E -E%!-E1E"	%E.1E:)rP   rP   rP   N)rC   r   r   r[   r   r[   ra   r[   r   r[   r   r[   r   zOptional[List[float]]r7   r   r>   s   @r(   r   r     sk    ( 15/ / / 	/
 / / / //bWr)   r   c                  D     e Zd Zd fdZ	 	 d	 	 	 	 	 	 	 ddZddZ xZS )TFConvNextV2Encoderc                <   t        	|   di | g | _        t        j                  d|j
                  t        |j                              }t        j                  ||j                        }|D cg c]   }|j                         j                         " }}|j                  d   }t        |j                        D ]Z  }|j                  |   }t        ||||dkD  rdnd|j                  |   ||   d|       }| j                  j                  |       |}\ y c c}w )Nr   r   rP   r   zstages.)r   r   r   r   r   rF   r!   )r"   r#   stagesr+   linspacedrop_path_ratesumdepthssplitnumpytolistrj   r   
num_stagesr   append)
r%   rC   r&   r   r1   prev_chsiout_chsstager'   s
            r(   r#   zTFConvNextV2Encoder.__init__Z  s   "6"++c6+@+@#fmmBTU((?FMMB7FG!1779++-GG&&q)v(() 	A))!,G%$$EqqmmA& / 2qc]E KKu%H	 Hs   0%Dc                    |rdnd }t        | j                        D ]  \  }}|r||fz   } ||      } |r||fz   }|st        d ||fD              S t        ||      S )Nr!   c              3  &   K   | ]	  }||  y wr7   r!   ).0vs     r(   	<genexpr>z+TFConvNextV2Encoder.call.<locals>.<genexpr>  s     Xq!-Xs   )last_hidden_staterX   )	enumerater   tupler
   )r%   rX   output_hidden_statesreturn_dictall_hidden_statesr   layer_modules          r(   r5   zTFConvNextV2Encoder.callo  s     #7BD(5 	8OA|#$58H$H!(7M		8   1]4D DX]4E$FXXX/-_pqqr)   c                    | j                   D ];  }t        j                  |j                        5  |j	                  d        d d d        = y # 1 sw Y   HxY wr7   )r   r+   r~   rF   rL   )r%   rM   r   s      r(   rL   zTFConvNextV2Encoder.build  sK    [[ 	"Euzz* "D!" "	"" "s   AA	r   )FT)rX   r8   r   Optional[bool]r   r   returnz.Union[Tuple, TFBaseModelOutputWithNoAttention]r7   )r9   r:   r;   r#   r5   rL   r=   r>   s   @r(   r   r   Y  sE    0 05&*	r r -r $	r
 
8r,"r)   r   c                  Z     e Zd ZeZd fdZe	 	 	 	 d	 	 	 	 	 	 	 	 	 dd       ZddZ xZ	S )TFConvNextV2MainLayerc                $   t        |   di | || _        t        |d      | _        t        |d      | _        t        j                  j                  |j                  d      | _        t        j                  j                  d      | _        y )	Nrz   r   encoderre   rf   channels_last)data_formatr!   )r"   r#   rC   r]   rz   r   r   r   rh   rm   layer_norm_epsre   GlobalAvgPool2Dpoolerro   s      r(   r#   zTFConvNextV2MainLayer.__init__  ss    "6"0lK*6	B88AVAV]h8i ll222Or)   c           	         ||n| j                   j                  }||n| j                   j                  }|t        d      | j	                  ||      }| j                  ||||      }|d   }| j                  |      }t        j                  |d      }| j                  |      }|r1t        |d   D 	cg c]  }	t        j                  |	d       c}	      }
|s|r
nd}
||f|
z   S t        |||r
	      S |j                  	      S c c}	w )
N You have to specify pixel_valuesr   r   r   r2   r   )r   r   r   rP   rs   r   r!   r   pooler_outputrX   )rC   r   use_return_dict
ValueErrorrz   r   r   r+   ry   re   r   r   rX   )r%   rq   r   r   r2   embedding_outputencoder_outputsr   pooled_outputhrX   s              r(   r5   zTFConvNextV2MainLayer.call  s4    %9$D $++JjJj 	 &1%<k$++B]B]?@@??<(?K,,!5#	 ' 
 ,A. $56LL):N}5  !_`Oa"b!2<<#E"bcM-AMrM%}5EE9/'+?-
 	
 FUEbEb
 	
 #cs   6Dc                   | j                   ry d| _         t        | dd       Mt        j                  | j                  j
                        5  | j                  j                  d        d d d        t        | dd       Mt        j                  | j                  j
                        5  | j                  j                  d        d d d        t        | dd       gt        j                  | j                  j
                        5  | j                  j                  d | j                  j                  d   g       d d d        y y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NTrz   r   re   rT   )r|   r}   r+   r~   rz   rF   rL   r   re   rC   rj   r   s     r(   rL   zTFConvNextV2MainLayer.build  s   ::
4t,8t334 ,%%d+,4D)5t||001 )""4()4d+7t~~223 K$$dDKK,D,DR,H%IJK K 8, ,) )K Ks$   D>%E
?5E>E
EEr   NNNF)
rq   TFModelInputType | Noner   r   r   r   r2   boolr   z5Union[TFBaseModelOutputWithPooling, Tuple[tf.Tensor]]r7   )
r9   r:   r;   r   config_classr#   r   r5   rL   r=   r>   s   @r(   r   r     sg    #L	P  15/3&*+
-+
 -+
 $	+

 +
 
?+
 +
ZKr)   r   c                      e Zd ZdZeZdZdZy)TFConvNextV2PreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    
convnextv2rq   N)r9   r:   r;   r<   r   r   base_model_prefixmain_input_namer!   r)   r(   r   r     s    
 $L$$Or)   r   a	  
    This model inherits from [`TFPreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a [keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model) subclass. Use it
    as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to general usage and
    behavior.

    <Tip>

    TensorFlow models and layers in `transformers` accept two formats as input:

    - having all inputs as keyword arguments (like PyTorch models), or
    - having all inputs as a list, tuple or dict in the first positional argument.

    The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
    and layers. Because of this support, when using methods like `model.fit()` things should "just work" for you - just
    pass your inputs and labels in any format that `model.fit()` supports! If, however, you want to use the second
    format outside of Keras methods like `fit()` and `predict()`, such as when creating your own layers or models with
    the Keras `Functional` API, there are three possibilities you can use to gather all the input Tensors in the first
    positional argument:

    - a single Tensor with `pixel_values` only and nothing else: `model(pixel_values)`
    - a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
    `model([pixel_values, attention_mask])` or `model([pixel_values, attention_mask, token_type_ids])`
    - a dictionary with one or several input Tensors associated to the input names given in the docstring:
    `model({"pixel_values": pixel_values, "token_type_ids": token_type_ids})`

    Note that when creating models and layers with
    [subclassing](https://keras.io/guides/making_new_layers_and_models_via_subclassing/) then you don't need to worry
    about any of this, as you can just pass inputs like you would to any other Python function!

    </Tip>

    Parameters:
        config ([`ConvNextV2Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
a  
    Args:
        pixel_values (`np.ndarray`, `tf.Tensor`, `List[tf.Tensor]`, `Dict[str, tf.Tensor]` or `Dict[str, np.ndarray]` and each example must have the shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail. This argument can be used only in eager mode, in graph mode the value in the config will be
            used instead.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple. This argument can be used in
            eager mode, in graph mode the value will always be set to `True`.
zSThe bare ConvNextV2 model outputting raw features without any specific head on top.c            	           e Zd Zd fdZe ee       eee	e
de      	 	 	 	 d	 	 	 	 	 	 	 	 	 dd                     Zd	dZ xZS )
TFConvNextV2Modelc                P    t        |   |g|i | t        |d      | _        y )Nr   r   )r"   r#   r   r   r%   rC   inputsr&   r'   s       r(   r#   zTFConvNextV2Model.__init__   s(    3&3F3/\Jr)   vision)
checkpointoutput_typer   modalityexpected_outputc                   ||n| j                   j                  }||n| j                   j                  }|t        d      | j	                  ||||      }|s|d d  S t        |j                  |j                  |j                        S )Nr   )rq   r   r   r2   r   )	rC   r   r   r   r   r   r   r   rX   )r%   rq   r   r   r2   outputss         r(   r5   zTFConvNextV2Model.call$  s    " %9$D $++JjJj 	 &1%<k$++B]B]?@@//%!5#	 " 
 1:9%77!//!//
 	
r)   c                    | j                   ry d| _         t        | dd       Nt        j                  | j                  j
                        5  | j                  j                  d        d d d        y y # 1 sw Y   y xY w)NTr   )r|   r}   r+   r~   r   rF   rL   r   s     r(   rL   zTFConvNextV2Model.buildL  si    ::
4t,8t334 ,%%d+, , 9, ,s   A11A:r   r   )
rq   r   r   r   r   r   r2   r   r   zCUnion[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]r7   )r9   r:   r;   r#   r   r   CONVNEXTV2_INPUTS_DOCSTRINGr   _CHECKPOINT_FOR_DOCr   _CONFIG_FOR_DOC_EXPECTED_OUTPUT_SHAPEr5   rL   r=   r>   s   @r(   r   r     s    
K *+FG&>$. 15/3&*
-
 -
 $	

 
 
M
 H 
>,r)   r   z
    ConvNextV2 Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    c                       e Zd Zd fdZe ee       eee	e
e      	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd                     ZddZ xZS )	"TFConvNextV2ForImageClassificationc                4   t        |   |g|i | |j                  | _        t        |d      | _        t
        j                  j                  |j                  t        |j                        t
        j                  j                         d      | _        y )Nr   r   
classifierr   )r"   r#   
num_labelsr   r   r   rh   r   r   rl   rJ   rK   r   r   s       r(   r#   z+TFConvNextV2ForImageClassification.__init__]  s~    3&3F3 ++/\J  ,,,,##.v/G/GH"//557	 - 
r)   )r   r   r   r   c                ~   ||n| j                   j                  }||n| j                   j                  }|t        d      | j	                  ||||      }|r|j
                  n|d   }| j                  |      }|dn| j                  ||      }	|s|f|dd z   }
|	|	f|
z   S |
S t        |	||j                        S )a  
        labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size,)`, *optional*):
            Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        Nr   r   r   )labelslogitsrP   )lossr  rX   )
rC   r   r   r   r   r   r   hf_compute_lossr   rX   )r%   rq   r   r   r   r2   r   r   r  r  outputs              r(   r5   z'TFConvNextV2ForImageClassification.callk  s    . %9$D $++JjJj 	 &1%<k$++B]B]?@@//!5#	 " 
 2=--'!*/~t4+?+?vV\+?+]Y,F)-)9TGf$EvE5!//
 	
r)   c                   | j                   ry d| _         t        | dd       Mt        j                  | j                  j
                        5  | j                  j                  d        d d d        t        | dd       ht        j                  | j                  j
                        5  | j                  j                  d d | j                  j                  d   g       d d d        y y # 1 sw Y   xY w# 1 sw Y   y xY w)NTr   r   rT   )
r|   r}   r+   r~   r   rF   rL   r   rC   rj   r   s     r(   rL   z(TFConvNextV2ForImageClassification.build  s    ::
4t,8t334 ,%%d+,4t,8t334 R%%tT4;;3K3KB3O&PQR R 9, ,R Rs   C%%6C1%C.1C:r   )NNNNF)rq   r   r   r   r   r   r   znp.ndarray | tf.Tensor | Noner2   r   r   z?Union[TFImageClassifierOutputWithNoAttention, Tuple[tf.Tensor]]r7   )r9   r:   r;   r#   r   r   r   r   _IMAGE_CLASS_CHECKPOINTr   r   _IMAGE_CLASS_EXPECTED_OUTPUTr5   rL   r=   r>   s   @r(   r   r   U  s    
 *+FG*:$4	 15/3&*04#(*
-*
 -*
 $	*

 .*
 !*
 
I*
 H *
X	Rr)   r   ):r<   
__future__r   typingr   r   r   r   r   np
tensorflowr+   activations_tfr	   modeling_tf_outputsr
   r   r   r   modeling_tf_utilsr   r   r   r   r   r   r   tf_utilsr   utilsr   r   r   r   configuration_convnextv2r   
get_loggerr9   loggerr   r   r   r  r  rh   Layerr   r@   r]   r   r   r   r   r   CONVNEXTV2_START_DOCSTRINGr   r   r   r!   r)   r(   <module>r     s    " / /   /    #  7 
		H	% % 8 '  < 1 5<<-- (ell(( :/VU\\// /VdZ+** Z+|TW** TWn/"%,,,, /"d HKELL.. HK HKV%"3 %' R   Y3,3 3,	3,l  LR)DFb LRLRr)   