


'''simple docstring'''


from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


_UpperCamelCase 							=  logging.get_logger(__name__)

# General docstring
_UpperCamelCase 							=  """RegNetConfig"""

# Base docstring
_UpperCamelCase 							=  """facebook/regnet-y-040"""
_UpperCamelCase 							=  [1, 1088, 7, 7]

# Image classification docstring
_UpperCamelCase 							=  """facebook/regnet-y-040"""
_UpperCamelCase 							=  """tabby, tabby cat"""

_UpperCamelCase 							=  [
    """facebook/regnet-y-040""",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase = 3			,     lowerCamelCase = 1			,     lowerCamelCase = 1			,     lowerCamelCase = "relu"			,     **lowerCamelCase			,     ):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          # The padding and conv has been verified in
          # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
          __A	:       str      =							tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2		)
          __A	:       List[str]      =							tf.keras.layers.ConvaD(
              filters=lowerCamelCase			,     kernel_size=lowerCamelCase			,     strides=lowerCamelCase			,     padding="VALID"			,     groups=lowerCamelCase			,     use_bias=lowerCamelCase			,     name="convolution"			,     )
          __A	:       Optional[int]      =							tf.keras.layers.BatchNormalization(epsilon=1E-5			,     momentum=0.9			,     name="normalization"		)
          __A	:       Tuple      =							ACTaFN[activation] if activation is not None else tf.identity


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.convolution(self.padding(lowerCamelCase		)		)
          __A	:       Union[str, Any]      =							self.normalization(lowerCamelCase		)
          __A	:       Any      =							self.activation(lowerCamelCase		)
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       Optional[Any]      =							config.num_channels
          __A	:       Any      =							TFRegNetConvLayer(
              out_channels=config.embedding_size			,     kernel_size=3			,     stride=2			,     activation=config.hidden_act			,     name="embedder"			,     )


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Optional[int]      =							shape_list(lowerCamelCase		)[1]
          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."		)

          # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
          # So change the input format from `NCHW` to `NHWC`.
          # shape = (batch_size, in_height, in_width, in_channels=num_channels)
          __A	:       Optional[Any]      =							tf.transpose(lowerCamelCase			,     perm=(0, 2, 3, 1)		)
          __A	:       int      =							self.embedder(lowerCamelCase		)
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase = 2			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       Dict      =							tf.keras.layers.ConvaD(
              filters=lowerCamelCase			,     kernel_size=1			,     strides=lowerCamelCase			,     use_bias=lowerCamelCase			,     name="convolution"		)
          __A	:       Dict      =							tf.keras.layers.BatchNormalization(epsilon=1E-5			,     momentum=0.9			,     name="normalization"		)


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase = False		):


          '''simple docstring'''





          return self.normalization(self.convolution(lowerCamelCase		)			,     training=lowerCamelCase		)







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       List[Any]      =							tf.keras.layers.GlobalAveragePoolingaD(keepdims=lowerCamelCase			,     name="pooler"		)
          __A	:       List[str]      =							[
              tf.keras.layers.ConvaD(filters=lowerCamelCase			,     kernel_size=1			,     activation="relu"			,     name="attention.0"		),
              tf.keras.layers.ConvaD(filters=lowerCamelCase			,     kernel_size=1			,     activation="sigmoid"			,     name="attention.2"		),
          ]


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.pooler(lowerCamelCase		)
          for layer_module in self.attention:
               __A	:       List[Any]      =							layer_module(lowerCamelCase		)
          __A	:       int      =							hidden_state * pooled
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase = 1			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       Optional[int]      =							in_channels != out_channels or stride != 1
          __A	:       List[str]      =							max(1			,     out_channels // config.groups_width		)
          __A	:       int      =							(
              TFRegNetShortCut(lowerCamelCase			,     stride=lowerCamelCase			,     name="shortcut"		)
              if should_apply_shortcut
              else tf.keras.layers.Activation("linear"			,     name="shortcut"		)
          )
          # `self.layers` instead of `self.layer` because that is a reserved argument.
          __A	:       Optional[Any]      =							[
              TFRegNetConvLayer(lowerCamelCase			,     kernel_size=1			,     activation=config.hidden_act			,     name="layer.0"		),
              TFRegNetConvLayer(
                  lowerCamelCase			,     stride=lowerCamelCase			,     groups=lowerCamelCase			,     activation=config.hidden_act			,     name="layer.1"		),
              TFRegNetConvLayer(lowerCamelCase			,     kernel_size=1			,     activation=lowerCamelCase			,     name="layer.2"		),
          ]
          __A	:       str      =							ACTaFN[config.hidden_act]


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							hidden_state
          for layer_module in self.layers:
               __A	:       Tuple      =							layer_module(lowerCamelCase		)
          __A	:       Union[str, Any]      =							self.shortcut(lowerCamelCase		)
          hidden_state += residual
          __A	:       Tuple      =							self.activation(lowerCamelCase		)
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase = 1			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       Union[str, Any]      =							in_channels != out_channels or stride != 1
          __A	:       str      =							max(1			,     out_channels // config.groups_width		)
          __A	:       Tuple      =							(
              TFRegNetShortCut(lowerCamelCase			,     stride=lowerCamelCase			,     name="shortcut"		)
              if should_apply_shortcut
              else tf.keras.layers.Activation("linear"			,     name="shortcut"		)
          )
          __A	:       Tuple      =							[
              TFRegNetConvLayer(lowerCamelCase			,     kernel_size=1			,     activation=config.hidden_act			,     name="layer.0"		),
              TFRegNetConvLayer(
                  lowerCamelCase			,     stride=lowerCamelCase			,     groups=lowerCamelCase			,     activation=config.hidden_act			,     name="layer.1"		),
              TFRegNetSELayer(lowerCamelCase			,     reduced_channels=int(round(in_channels / 4		)		)			,     name="layer.2"		),
              TFRegNetConvLayer(lowerCamelCase			,     kernel_size=1			,     activation=lowerCamelCase			,     name="layer.3"		),
          ]
          __A	:       str      =							ACTaFN[config.hidden_act]


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Tuple      =							hidden_state
          for layer_module in self.layers:
               __A	:       Optional[int]      =							layer_module(lowerCamelCase		)
          __A	:       int      =							self.shortcut(lowerCamelCase		)
          hidden_state += residual
          __A	:       str      =							self.activation(lowerCamelCase		)
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase = 2			,     lowerCamelCase = 2			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)

          __A	:       Dict      =							TFRegNetXLayer if config.layer_type == "x" else TFRegNetYLayer
          __A	:       Tuple      =							[
              # downsampling is done in the first layer with stride of 2
              layer(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     stride=lowerCamelCase			,     name="layers.0"		),
              *[layer(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     name=f"layers.{i+1}"		) for i in range(depth - 1		)],
          ]


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          for layer_module in self.layers:
               __A	:       Optional[int]      =							layer_module(lowerCamelCase		)
          return hidden_state







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       List[Any]      =							[]
          # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
          self.stages.append(
              TFRegNetStage(
                  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"			,     )		)
          __A	:       List[Any]      =							zip(config.hidden_sizes			,     config.hidden_sizes[1:]		)
          for i, ((in_channels, out_channels), depth) in enumerate(zip(lowerCamelCase			,     config.depths[1:]		)		):
               self.stages.append(TFRegNetStage(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     depth=lowerCamelCase			,     name=f"stages.{i+1}"		)		)


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase = False			,     lowerCamelCase = True		):


          '''simple docstring'''





          __A	:       Optional[int]      =							() if output_hidden_states else None

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

               __A	:       List[Any]      =							stage_module(lowerCamelCase		)

          if output_hidden_states:
               __A	:       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		)







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

     """simple docstring"""






     lowerCamelCase__       						=				RegNetConfig


     def __init__(   self			,     lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)
          __A	:       List[str]      =							config
          __A	:       List[Any]      =							TFRegNetEmbeddings(lowerCamelCase			,     name="embedder"		)
          __A	:       List[Any]      =							TFRegNetEncoder(lowerCamelCase			,     name="encoder"		)
          __A	:       List[str]      =							tf.keras.layers.GlobalAveragePoolingaD(keepdims=lowerCamelCase			,     name="pooler"		)


     @unpack_inputs
     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase = None			,     lowerCamelCase = None			,     lowerCamelCase = False			,     ):


          '''simple docstring'''





          __A	:       Tuple      =							(
              output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
          )
          __A	:       str      =							return_dict if return_dict is not None else self.config.use_return_dict

          __A	:       Tuple      =							self.embedder(lowerCamelCase			,     training=lowerCamelCase		)

          __A	:       Optional[int]      =							self.encoder(
              lowerCamelCase			,     output_hidden_states=lowerCamelCase			,     return_dict=lowerCamelCase			,     training=lowerCamelCase		)

          __A	:       Optional[int]      =							encoder_outputs[0]
          __A	:       Tuple      =							self.pooler(lowerCamelCase		)

          # Change to NCHW output format have uniformity in the modules
          __A	:       Optional[Any]      =							tf.transpose(lowerCamelCase			,     perm=(0, 3, 1, 2)		)
          __A	:       Optional[int]      =							tf.transpose(lowerCamelCase			,     perm=(0, 3, 1, 2)		)

          # Change the other hidden state outputs to NCHW as well
          if output_hidden_states:
               __A	:       int      =							tuple([tf.transpose(lowerCamelCase			,     perm=(0, 3, 1, 2)		) for h in encoder_outputs[1]]		)

          if not return_dict:
               return (last_hidden_state, pooled_output) + encoder_outputs[1:]

          return TFBaseModelOutputWithPoolingAndNoAttention(
              last_hidden_state=lowerCamelCase			,     pooler_output=lowerCamelCase			,     hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states			,     )







class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     lowerCamelCase__       						=				RegNetConfig
     lowerCamelCase__       						=				'regnet'
     lowerCamelCase__       						=				'pixel_values'


     @property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)			,     dtype=tf.floataa		)}


_UpperCamelCase 							=  r"""
    Parameters:
    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.
        config ([`RegNetConfig`]): 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.
"""

_UpperCamelCase 							=  r"""
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConveNextImageProcessor.__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.
"""







@add_start_docstrings(
    'The bare RegNet model outputting raw features without any specific head on top.'    ,		lowerCAmelCase    ,		)
class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     *lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(lowerCamelCase			,     *lowerCamelCase			,     **lowerCamelCase		)
          __A	:       int      =							TFRegNetMainLayer(lowerCamelCase			,     name="regnet"		)


     @unpack_inputs
     @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			,     )
     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase = None			,     lowerCamelCase = None			,     lowerCamelCase=False			,     ):


          '''simple docstring'''





          __A	:       Optional[int]      =							(
              output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
          )
          __A	:       str      =							return_dict if return_dict is not None else self.config.use_return_dict

          __A	:       Tuple      =							self.regnet(
              pixel_values=lowerCamelCase			,     output_hidden_states=lowerCamelCase			,     return_dict=lowerCamelCase			,     training=lowerCamelCase			,     )
          if not return_dict:
               return (outputs[0],) + outputs[1:]

          return TFBaseModelOutputWithPoolingAndNoAttention(
              last_hidden_state=outputs.last_hidden_state			,     pooler_output=outputs.pooler_output			,     hidden_states=outputs.hidden_states			,     )







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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     *lowerCamelCase			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(lowerCamelCase			,     *lowerCamelCase			,     **lowerCamelCase		)
          __A	:       List[str]      =							config.num_labels
          __A	:       List[str]      =							TFRegNetMainLayer(lowerCamelCase			,     name="regnet"		)
          # classification head
          __A	:       Dict      =							[
              tf.keras.layers.Flatten(),
              tf.keras.layers.Dense(config.num_labels			,     name="classifier.1"		) if config.num_labels > 0 else tf.identity,
          ]


     @unpack_inputs
     @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			,     )
     def lowerCAmelCase__  (   self			,     lowerCamelCase = None			,     lowerCamelCase = None			,     lowerCamelCase = None			,     lowerCamelCase = None			,     lowerCamelCase=False			,     ):


          '''simple docstring'''





          __A	:       Tuple      =							(
              output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
          )
          __A	:       Tuple      =							return_dict if return_dict is not None else self.config.use_return_dict

          __A	:       List[Any]      =							self.regnet(
              lowerCamelCase			,     output_hidden_states=lowerCamelCase			,     return_dict=lowerCamelCase			,     training=lowerCamelCase		)

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

          __A	:       int      =							self.classifier[0](lowerCamelCase		)
          __A	:       Dict      =							self.classifier[1](lowerCamelCase		)

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

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

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





'''simple docstring'''


# Function to print upper half of diamond (pyramid)


def 		_lowercase (SCREAMING_SNAKE_CASE							):




     '''simple docstring'''





     for i in range(0       ,					SCREAMING_SNAKE_CASE							):
          for _ in range(0       ,					n - i - 1							):  # printing spaces
               print(" "       ,					end=""							)
          for _ in range(0       ,					i + 1							):  # printing stars
               print("* "       ,					end=""							)
          print()


def 		_lowercase (SCREAMING_SNAKE_CASE							):




     '''simple docstring'''





     for i in range(SCREAMING_SNAKE_CASE       ,					0       ,					-1							):
          for _ in range(SCREAMING_SNAKE_CASE       ,					0       ,					-1							):  # printing stars
               print("* "       ,					end=""							)
          print()
          for _ in range(n - i + 1       ,					0       ,					-1							):  # printing spaces
               print(" "       ,					end=""							)


def 		_lowercase (SCREAMING_SNAKE_CASE							):




     '''simple docstring'''





     if n <= 0:
          print("       ...       ....        nothing printing :("							)
          return
     floyd(SCREAMING_SNAKE_CASE							)  # upper half
     reverse_floyd(SCREAMING_SNAKE_CASE							)  # lower half


if __name__ == "__main__":
      print(r"""| /\ | |- |  |-  |--| |\  /| |-""")
      print(r"""|/  \| |- |_ |_  |__| | \/ | |_""")
      _UpperCamelCase 							=  1
      while K:
            _UpperCamelCase 							=  int(input("""enter the number and , and see the magic : """))
            print()
            pretty_print(user_number)
            _UpperCamelCase 							=  int(input("""press 0 to exit... and 1 to continue..."""))

      print("""Good Bye...""")

