



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


_SCREAMING_SNAKE_CASE 		=						logging.get_logger(__name__)

# General docstring
_SCREAMING_SNAKE_CASE 		=						"""RegNetConfig"""

# Base docstring
_SCREAMING_SNAKE_CASE 		=						"""facebook/regnet-y-040"""
_SCREAMING_SNAKE_CASE 		=						[1, 10_88, 7, 7]

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

_SCREAMING_SNAKE_CASE 		=						[
    """facebook/regnet-y-040""",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : List[str]						,				_A : int						,				_A : Dict = 3						,				_A : List[Any] = 1						,				_A : Any = 1						,				_A : Tuple = "relu"						,				**_A : List[Any]						,				)							->      Tuple:







							"""simple docstring"""


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






						def UpperCAmelCase_			( self : List[Any]						,				_A : Dict		)							->      List[Any]:







							"""simple docstring"""


							snake_case_						:     Any     =		self.convolution(self.padding(_A		)		)
							snake_case_						:     List[str]     =		self.normalization(_A		)
							snake_case_						:     Tuple     =		self.activation(_A		)
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Union[str, Any]						,				_A : List[str]						,				**_A : int		)							->      int:







							"""simple docstring"""


							super().__init__(**_A		)
							snake_case_						:     int     =		config.num_channels
							snake_case_						:     int     =		TFRegNetConvLayer(
							    out_channels=config.embedding_size						,				kernel_size=3						,				stride=2						,				activation=config.hidden_act						,				name='embedder'						,				)






						def UpperCAmelCase_			( self : List[str]						,				_A : str		)							->      str:







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		shape_list(_A		)[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)
							snake_case_						:     Optional[int]     =		tf.transpose(_A						,				perm=(0, 2, 3, 1)		)
							snake_case_						:     Dict     =		self.embedder(_A		)
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Any						,				_A : Any						,				_A : Optional[int] = 2						,				**_A : str		)							->      List[Any]:







							"""simple docstring"""


							super().__init__(**_A		)
							snake_case_						:     List[str]     =		tf.keras.layers.ConvaD(
							    filters=_A						,				kernel_size=1						,				strides=_A						,				use_bias=_A						,				name='convolution'		)
							snake_case_						:     int     =		tf.keras.layers.BatchNormalization(epsilon=1E-5						,				momentum=0.9						,				name='normalization'		)






						def UpperCAmelCase_			( self : Optional[int]						,				_A : List[Any]						,				_A : List[str] = False		)							->      Dict:







							"""simple docstring"""


							return self.normalization(self.convolution(_A		)						,				training=_A		)
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Dict						,				_A : Union[str, Any]						,				_A : int						,				**_A : Tuple		)							->      Any:







							"""simple docstring"""


							super().__init__(**_A		)
							snake_case_						:     str     =		tf.keras.layers.GlobalAveragePoolingaD(keepdims=_A						,				name='pooler'		)
							snake_case_						:     Union[str, Any]     =		[
							    tf.keras.layers.ConvaD(filters=_A						,				kernel_size=1						,				activation='relu'						,				name='attention.0'		),
							    tf.keras.layers.ConvaD(filters=_A						,				kernel_size=1						,				activation='sigmoid'						,				name='attention.2'		),
							]






						def UpperCAmelCase_			( self : Optional[Any]						,				_A : Optional[int]		)							->      Union[str, Any]:







							"""simple docstring"""


							snake_case_						:     Tuple     =		self.pooler(_A		)
							for layer_module in self.attention:
								snake_case_						:     List[str]     =		layer_module(_A		)
							snake_case_						:     Tuple     =		hidden_state * pooled
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Union[str, Any]						,				_A : List[str]						,				_A : str						,				_A : Union[str, Any]						,				_A : List[str] = 1						,				**_A : Any		)							->      List[Any]:







							"""simple docstring"""


							super().__init__(**_A		)
							snake_case_						:     Dict     =		in_channels != out_channels or stride != 1
							snake_case_						:     Dict     =		max(1						,				out_channels // config.groups_width		)
							snake_case_						:     Any     =		(
							    TFRegNetShortCut(_A						,				stride=_A						,				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.
							snake_case_						:     str     =		[
							    TFRegNetConvLayer(_A						,				kernel_size=1						,				activation=config.hidden_act						,				name='layer.0'		),
							    TFRegNetConvLayer(
							        _A						,				stride=_A						,				groups=_A						,				activation=config.hidden_act						,				name='layer.1'		),
							    TFRegNetConvLayer(_A						,				kernel_size=1						,				activation=_A						,				name='layer.2'		),
							]
							snake_case_						:     Union[str, Any]     =		ACTaFN[config.hidden_act]






						def UpperCAmelCase_			( self : Dict						,				_A : Union[str, Any]		)							->      Tuple:







							"""simple docstring"""


							snake_case_						:     Optional[int]     =		hidden_state
							for layer_module in self.layers:
								snake_case_						:     Optional[int]     =		layer_module(_A		)
							snake_case_						:     str     =		self.shortcut(_A		)
							hidden_state += residual
							snake_case_						:     Tuple     =		self.activation(_A		)
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : List[Any]						,				_A : List[Any]						,				_A : Optional[Any]						,				_A : Dict						,				_A : Optional[Any] = 1						,				**_A : Optional[Any]		)							->      int:







							"""simple docstring"""


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






						def UpperCAmelCase_			( self : int						,				_A : str		)							->      Any:







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		hidden_state
							for layer_module in self.layers:
								snake_case_						:     Optional[Any]     =		layer_module(_A		)
							snake_case_						:     Any     =		self.shortcut(_A		)
							hidden_state += residual
							snake_case_						:     Tuple     =		self.activation(_A		)
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Tuple						,				_A : Optional[int]						,				_A : Optional[int]						,				_A : Any						,				_A : Optional[int] = 2						,				_A : Tuple = 2						,				**_A : Any		)							->      str:







							"""simple docstring"""


							super().__init__(**_A		)

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






						def UpperCAmelCase_			( self : Tuple						,				_A : Optional[int]		)							->      Union[str, Any]:







							"""simple docstring"""


							for layer_module in self.layers:
								snake_case_						:     Dict     =		layer_module(_A		)
							return hidden_state
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):






						def __init__( self : Dict						,				_A : Union[str, Any]						,				**_A : Tuple		)							->      Any:







							"""simple docstring"""


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






						def UpperCAmelCase_			( self : Union[str, Any]						,				_A : List[Any]						,				_A : Union[str, Any] = False						,				_A : Union[str, Any] = True		)							->      int:







							"""simple docstring"""


							snake_case_						:     int     =		() if output_hidden_states else None

							for stage_module in self.stages:
								if output_hidden_states:
									snake_case_						:     List[Any]     =		hidden_states + (hidden_state,)

								snake_case_						:     Any     =		stage_module(_A		)

							if output_hidden_states:
								snake_case_						:     Dict     =		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=_A						,				hidden_states=_A		)
@keras_serializable
class SCREAMING_SNAKE_CASE_  (   tf.keras.layers.Layer   ):
						__magic_name__:     Any	 =    RegNetConfig






						def __init__( self : List[Any]						,				_A : Optional[Any]						,				**_A : Any		)							->      Any:







							"""simple docstring"""


							super().__init__(**_A		)
							snake_case_						:     Dict     =		config
							snake_case_						:     Optional[Any]     =		TFRegNetEmbeddings(_A						,				name='embedder'		)
							snake_case_						:     int     =		TFRegNetEncoder(_A						,				name='encoder'		)
							snake_case_						:     Tuple     =		tf.keras.layers.GlobalAveragePoolingaD(keepdims=_A						,				name='pooler'		)






						@unpack_inputs
						def UpperCAmelCase_			( self : List[Any]						,				_A : Dict						,				_A : List[str] = None						,				_A : str = None						,				_A : List[Any] = False						,				)							->      Dict:







							"""simple docstring"""


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

							snake_case_						:     Dict     =		self.embedder(_A						,				training=_A		)

							snake_case_						:     List[Any]     =		self.encoder(
							    _A						,				output_hidden_states=_A						,				return_dict=_A						,				training=_A		)

							snake_case_						:     Optional[Any]     =		encoder_outputs[0]
							snake_case_						:     str     =		self.pooler(_A		)

							# Change to NCHW output format have uniformity in the modules
							snake_case_						:     Any     =		tf.transpose(_A						,				perm=(0, 3, 1, 2)		)
							snake_case_						:     List[str]     =		tf.transpose(_A						,				perm=(0, 3, 1, 2)		)

							# Change the other hidden state outputs to NCHW as well
							if output_hidden_states:
								snake_case_						:     int     =		tuple([tf.transpose(_A						,				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=_A						,				pooler_output=_A						,				hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states						,				)
class SCREAMING_SNAKE_CASE_  (   snake_case_   ):
						__magic_name__:     List[str]	 =    RegNetConfig
						__magic_name__:     int	 =    "regnet"
						__magic_name__:     List[Any]	 =    "pixel_values"






						@property
						def UpperCAmelCase_			( self : List[str]		)							->      Optional[int]:







							"""simple docstring"""


							return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)						,				dtype=tf.floataa		)}
_SCREAMING_SNAKE_CASE 		=						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.
"""

_SCREAMING_SNAKE_CASE 		=						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."    ,			snake_case_    ,			)
class SCREAMING_SNAKE_CASE_  (   snake_case_   ):






						def __init__( self : int						,				_A : List[str]						,				*_A : Tuple						,				**_A : Tuple		)							->      Any:







							"""simple docstring"""


							super().__init__(_A						,				*_A						,				**_A		)
							snake_case_						:     Any     =		TFRegNetMainLayer(_A						,				name='regnet'		)






						@unpack_inputs
						@add_start_docstrings_to_model_forward(_A		)
						@add_code_sample_docstrings(
						    checkpoint=_CHECKPOINT_FOR_DOC						,				output_type=_A						,				config_class=_CONFIG_FOR_DOC						,				modality='vision'						,				expected_output=_EXPECTED_OUTPUT_SHAPE						,				)
						def UpperCAmelCase_			( self : Tuple						,				_A : Union[str, Any]						,				_A : Union[str, Any] = None						,				_A : List[Any] = None						,				_A : Optional[Any]=False						,				)							->      str:







							"""simple docstring"""


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

							snake_case_						:     List[Any]     =		self.regnet(
							    pixel_values=_A						,				output_hidden_states=_A						,				return_dict=_A						,				training=_A						,				)
							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    "    ,			snake_case_    ,			)
class SCREAMING_SNAKE_CASE_  (   snake_case_    ,			snake_case_   ):






						def __init__( self : Tuple						,				_A : List[Any]						,				*_A : Dict						,				**_A : Optional[Any]		)							->      List[str]:







							"""simple docstring"""


							super().__init__(_A						,				*_A						,				**_A		)
							snake_case_						:     List[Any]     =		config.num_labels
							snake_case_						:     int     =		TFRegNetMainLayer(_A						,				name='regnet'		)
							# classification head
							snake_case_						:     List[Any]     =		[
							    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(_A		)
						@add_code_sample_docstrings(
						    checkpoint=_IMAGE_CLASS_CHECKPOINT						,				output_type=_A						,				config_class=_CONFIG_FOR_DOC						,				expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT						,				)
						def UpperCAmelCase_			( self : Tuple						,				_A : List[Any] = None						,				_A : str = None						,				_A : Tuple = None						,				_A : Union[str, Any] = None						,				_A : str=False						,				)							->      Tuple:







							"""simple docstring"""


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

							snake_case_						:     Tuple     =		self.regnet(
							    _A						,				output_hidden_states=_A						,				return_dict=_A						,				training=_A		)

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

							snake_case_						:     Any     =		self.classifier[0](_A		)
							snake_case_						:     Dict     =		self.classifier[1](_A		)

							snake_case_						:     Tuple     =		None if labels is None else self.hf_compute_loss(labels=_A						,				logits=_A		)

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

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








from decimal import Decimal, getcontext
from math import ceil, factorial


def 							SCREAMING_SNAKE_CASE__  (      __a				):

	if not isinstance(__a				,	__a				):
		raise TypeError('Undefined for non-integers'				)
	elif precision < 1:
		raise ValueError('Undefined for non-natural numbers'				)

	snake_case_						:     Dict     =		precision
	snake_case_						:     str     =		ceil(precision / 14				)
	snake_case_						:     str     =		42_68_80 * Decimal(1_00_05				).sqrt()
	snake_case_						:     Tuple     =		1
	snake_case_						:     int     =		13_59_14_09
	snake_case_						:     Tuple     =		Decimal(__a				)
	for k in range(1				,	__a				):
		snake_case_						:     List[Any]     =		factorial(6 * k				) // (factorial(3 * k				) * factorial(__a				) ** 3)
		linear_term += 5_45_14_01_34
		exponential_term *= -26_25_37_41_26_40_76_80_00
		partial_sum += Decimal(multinomial_term * linear_term				) / exponential_term
	return str(constant_term / partial_sum				)[:-1]


if __name__ == "__main__":
						_SCREAMING_SNAKE_CASE 		=						50
						print(F'''The first {n} digits of pi is: {pi(n)}''')

