



"""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


__snake_case							:   Any      =    logging.get_logger(__name__)

# General docstring
__snake_case							:   int      =    '''RegNetConfig'''

# Base docstring
__snake_case							:   Dict      =    '''facebook/regnet-y-040'''
__snake_case							:   Union[str, Any]      =    [1, 1_088, 7, 7]

# Image classification docstring
__snake_case							:   List[str]      =    '''facebook/regnet-y-040'''
__snake_case							:   Optional[Any]      =    '''tabby, tabby cat'''

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



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




	'''simple docstring'''





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

				"""simple docstring"""

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







	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		List[Any])				->       Any:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       self.convolution(self.padding(_SCREAMING_SNAKE_CASE))
				__lowerCAmelCase      :  Tuple												=       self.normalization(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       self.activation(_SCREAMING_SNAKE_CASE)
				return hidden_state






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




	'''simple docstring'''





	def __init__(     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			**_SCREAMING_SNAKE_CASE:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Any												=       config.num_channels
				__lowerCAmelCase      :  List[str]												=       TFRegNetConvLayer(
				    out_channels=config.embedding_size       ,			kernel_size=3       ,			stride=2       ,			activation=config.hidden_act       ,			name="embedder"       ,			)







	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       shape_list(_SCREAMING_SNAKE_CASE)[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)
				__lowerCAmelCase      :  List[str]												=       tf.transpose(_SCREAMING_SNAKE_CASE       ,			perm=(0, 2, 3, 1))
				__lowerCAmelCase      :  Union[str, Any]												=       self.embedder(_SCREAMING_SNAKE_CASE)
				return hidden_state






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




	'''simple docstring'''





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

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Tuple												=       tf.keras.layers.ConvaD(
				    filters=_SCREAMING_SNAKE_CASE       ,			kernel_size=1       ,			strides=_SCREAMING_SNAKE_CASE       ,			use_bias=_SCREAMING_SNAKE_CASE       ,			name="convolution")
				__lowerCAmelCase      :  Tuple												=       tf.keras.layers.BatchNormalization(epsilon=1e-5       ,			momentum=0.9       ,			name="normalization")







	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor       ,			_SCREAMING_SNAKE_CASE:		bool = False)				->       tf.Tensor:

				"""simple docstring"""

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






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




	'''simple docstring'''





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

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       tf.keras.layers.GlobalAveragePoolingaD(keepdims=_SCREAMING_SNAKE_CASE       ,			name="pooler")
				__lowerCAmelCase      :  Dict												=       [
				    tf.keras.layers.ConvaD(filters=_SCREAMING_SNAKE_CASE       ,			kernel_size=1       ,			activation="relu"       ,			name="attention.0"),
				    tf.keras.layers.ConvaD(filters=_SCREAMING_SNAKE_CASE       ,			kernel_size=1       ,			activation="sigmoid"       ,			name="attention.2"),
				]







	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any])				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.pooler(_SCREAMING_SNAKE_CASE)
				for layer_module in self.attention:
							__lowerCAmelCase      :  List[Any]												=       layer_module(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       hidden_state * pooled
				return hidden_state






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




	'''simple docstring'''





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

				"""simple docstring"""

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







	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[Any])				->       Any:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       hidden_state
				for layer_module in self.layers:
							__lowerCAmelCase      :  Union[str, Any]												=       layer_module(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       self.shortcut(_SCREAMING_SNAKE_CASE)
				hidden_state += residual
				__lowerCAmelCase      :  Tuple												=       self.activation(_SCREAMING_SNAKE_CASE)
				return hidden_state






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




	'''simple docstring'''





	def __init__(     self:		List[str]       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		int = 1       ,			**_SCREAMING_SNAKE_CASE:		List[Any])				->       str:

				"""simple docstring"""

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







	def 							_SCREAMING_SNAKE_CASE   (     self:		int       ,			_SCREAMING_SNAKE_CASE:		Any)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       hidden_state
				for layer_module in self.layers:
							__lowerCAmelCase      :  Optional[Any]												=       layer_module(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       self.shortcut(_SCREAMING_SNAKE_CASE)
				hidden_state += residual
				__lowerCAmelCase      :  Optional[Any]												=       self.activation(_SCREAMING_SNAKE_CASE)
				return hidden_state






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




	'''simple docstring'''





	def __init__(     self:		List[str]       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		int = 2       ,			_SCREAMING_SNAKE_CASE:		int = 2       ,			**_SCREAMING_SNAKE_CASE:		Optional[int])				->       Tuple:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

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







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

				"""simple docstring"""

				for layer_module in self.layers:
							__lowerCAmelCase      :  Dict												=       layer_module(_SCREAMING_SNAKE_CASE)
				return hidden_state






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




	'''simple docstring'''





	def __init__(     self:		int       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			**_SCREAMING_SNAKE_CASE:		str)				->       List[str]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Union[str, 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(
				        _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"       ,			))
				__lowerCAmelCase      :  Tuple												=       zip(config.hidden_sizes       ,			config.hidden_sizes[1:])
				for i, ((in_channels, out_channels), depth) in enumerate(zip(_SCREAMING_SNAKE_CASE       ,			config.depths[1:])):
							self.stages.append(TFRegNetStage(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			depth=_SCREAMING_SNAKE_CASE       ,			name=F"""stages.{i+1}"""))







	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = True)				->       TFBaseModelOutputWithNoAttention:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       () if output_hidden_states else None

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

							__lowerCAmelCase      :  int												=       stage_module(_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)






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




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	RegNetConfig

	def __init__(     self:		Dict       ,			_SCREAMING_SNAKE_CASE:		int       ,			**_SCREAMING_SNAKE_CASE:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       config
				__lowerCAmelCase      :  Any												=       TFRegNetEmbeddings(_SCREAMING_SNAKE_CASE       ,			name="embedder")
				__lowerCAmelCase      :  str												=       TFRegNetEncoder(_SCREAMING_SNAKE_CASE       ,			name="encoder")
				__lowerCAmelCase      :  Dict												=       tf.keras.layers.GlobalAveragePoolingaD(keepdims=_SCREAMING_SNAKE_CASE       ,			name="pooler")







	@unpack_inputs
	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor       ,			_SCREAMING_SNAKE_CASE:		Optional[bool] = None       ,			_SCREAMING_SNAKE_CASE:		Optional[bool] = None       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			)				->       TFBaseModelOutputWithPoolingAndNoAttention:

				"""simple docstring"""

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

				__lowerCAmelCase      :  Optional[int]												=       self.embedder(_SCREAMING_SNAKE_CASE       ,			training=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  int												=       self.encoder(
				    _SCREAMING_SNAKE_CASE       ,			output_hidden_states=_SCREAMING_SNAKE_CASE       ,			return_dict=_SCREAMING_SNAKE_CASE       ,			training=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Union[str, Any]												=       encoder_outputs[0]
				__lowerCAmelCase      :  Optional[int]												=       self.pooler(_SCREAMING_SNAKE_CASE)

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

				# Change the other hidden state outputs to NCHW as well
				if output_hidden_states:
							__lowerCAmelCase      :  Any												=       tuple([tf.transpose(_SCREAMING_SNAKE_CASE       ,			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=_SCREAMING_SNAKE_CASE       ,			pooler_output=_SCREAMING_SNAKE_CASE       ,			hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states       ,			)






class 			A__   (  _A							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	RegNetConfig
	SCREAMING_SNAKE_CASE          =	"regnet"
	SCREAMING_SNAKE_CASE          =	"pixel_values"

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       List[Any]:

				"""simple docstring"""

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






__snake_case							:   Optional[Any]      =    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.
'''

__snake_case							:   int      =    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.'  ,		_A  ,		)
class 			A__   (  _A							):




	'''simple docstring'''





	def __init__(     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			*_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			**_SCREAMING_SNAKE_CASE:		List[str])				->       Optional[Any]:

				"""simple docstring"""

				super().__init__(_SCREAMING_SNAKE_CASE       ,			*_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Any												=       TFRegNetMainLayer(_SCREAMING_SNAKE_CASE       ,			name="regnet")







	@unpack_inputs
	@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       ,			)
	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor       ,			_SCREAMING_SNAKE_CASE:		Optional[bool] = None       ,			_SCREAMING_SNAKE_CASE:		Optional[bool] = None       ,			_SCREAMING_SNAKE_CASE:		Dict=False       ,			)				->       Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       (
				    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
				)
				__lowerCAmelCase      :  Dict												=       return_dict if return_dict is not None else self.config.use_return_dict

				__lowerCAmelCase      :  List[str]												=       self.regnet(
				    pixel_values=_SCREAMING_SNAKE_CASE       ,			output_hidden_states=_SCREAMING_SNAKE_CASE       ,			return_dict=_SCREAMING_SNAKE_CASE       ,			training=_SCREAMING_SNAKE_CASE       ,			)
				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    '  ,		_A  ,		)
class 			A__   (  _A  ,		_A							):




	'''simple docstring'''





	def __init__(     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		RegNetConfig       ,			*_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			**_SCREAMING_SNAKE_CASE:		Union[str, Any])				->       int:

				"""simple docstring"""

				super().__init__(_SCREAMING_SNAKE_CASE       ,			*_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       config.num_labels
				__lowerCAmelCase      :  List[str]												=       TFRegNetMainLayer(_SCREAMING_SNAKE_CASE       ,			name="regnet")
				# classification head
				__lowerCAmelCase      :  Optional[int]												=       [
				    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(_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       ,			)
	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor = None       ,			_SCREAMING_SNAKE_CASE:		tf.Tensor = None       ,			_SCREAMING_SNAKE_CASE:		bool = None       ,			_SCREAMING_SNAKE_CASE:		bool = None       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=False       ,			)				->       Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       (
				    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

				__lowerCAmelCase      :  Any												=       self.regnet(
				    _SCREAMING_SNAKE_CASE       ,			output_hidden_states=_SCREAMING_SNAKE_CASE       ,			return_dict=_SCREAMING_SNAKE_CASE       ,			training=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       outputs.pooler_output if return_dict else outputs[1]

				__lowerCAmelCase      :  Any												=       self.classifier[0](_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       self.classifier[1](_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Union[str, Any]												=       None if labels is None else self.hf_compute_loss(labels=_SCREAMING_SNAKE_CASE       ,			logits=_SCREAMING_SNAKE_CASE)

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

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







"""simple docstring"""



from ...utils import is_torch_available, is_transformers_available


if is_transformers_available() and is_torch_available():
						from .pipeline_vq_diffusion import LearnedClassifierFreeSamplingEmbeddings, VQDiffusionPipeline



