





from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_lowercase		:     int 					=logging.get_logger(__name__)






class 	UpperCamelCase_     (     snake_case__       ):
					_a			:	List[Any]							=				['input_ids', 'attention_mask']



					def __init__(		self    :    Dict					,			lowerCamelCase    :    Dict="[PAD]"					,			lowerCamelCase    :    List[str]="[BOS]"					,			lowerCamelCase    :    str="[EOS]"					,			lowerCamelCase    :    Tuple="[MASK]"					,			lowerCamelCase    :    List[Any]="[CLS]"					,			lowerCamelCase    :    Optional[int]="[SEP]"					,			lowerCamelCase    :    List[str]=20_48					,			**lowerCamelCase    :    str					,			):
							lowerCamelCase_  :    int   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else pad_token
							lowerCamelCase_  :    int   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else bos_token
							lowerCamelCase_  :    Tuple   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else eos_token
							lowerCamelCase_  :    List[Any]   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else mask_token
							lowerCamelCase_  :    Optional[Any]   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else cls_token
							lowerCamelCase_  :    List[Any]   	=			AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase	) if isinstance(lowerCamelCase					,			lowerCamelCase	) else sep_token

							super().__init__(
							    pad_token=lowerCamelCase					,			bos_token=lowerCamelCase					,			eos_token=lowerCamelCase					,			mask_token=lowerCamelCase					,			cls_token=lowerCamelCase					,			sep_token=lowerCamelCase					,			model_max_length=lowerCamelCase					,			**lowerCamelCase					,			)

							lowerCamelCase_  :    str   	=			2**8  # utf is 8 bits

							# define special tokens dict
							lowerCamelCase_  :    Dict[str, int]   	=			{
							    self.pad_token: 0,
							    self.bos_token: 1,
							    self.eos_token: 2,
							    self.mask_token: 3,
							    self.cls_token: 4,
							    self.sep_token: 5,
							}
							lowerCamelCase_  :    Optional[int]   	=			len(self.special_tokens_encoder	)
							lowerCamelCase_  :    Dict[int, str]   	=			{v: k for k, v in self.special_tokens_encoder.items()}



					def      __a    (		self    :    List[str]	):
							lowerCamelCase_  :    Dict   	=			self.special_tokens_encoder.copy()
							vocab.update(self.added_tokens_encoder	)
							for i in range(self._utf_vocab_size	):
									lowerCamelCase_  :    Tuple   	=			chr(lowerCamelCase	)
									lowerCamelCase_  :    List[str]   	=			i + len(self.special_tokens_encoder	)
							return vocab



					@property
					def      __a    (		self    :    Optional[Any]	):
							return self._utf_vocab_size + self._num_special_tokens



					def      __a    (		self    :    Tuple					,			lowerCamelCase    :    List[int]					,			lowerCamelCase    :    Optional[List[int]] = None					,			lowerCamelCase    :    bool = False	):
							if already_has_special_tokens:
									return super().get_special_tokens_mask(
									    token_ids_a=lowerCamelCase					,			token_ids_a=lowerCamelCase					,			already_has_special_tokens=lowerCamelCase	)

							# normal case: some special tokens
							if token_ids_a is None:
									return [1] + [0] * len(lowerCamelCase	) + [1]
							return [1] + ([0] * len(lowerCamelCase	)) + [1] + ([0] * len(lowerCamelCase	)) + [1]



					def      __a    (		self    :    Union[str, Any]					,			lowerCamelCase    :    List[int]					,			lowerCamelCase    :    Optional[List[int]] = None	):
							if token_ids_a is None:
									return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
							else:
									return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]



					def      __a    (		self    :    Optional[int]					,			lowerCamelCase    :    str	):
							lowerCamelCase_  :    Any   	=			[chr(lowerCamelCase	) for i in text.encode('utf-8'	)]
							return tokens



					def      __a    (		self    :    List[Any]					,			lowerCamelCase    :    Tuple	):
							if token in self.special_tokens_encoder:
									lowerCamelCase_  :    List[str]   	=			self.special_tokens_encoder[token]
							elif token in self.added_tokens_encoder:
									lowerCamelCase_  :    Tuple   	=			self.added_tokens_encoder[token]
							elif len(lowerCamelCase	) != 1:
									lowerCamelCase_  :    str   	=			self.unk_token_id
							else:
									lowerCamelCase_  :    Tuple   	=			ord(lowerCamelCase	) + self._num_special_tokens
							return token_id



					def      __a    (		self    :    Tuple					,			lowerCamelCase    :    Any	):
							if index in self.special_tokens_decoder:
									lowerCamelCase_  :    Any   	=			self.special_tokens_decoder[index]
							elif index in self.added_tokens_decoder:
									lowerCamelCase_  :    List[Any]   	=			self.added_tokens_decoder[index]
							else:
									lowerCamelCase_  :    Union[str, Any]   	=			chr(index - self._num_special_tokens	)
							return token



					def      __a    (		self    :    Optional[Any]					,			lowerCamelCase    :    Any	):
							lowerCamelCase_  :    Union[str, Any]   	=			b''
							for token in tokens:
									if token in self.special_tokens_decoder:
											lowerCamelCase_  :    Optional[int]   	=			self.special_tokens_decoder[token].encode('utf-8'	)
									elif token in self.added_tokens_decoder:
											lowerCamelCase_  :    Any   	=			self.special_tokens_decoder[token].encode('utf-8'	)
									elif token in self.special_tokens_encoder:
											lowerCamelCase_  :    Optional[Any]   	=			token.encode('utf-8'	)
									elif token in self.added_tokens_encoder:
											lowerCamelCase_  :    str   	=			token.encode('utf-8'	)
									else:
											lowerCamelCase_  :    Tuple   	=			bytes([ord(lowerCamelCase	)]	)
									bstring += tok_string
							lowerCamelCase_  :    str   	=			bstring.decode('utf-8'					,			errors='replace'	)
							return string





					def      __a    (		self    :    int					,			lowerCamelCase    :    str					,			lowerCamelCase    :    Optional[str] = None	):
							return ()







from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


_lowercase		:     Optional[Any] 					=logging.get_logger(__name__)

# General docstring
_lowercase		:     Union[str, Any] 					="""ResNetConfig"""

# Base docstring
_lowercase		:     Dict 					="""microsoft/resnet-50"""
_lowercase		:     Tuple 					=[1, 2048, 7, 7]

# Image classification docstring
_lowercase		:     Dict 					="""microsoft/resnet-50"""
_lowercase		:     int 					="""tiger cat"""

_lowercase		:     Optional[Any] 					=[
    """microsoft/resnet-50""",
    # See all resnet models at https://huggingface.co/models?filter=resnet
]






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    List[str]					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int = 3					,			lowerCamelCase    :    int = 1					,			lowerCamelCase    :    str = "relu"					,			**lowerCamelCase    :    Tuple	):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    Tuple   	=			kernel_size // 2
							lowerCamelCase_  :    Optional[int]   	=			tf.keras.layers.ConvaD(
							    lowerCamelCase					,			kernel_size=lowerCamelCase					,			strides=lowerCamelCase					,			padding='valid'					,			use_bias=lowerCamelCase					,			name='convolution'	)
							# Use same default momentum and epsilon as PyTorch equivalent
							lowerCamelCase_  :    Union[str, Any]   	=			tf.keras.layers.BatchNormalization(epsilon=1E-5					,			momentum=0.9					,			name='normalization'	)
							lowerCamelCase_  :    Optional[Any]   	=			ACTaFN[activation] if activation is not None else tf.keras.layers.Activation('linear'	)



					def      __a    (		self    :    int					,			lowerCamelCase    :    tf.Tensor	):
							# Pad to match that done in the PyTorch Conv2D model
							lowerCamelCase_  :    int   	=			(self.pad_value, self.pad_value)
							lowerCamelCase_  :    Optional[Any]   	=			tf.pad(lowerCamelCase					,			[(0, 0), height_pad, width_pad, (0, 0)]	)
							lowerCamelCase_  :    str   	=			self.conv(lowerCamelCase	)
							return hidden_state





					def      __a    (		self    :    Tuple					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							lowerCamelCase_  :    Optional[Any]   	=			self.convolution(lowerCamelCase	)
							lowerCamelCase_  :    int   	=			self.normalization(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    Any   	=			self.activation(lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    Dict					,			lowerCamelCase    :    ResNetConfig					,			**lowerCamelCase    :    Optional[Any]	):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    Union[str, Any]   	=			TFResNetConvLayer(
							    config.embedding_size					,			kernel_size=7					,			stride=2					,			activation=config.hidden_act					,			name='embedder'					,			)
							lowerCamelCase_  :    Any   	=			tf.keras.layers.MaxPoolaD(pool_size=3					,			strides=2					,			padding='valid'					,			name='pooler'	)
							lowerCamelCase_  :    Any   	=			config.num_channels





					def      __a    (		self    :    List[Any]					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							lowerCamelCase_	,			lowerCamelCase_	,			lowerCamelCase_	,			lowerCamelCase_  :    Tuple   	=			shape_list(lowerCamelCase	)
							if tf.executing_eagerly() and num_channels != self.num_channels:
									raise ValueError(
									    'Make sure that the channel dimension of the pixel values match with the one set in the configuration.'	)
							lowerCamelCase_  :    Optional[int]   	=			pixel_values
							lowerCamelCase_  :    Optional[Any]   	=			self.embedder(lowerCamelCase	)
							lowerCamelCase_  :    Optional[int]   	=			tf.pad(lowerCamelCase					,			[[0, 0], [1, 1], [1, 1], [0, 0]]	)
							lowerCamelCase_  :    str   	=			self.pooler(lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    Union[str, Any]					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int = 2					,			**lowerCamelCase    :    List[Any]	):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    int   	=			tf.keras.layers.ConvaD(
							    lowerCamelCase					,			kernel_size=1					,			strides=lowerCamelCase					,			use_bias=lowerCamelCase					,			name='convolution'	)
							# Use same default momentum and epsilon as PyTorch equivalent
							lowerCamelCase_  :    Any   	=			tf.keras.layers.BatchNormalization(epsilon=1E-5					,			momentum=0.9					,			name='normalization'	)





					def      __a    (		self    :    Tuple					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							lowerCamelCase_  :    Union[str, Any]   	=			x
							lowerCamelCase_  :    Optional[int]   	=			self.convolution(lowerCamelCase	)
							lowerCamelCase_  :    List[str]   	=			self.normalization(lowerCamelCase					,			training=lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    List[Any]					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int = 1					,			lowerCamelCase    :    str = "relu"					,			**lowerCamelCase    :    Optional[int]	):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    Any   	=			in_channels != out_channels or stride != 1
							lowerCamelCase_  :    Tuple   	=			TFResNetConvLayer(lowerCamelCase					,			stride=lowerCamelCase					,			name='layer.0'	)
							lowerCamelCase_  :    str   	=			TFResNetConvLayer(lowerCamelCase					,			activation=lowerCamelCase					,			name='layer.1'	)
							lowerCamelCase_  :    Any   	=			(
							    TFResNetShortCut(lowerCamelCase					,			stride=lowerCamelCase					,			name='shortcut'	)
							    if should_apply_shortcut
							    else tf.keras.layers.Activation('linear'					,			name='shortcut'	)
							)
							lowerCamelCase_  :    str   	=			ACTaFN[activation]





					def      __a    (		self    :    List[Any]					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							lowerCamelCase_  :    Optional[int]   	=			hidden_state
							lowerCamelCase_  :    Tuple   	=			self.conva(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    List[Any]   	=			self.conva(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    int   	=			self.shortcut(lowerCamelCase					,			training=lowerCamelCase	)
							hidden_state += residual
							lowerCamelCase_  :    Dict   	=			self.activation(lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    Optional[Any]					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int = 1					,			lowerCamelCase    :    str = "relu"					,			lowerCamelCase    :    int = 4					,			**lowerCamelCase    :    Optional[int]					,			):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    List[Any]   	=			in_channels != out_channels or stride != 1
							lowerCamelCase_  :    Optional[Any]   	=			out_channels // reduction
							lowerCamelCase_  :    int   	=			TFResNetConvLayer(lowerCamelCase					,			kernel_size=1					,			name='layer.0'	)
							lowerCamelCase_  :    Tuple   	=			TFResNetConvLayer(lowerCamelCase					,			stride=lowerCamelCase					,			name='layer.1'	)
							lowerCamelCase_  :    Optional[int]   	=			TFResNetConvLayer(lowerCamelCase					,			kernel_size=1					,			activation=lowerCamelCase					,			name='layer.2'	)
							lowerCamelCase_  :    Optional[Any]   	=			(
							    TFResNetShortCut(lowerCamelCase					,			stride=lowerCamelCase					,			name='shortcut'	)
							    if should_apply_shortcut
							    else tf.keras.layers.Activation('linear'					,			name='shortcut'	)
							)
							lowerCamelCase_  :    List[Any]   	=			ACTaFN[activation]





					def      __a    (		self    :    str					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							lowerCamelCase_  :    int   	=			hidden_state
							lowerCamelCase_  :    Tuple   	=			self.conva(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    List[Any]   	=			self.conva(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    List[str]   	=			self.conva(lowerCamelCase					,			training=lowerCamelCase	)
							lowerCamelCase_  :    List[Any]   	=			self.shortcut(lowerCamelCase					,			training=lowerCamelCase	)
							hidden_state += residual
							lowerCamelCase_  :    int   	=			self.activation(lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    int					,			lowerCamelCase    :    ResNetConfig					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int					,			lowerCamelCase    :    int = 2					,			lowerCamelCase    :    int = 2					,			**lowerCamelCase    :    List[Any]	):
							super().__init__(**lowerCamelCase	)

							lowerCamelCase_  :    List[Any]   	=			TFResNetBottleNeckLayer if config.layer_type == 'bottleneck' else TFResNetBasicLayer

							lowerCamelCase_  :    Tuple   	=			[layer(lowerCamelCase					,			lowerCamelCase					,			stride=lowerCamelCase					,			activation=config.hidden_act					,			name='layers.0'	)]
							layers += [
							    layer(lowerCamelCase					,			lowerCamelCase					,			activation=config.hidden_act					,			name=F"layers.{i + 1}"	)
							    for i in range(depth - 1	)
							]
							lowerCamelCase_  :    Dict   	=			layers





					def      __a    (		self    :    Any					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False	):
							for layer in self.stage_layers:
									lowerCamelCase_  :    Any   	=			layer(lowerCamelCase					,			training=lowerCamelCase	)
							return hidden_state






class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):



					def __init__(		self    :    List[Any]					,			lowerCamelCase    :    ResNetConfig					,			**lowerCamelCase    :    Optional[Any]	):
							super().__init__(**lowerCamelCase	)
							# based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
							lowerCamelCase_  :    List[Any]   	=			[
							    TFResNetStage(
							        lowerCamelCase					,			config.embedding_size					,			config.hidden_sizes[0]					,			stride=2 if config.downsample_in_first_stage else 1					,			depth=config.depths[0]					,			name='stages.0'					,			)
							]
							for i, (in_channels, out_channels, depth) in enumerate(
							    zip(config.hidden_sizes					,			config.hidden_sizes[1:]					,			config.depths[1:]	)	):
									self.stages.append(TFResNetStage(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			depth=lowerCamelCase					,			name=F"stages.{i + 1}"	)	)





					def      __a    (		self    :    Optional[int]					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    bool = False					,			lowerCamelCase    :    bool = True					,			lowerCamelCase    :    bool = False					,			):
							lowerCamelCase_  :    Optional[int]   	=			() if output_hidden_states else None

							for stage_module in self.stages:
									if output_hidden_states:
											lowerCamelCase_  :    Any   	=			hidden_states + (hidden_state,)

									lowerCamelCase_  :    Optional[Any]   	=			stage_module(lowerCamelCase					,			training=lowerCamelCase	)

							if output_hidden_states:
									lowerCamelCase_  :    Union[str, Any]   	=			hidden_states + (hidden_state,)

							if not return_dict:
									return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

							return TFBaseModelOutputWithNoAttention(last_hidden_state=lowerCamelCase					,			hidden_states=lowerCamelCase	)






class 	UpperCamelCase_     (     snake_case__       ):
					_a			:	int							=				ResNetConfig
					_a			:	Optional[Any]							=				'resnet'
					_a			:	int							=				'pixel_values'



					@property
					def      __a    (		self    :    Tuple	):
							return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_24, 2_24)					,			dtype=tf.floataa	)}
_lowercase		:     Union[str, Any] 					=r"""
    This model is a TensorFlow
    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a
    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`ResNetConfig`]): 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.
"""


_lowercase		:     Optional[Any] 					=r"""
    Args:
        pixel_values (`tf.Tensor` of 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.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
"""






@keras_serializable
class 	UpperCamelCase_     (     tf.keras.layers.Layer       ):
					_a			:	int							=				ResNetConfig



					def __init__(		self    :    Dict					,			lowerCamelCase    :    ResNetConfig					,			**lowerCamelCase    :    List[str]	):
							super().__init__(**lowerCamelCase	)
							lowerCamelCase_  :    Tuple   	=			config
							lowerCamelCase_  :    int   	=			TFResNetEmbeddings(lowerCamelCase					,			name='embedder'	)
							lowerCamelCase_  :    Union[str, Any]   	=			TFResNetEncoder(lowerCamelCase					,			name='encoder'	)
							lowerCamelCase_  :    Tuple   	=			tf.keras.layers.GlobalAveragePoolingaD(keepdims=lowerCamelCase	)





					@unpack_inputs
					def      __a    (		self    :    List[str]					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    Optional[bool] = None					,			lowerCamelCase    :    Optional[bool] = None					,			lowerCamelCase    :    bool = False					,			):
							lowerCamelCase_  :    str   	=			(
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							lowerCamelCase_  :    Optional[Any]   	=			return_dict if return_dict is not None else self.config.use_return_dict

							# TF 2.0 image layers can't use NCHW format when running on CPU.
							# We transpose to NHWC format and then transpose back after the full forward pass.
							# (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
							lowerCamelCase_  :    str   	=			tf.transpose(lowerCamelCase					,			perm=[0, 2, 3, 1]	)
							lowerCamelCase_  :    Any   	=			self.embedder(lowerCamelCase					,			training=lowerCamelCase	)

							lowerCamelCase_  :    str   	=			self.encoder(
							    lowerCamelCase					,			output_hidden_states=lowerCamelCase					,			return_dict=lowerCamelCase					,			training=lowerCamelCase	)

							lowerCamelCase_  :    Optional[int]   	=			encoder_outputs[0]

							lowerCamelCase_  :    str   	=			self.pooler(lowerCamelCase	)

							# Transpose all the outputs to the NCHW format
							# (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
							lowerCamelCase_  :    str   	=			tf.transpose(lowerCamelCase					,			(0, 3, 1, 2)	)
							lowerCamelCase_  :    Tuple   	=			tf.transpose(lowerCamelCase					,			(0, 3, 1, 2)	)
							lowerCamelCase_  :    Dict   	=			()
							for hidden_state in encoder_outputs[1:]:
									lowerCamelCase_  :    Dict   	=			hidden_states + tuple(tf.transpose(lowerCamelCase					,			(0, 3, 1, 2)	) for h in hidden_state	)

							if not return_dict:
									return (last_hidden_state, pooled_output) + hidden_states

							lowerCamelCase_  :    Dict   	=			hidden_states if output_hidden_states else None

							return TFBaseModelOutputWithPoolingAndNoAttention(
							    last_hidden_state=lowerCamelCase					,			pooler_output=lowerCamelCase					,			hidden_states=lowerCamelCase					,			)






@add_start_docstrings(
    'The bare ResNet model outputting raw features without any specific head on top.'     ,    snake_case__     ,    )
class 	UpperCamelCase_     (     snake_case__       ):



					def __init__(		self    :    Any					,			lowerCamelCase    :    ResNetConfig					,			**lowerCamelCase    :    int	):
							super().__init__(lowerCamelCase					,			**lowerCamelCase	)
							lowerCamelCase_  :    List[str]   	=			TFResNetMainLayer(config=lowerCamelCase					,			name='resnet'	)





					@add_start_docstrings_to_model_forward(lowerCamelCase	)
					@add_code_sample_docstrings(
					    checkpoint=_CHECKPOINT_FOR_DOC					,			output_type=lowerCamelCase					,			config_class=_CONFIG_FOR_DOC					,			modality='vision'					,			expected_output=_EXPECTED_OUTPUT_SHAPE					,			)
					@unpack_inputs
					def      __a    (		self    :    List[str]					,			lowerCamelCase    :    tf.Tensor					,			lowerCamelCase    :    Optional[bool] = None					,			lowerCamelCase    :    Optional[bool] = None					,			lowerCamelCase    :    bool = False					,			):
							lowerCamelCase_  :    List[str]   	=			(
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							lowerCamelCase_  :    Tuple   	=			return_dict if return_dict is not None else self.config.use_return_dict

							lowerCamelCase_  :    Dict   	=			self.resnet(
							    pixel_values=lowerCamelCase					,			output_hidden_states=lowerCamelCase					,			return_dict=lowerCamelCase					,			training=lowerCamelCase					,			)
							return resnet_outputs






@add_start_docstrings(
    '\n    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '     ,    snake_case__     ,    )
class 	UpperCamelCase_     (     snake_case__     ,    snake_case__       ):



					def __init__(		self    :    Tuple					,			lowerCamelCase    :    ResNetConfig					,			**lowerCamelCase    :    Optional[Any]	):
							super().__init__(lowerCamelCase					,			**lowerCamelCase	)
							lowerCamelCase_  :    Tuple   	=			config.num_labels
							lowerCamelCase_  :    Union[str, Any]   	=			TFResNetMainLayer(lowerCamelCase					,			name='resnet'	)
							# classification head
							lowerCamelCase_  :    Dict   	=			(
							    tf.keras.layers.Dense(config.num_labels					,			name='classifier.1'	)
							    if config.num_labels > 0
							    else tf.keras.layers.Activation('linear'					,			name='classifier.1'	)
							)



					def      __a    (		self    :    List[str]					,			lowerCamelCase    :    tf.Tensor	):
							lowerCamelCase_  :    Tuple   	=			tf.keras.layers.Flatten()(lowerCamelCase	)
							lowerCamelCase_  :    Dict   	=			self.classifier_layer(lowerCamelCase	)
							return logits





					@add_start_docstrings_to_model_forward(lowerCamelCase	)
					@add_code_sample_docstrings(
					    checkpoint=_IMAGE_CLASS_CHECKPOINT					,			output_type=lowerCamelCase					,			config_class=_CONFIG_FOR_DOC					,			expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT					,			)
					@unpack_inputs
					def      __a    (		self    :    Optional[int]					,			lowerCamelCase    :    tf.Tensor = None					,			lowerCamelCase    :    tf.Tensor = None					,			lowerCamelCase    :    bool = None					,			lowerCamelCase    :    bool = None					,			lowerCamelCase    :    bool = False					,			):
							lowerCamelCase_  :    List[str]   	=			return_dict if return_dict is not None else self.config.use_return_dict

							lowerCamelCase_  :    Optional[int]   	=			self.resnet(
							    lowerCamelCase					,			output_hidden_states=lowerCamelCase					,			return_dict=lowerCamelCase					,			training=lowerCamelCase	)

							lowerCamelCase_  :    Union[str, Any]   	=			outputs.pooler_output if return_dict else outputs[1]

							lowerCamelCase_  :    Union[str, Any]   	=			self.classifier(lowerCamelCase	)

							lowerCamelCase_  :    List[Any]   	=			None if labels is None else self.hf_compute_loss(lowerCamelCase					,			lowerCamelCase	)

							if not return_dict:
									lowerCamelCase_  :    int   	=			(logits,) + outputs[2:]
									return (loss,) + output if loss is not None else output

							return TFImageClassifierOutputWithNoAttention(loss=lowerCamelCase					,			logits=lowerCamelCase					,			hidden_states=outputs.hidden_states	)
