


'''simple docstring'''



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


A__		: str												=  logging.get_logger(__name__)

# General docstring
A__		: int												=  """ResNetConfig"""

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

# Image classification docstring
A__		: int												=  """microsoft/resnet-50"""
A__		: Any												=  """tiger cat"""

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





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





    """simple docstring"""






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







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_     )    ->					tf.Tensor:
         __lowerCamelCase       :     Optional[int]        =		(self.pad_value, self.pad_value)
         __lowerCamelCase       :     Dict        =		tf.pad(SCREAMING_SNAKE_CASE_      ,					[(0, 0), height_pad, width_pad, (0, 0)]     )
         __lowerCamelCase       :     List[str]        =		self.conv(SCREAMING_SNAKE_CASE_     )
         return hidden_state







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:
         __lowerCamelCase       :     Dict        =		self.convolution(SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Optional[Any]        =		self.normalization(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     int        =		self.activation(SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(**SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     List[str]        =		TFResNetConvLayer(
             config.embedding_size      ,					kernel_size=7      ,					stride=2      ,					activation=config.hidden_act      ,					name='embedder'      ,					)
         __lowerCamelCase       :     int        =		tf.keras.layers.MaxPoolaD(pool_size=3      ,					strides=2      ,					padding='valid'      ,					name='pooler'     )
         __lowerCamelCase       :     Tuple        =		config.num_channels







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:
         __lowerCamelCase       :     int        =		shape_list(SCREAMING_SNAKE_CASE_     )
         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       :     Tuple        =		pixel_values
         __lowerCamelCase       :     Tuple        =		self.embedder(SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Dict        =		tf.pad(SCREAMING_SNAKE_CASE_      ,					[[0, 0], [1, 1], [1, 1], [0, 0]]     )
         __lowerCamelCase       :     List[Any]        =		self.pooler(SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






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







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:
         __lowerCamelCase       :     Union[str, Any]        =		x
         __lowerCamelCase       :     Optional[Any]        =		self.convolution(SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     str        =		self.normalization(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






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







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:
         __lowerCamelCase       :     Optional[int]        =		hidden_state
         __lowerCamelCase       :     Tuple        =		self.conva(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Union[str, Any]        =		self.conva(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     str        =		self.shortcut(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         hidden_state += residual
         __lowerCamelCase       :     Tuple        =		self.activation(SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






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







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:
         __lowerCamelCase       :     Union[str, Any]        =		hidden_state
         __lowerCamelCase       :     Dict        =		self.conva(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Optional[int]        =		self.conva(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     int        =		self.conva(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     List[Any]        =		self.shortcut(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         hidden_state += residual
         __lowerCamelCase       :     int        =		self.activation(SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = 2      ,					SCREAMING_SNAKE_CASE_ = 2      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(**SCREAMING_SNAKE_CASE_     )

         __lowerCamelCase       :     str        =		TFResNetBottleNeckLayer if config.layer_type == "bottleneck" else TFResNetBasicLayer

         __lowerCamelCase       :     Optional[Any]        =		[layer(SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					stride=SCREAMING_SNAKE_CASE_      ,					activation=config.hidden_act      ,					name='layers.0'     )]
         layers += [
             layer(SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					activation=config.hidden_act      ,					name=f'layers.{i + 1}'     )
             for i in range(depth - 1     )
         ]
         __lowerCamelCase       :     int        =		layers







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False     )    ->					tf.Tensor:

         for layer in self.stage_layers:
              __lowerCamelCase       :     Dict        =		layer(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )
         return hidden_state







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





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(**SCREAMING_SNAKE_CASE_     )
         # based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
         __lowerCamelCase       :     str        =		[
             TFResNetStage(
                 SCREAMING_SNAKE_CASE_      ,					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(SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					depth=SCREAMING_SNAKE_CASE_      ,					name=f'stages.{i + 1}'     )     )







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = False      ,					SCREAMING_SNAKE_CASE_ = True      ,					SCREAMING_SNAKE_CASE_ = False      ,					)    ->					TFBaseModelOutputWithNoAttention:
         __lowerCamelCase       :     Union[str, Any]        =		() if output_hidden_states else None

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

              __lowerCamelCase       :     str        =		stage_module(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )

         if output_hidden_states:
              __lowerCamelCase       :     Tuple        =		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=SCREAMING_SNAKE_CASE_      ,					hidden_states=SCREAMING_SNAKE_CASE_     )







class        UpperCAmelCase_  (__A  ):





    """simple docstring"""






    lowerCamelCase  : Dict												=      ResNetConfig
    lowerCamelCase  : List[Any]												=      'resnet'
    lowerCamelCase  : Tuple												=      'pixel_values'







    @property
    def 				lowercase_    (							self     )    ->					str:
         return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_24, 2_24)      ,					dtype=tf.floataa     )}







A__		: Dict												=  R"""\n    This model is a TensorFlow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n"""


A__		: List[str]												=  R"""\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n"""





@keras_serializable
class        UpperCAmelCase_  (tf.keras.layers.Layer  ):





    """simple docstring"""






    lowerCamelCase  : List[Any]												=      ResNetConfig







    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(**SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Dict        =		config
         __lowerCamelCase       :     Dict        =		TFResNetEmbeddings(SCREAMING_SNAKE_CASE_      ,					name='embedder'     )
         __lowerCamelCase       :     Dict        =		TFResNetEncoder(SCREAMING_SNAKE_CASE_      ,					name='encoder'     )
         __lowerCamelCase       :     Dict        =		tf.keras.layers.GlobalAveragePoolingaD(keepdims=SCREAMING_SNAKE_CASE_     )







    @unpack_inputs
    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = False      ,					)    ->					Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
         __lowerCamelCase       :     int        =		(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         __lowerCamelCase       :     List[str]        =		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       :     List[Any]        =		tf.transpose(SCREAMING_SNAKE_CASE_      ,					perm=[0, 2, 3, 1]     )
         __lowerCamelCase       :     Optional[Any]        =		self.embedder(SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )

         __lowerCamelCase       :     Dict        =		self.encoder(
             SCREAMING_SNAKE_CASE_      ,					output_hidden_states=SCREAMING_SNAKE_CASE_      ,					return_dict=SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )

         __lowerCamelCase       :     List[str]        =		encoder_outputs[0]

         __lowerCamelCase       :     str        =		self.pooler(SCREAMING_SNAKE_CASE_     )

         # Transpose all the outputs to the NCHW format
         # (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
         __lowerCamelCase       :     int        =		tf.transpose(SCREAMING_SNAKE_CASE_      ,					(0, 3, 1, 2)     )
         __lowerCamelCase       :     Optional[int]        =		tf.transpose(SCREAMING_SNAKE_CASE_      ,					(0, 3, 1, 2)     )
         __lowerCamelCase       :     Optional[int]        =		()
         for hidden_state in encoder_outputs[1:]:
              __lowerCamelCase       :     Union[str, Any]        =		hidden_states + tuple(tf.transpose(SCREAMING_SNAKE_CASE_      ,					(0, 3, 1, 2)     ) for h in hidden_state     )

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

         __lowerCamelCase       :     Tuple        =		hidden_states if output_hidden_states else None

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







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





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Optional[Any]        =		TFResNetMainLayer(config=SCREAMING_SNAKE_CASE_      ,					name='resnet'     )







    @add_start_docstrings_to_model_forward(SCREAMING_SNAKE_CASE_     )
    @add_code_sample_docstrings(
        checkpoint=_CHECKPOINT_FOR_DOC      ,					output_type=SCREAMING_SNAKE_CASE_      ,					config_class=_CONFIG_FOR_DOC      ,					modality='vision'      ,					expected_output=_EXPECTED_OUTPUT_SHAPE      ,					)
    @unpack_inputs
    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = False      ,					)    ->					Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
         __lowerCamelCase       :     Optional[Any]        =		(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         __lowerCamelCase       :     str        =		return_dict if return_dict is not None else self.config.use_return_dict

         __lowerCamelCase       :     str        =		self.resnet(
             pixel_values=SCREAMING_SNAKE_CASE_      ,					output_hidden_states=SCREAMING_SNAKE_CASE_      ,					return_dict=SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_      ,					)
         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    ' ,		__A ,		)
class        UpperCAmelCase_  (__A ,		__A  ):





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )    ->					None:
         super().__init__(SCREAMING_SNAKE_CASE_      ,					**SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Any        =		config.num_labels
         __lowerCamelCase       :     Any        =		TFResNetMainLayer(SCREAMING_SNAKE_CASE_      ,					name='resnet'     )
         # classification head
         __lowerCamelCase       :     Optional[int]        =		(
             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 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_     )    ->					tf.Tensor:
         __lowerCamelCase       :     Any        =		tf.keras.layers.Flatten()(SCREAMING_SNAKE_CASE_     )
         __lowerCamelCase       :     Dict        =		self.classifier_layer(SCREAMING_SNAKE_CASE_     )
         return logits







    @add_start_docstrings_to_model_forward(SCREAMING_SNAKE_CASE_     )
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT      ,					output_type=SCREAMING_SNAKE_CASE_      ,					config_class=_CONFIG_FOR_DOC      ,					expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,					)
    @unpack_inputs
    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = None      ,					SCREAMING_SNAKE_CASE_ = False      ,					)    ->					Union[Tuple[tf.Tensor], TFImageClassifierOutputWithNoAttention]:
         __lowerCamelCase       :     Optional[int]        =		return_dict if return_dict is not None else self.config.use_return_dict

         __lowerCamelCase       :     str        =		self.resnet(
             SCREAMING_SNAKE_CASE_      ,					output_hidden_states=SCREAMING_SNAKE_CASE_      ,					return_dict=SCREAMING_SNAKE_CASE_      ,					training=SCREAMING_SNAKE_CASE_     )

         __lowerCamelCase       :     Optional[int]        =		outputs.pooler_output if return_dict else outputs[1]

         __lowerCamelCase       :     List[Any]        =		self.classifier(SCREAMING_SNAKE_CASE_     )

         __lowerCamelCase       :     Dict        =		None if labels is None else self.hf_compute_loss(SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_     )

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

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










'''simple docstring'''



import math
from itertools import permutations



def       UpperCAmelCase__ (     UpperCAmelCase_   :    int							)					->		bool:

     if 1 < number < 4:
          # 2 and 3 are primes
          return True
     elif number < 2 or number % 2 == 0 or number % 3 == 0:
          # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
          return False

     # All primes number are in format of 6k +/- 1
     for i in range(5				,   int(math.sqrt(UpperCAmelCase_							) + 1							)				,   6							):
          if number % i == 0 or number % (i + 2) == 0:
               return False
     return True



def       UpperCAmelCase__ (     UpperCAmelCase_   :    int				,   UpperCAmelCase_   :    list							)					->		bool:
     __lowerCamelCase    ,	__lowerCamelCase       :     str        =		0, len(UpperCAmelCase_							) - 1
     while left <= right:
          __lowerCamelCase       :     Optional[Any]        =		(left + right) // 2
          if prime_list[middle] == target:
               return True
          elif prime_list[middle] < target:
               __lowerCamelCase       :     Union[str, Any]        =		middle + 1
          else:
               __lowerCamelCase       :     Union[str, Any]        =		middle - 1

     return False



def       UpperCAmelCase__ (     )					->		List[str]:
     __lowerCamelCase       :     Tuple        =		[n for n in range(10_01				,   1_00_00				,   2							) if is_prime(UpperCAmelCase_							)]
     __lowerCamelCase       :     Any        =		[]

     for number in prime_list:
          __lowerCamelCase       :     Optional[int]        =		[]

          for prime_member in permutations(list(str(UpperCAmelCase_							)							)							):
               __lowerCamelCase       :     int        =		int(''.join(UpperCAmelCase_							)							)

               if prime % 2 == 0:
                    continue

               if search(UpperCAmelCase_				,   UpperCAmelCase_							):
                    tmp_numbers.append(UpperCAmelCase_							)

          tmp_numbers.sort()
          if len(UpperCAmelCase_							) >= 3:
               candidates.append(UpperCAmelCase_							)

     __lowerCamelCase       :     int        =		[]
     for candidate in candidates:
          __lowerCamelCase       :     Union[str, Any]        =		len(UpperCAmelCase_							)
          __lowerCamelCase       :     Optional[Any]        =		False

          for i in range(UpperCAmelCase_							):
               for j in range(i + 1				,   UpperCAmelCase_							):
                    for k in range(j + 1				,   UpperCAmelCase_							):
                         if (
                             abs(candidate[i] - candidate[j]							)
                             == abs(candidate[j] - candidate[k]							)
                             and len({candidate[i], candidate[j], candidate[k]}							) == 3
                         ):
                              passed.append(
                                  sorted([candidate[i], candidate[j], candidate[k]]							)							)
                              __lowerCamelCase       :     List[str]        =		True

                         if found:
                              break
                    if found:
                         break
               if found:
                    break

     __lowerCamelCase       :     List[Any]        =		set()
     for seq in passed:
          answer.add(''.join([str(UpperCAmelCase_							) for i in seq]							)							)

     return max(int(UpperCAmelCase_							) for x in answer							)


if __name__ == "__main__":
      print(solution())






