


from typing import List, Optional, Union

import numpy as np
import torch
import torchaudio.compliance.kaldi as ta_kaldi

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


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






class _lowerCamelCase(		_a     ):
       lowercase_				:			int									=    ["""input_features""", """attention_mask"""]
       def __init__(      self,   lowerCamelCase=80,   lowerCamelCase=1_60_00,   lowerCamelCase=80,   lowerCamelCase=0.0,   lowerCamelCase=True,   lowerCamelCase=True,   lowerCamelCase=True,   **lowerCamelCase,   ) ->     Dict:




           """simple docstring"""

           super().__init__(feature_size=lowerCamelCase,   sampling_rate=lowerCamelCase,   padding_value=lowerCamelCase,   **lowerCamelCase)
           _lowercase :							Dict   	=	num_mel_bins
           _lowercase :							int   	=	do_ceptral_normalize
           _lowercase :							Tuple   	=	normalize_means
           _lowercase :							List[Any]   	=	normalize_vars
           _lowercase :							str   	=	True
       def     UpperCamelCase  (      self,   lowerCamelCase,   ) ->     np.ndarray:




           """simple docstring"""

           _lowercase :							List[Any]   	=	waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
           _lowercase :							Any   	=	torch.from_numpy(lowerCamelCase).unsqueeze(0)
           _lowercase :							Dict   	=	ta_kaldi.fbank(lowerCamelCase,   num_mel_bins=self.num_mel_bins,   sample_frequency=self.sampling_rate)
           return features.numpy()
       @staticmethod
       def     UpperCamelCase  (      lowerCamelCase,   lowerCamelCase,   lowerCamelCase = True,   lowerCamelCase = True,   lowerCamelCase = 0.0,   ) ->     np.ndarray:




           """simple docstring"""

           if normalize_means:
               _lowercase :							Union[str, Any]   	=	x[:input_length].mean(axis=0)
               _lowercase :							List[str]   	=	np.subtract(lowerCamelCase,   lowerCamelCase)
           if normalize_vars:
               _lowercase :							int   	=	x[:input_length].std(axis=0)
               _lowercase :							int   	=	np.divide(lowerCamelCase,   lowerCamelCase)

           if input_length < x.shape[0]:
               _lowercase :							Union[str, Any]   	=	padding_value

           # make sure array is in float32
           _lowercase :							List[str]   	=	x.astype(np.floataa)

           return x
       def     UpperCamelCase  (      self,   lowerCamelCase,   lowerCamelCase = None) ->     List[np.ndarray]:




           """simple docstring"""

           _lowercase :							int   	=	attention_mask.sum(-1) if attention_mask is not None else [x.shape[0] for x in input_features]
           return [
               self.utterance_cmvn(lowerCamelCase,   lowerCamelCase,   self.normalize_means,   self.normalize_vars,   self.padding_value)
               for x, n in zip(lowerCamelCase,   lowerCamelCase)
           ]




       def __call__(      self,   lowerCamelCase,   lowerCamelCase = False,   lowerCamelCase = None,   lowerCamelCase = False,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase = None,   **lowerCamelCase,   ) ->     BatchFeature:




           """simple docstring"""

           if sampling_rate is not None:
               if sampling_rate != self.sampling_rate:
                   raise ValueError(
                       F'''The model corresponding to this feature extractor: {self} was trained using a sampling rate of'''
                       F''' {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with'''
                       F''' {self.sampling_rate} and not {sampling_rate}.''')
           else:
               logger.warning(
                   'It is strongly recommended to pass the `sampling_rate` argument to this function. '
                   'Failing to do so can result in silent errors that might be hard to debug.')

           _lowercase :							Tuple   	=	isinstance(lowerCamelCase,   np.ndarray) and len(raw_speech.shape) > 1
           if is_batched_numpy and len(raw_speech.shape) > 2:
               raise ValueError(F'''Only mono-channel audio is supported for input to {self}''')
           _lowercase :							List[Any]   	=	is_batched_numpy or (
               isinstance(lowerCamelCase,   (list, tuple)) and (isinstance(raw_speech[0],   (np.ndarray, tuple, list)))
           )

           if is_batched:
               _lowercase :							int   	=	[np.asarray(lowerCamelCase,   dtype=np.floataa) for speech in raw_speech]
           elif not is_batched and not isinstance(lowerCamelCase,   np.ndarray):
               _lowercase :							List[str]   	=	np.asarray(lowerCamelCase,   dtype=np.floataa)
           elif isinstance(lowerCamelCase,   np.ndarray) and raw_speech.dtype is np.dtype(np.floataa):
               _lowercase :							Tuple   	=	raw_speech.astype(np.floataa)

           # always return batch
           if not is_batched:
               _lowercase :							List[str]   	=	[raw_speech]

           # extract fbank features
           _lowercase :							List[Any]   	=	[self._extract_fbank_features(lowerCamelCase) for waveform in raw_speech]

           # convert into correct format for padding
           _lowercase :							Tuple   	=	BatchFeature({'input_features': features})

           _lowercase :							Optional[Any]   	=	self.pad(
               lowerCamelCase,   padding=lowerCamelCase,   max_length=lowerCamelCase,   truncation=lowerCamelCase,   pad_to_multiple_of=lowerCamelCase,   return_attention_mask=lowerCamelCase,   **lowerCamelCase,   )

           # make sure list is in array format
           _lowercase :							List[str]   	=	padded_inputs.get('input_features')
           if isinstance(input_features[0],   lowerCamelCase):
               _lowercase :							Any   	=	[np.asarray(lowerCamelCase,   dtype=np.floataa) for feature in input_features]

           _lowercase :							List[Any]   	=	padded_inputs.get('attention_mask')
           if attention_mask is not None:
               _lowercase :							Optional[int]   	=	[np.asarray(lowerCamelCase,   dtype=np.intaa) for array in attention_mask]

           # Utterance-level cepstral mean and variance normalization
           if self.do_ceptral_normalize:
               _lowercase :							Optional[int]   	=	(
                   np.array(lowerCamelCase,   dtype=np.intaa)
                   if self._get_padding_strategies(lowerCamelCase,   max_length=lowerCamelCase) is not PaddingStrategy.DO_NOT_PAD
                   else None
               )
               _lowercase :							Tuple   	=	self.normalize(
                   padded_inputs['input_features'],   attention_mask=lowerCamelCase)

           if return_tensors is not None:
               _lowercase :							List[str]   	=	padded_inputs.convert_to_tensors(lowerCamelCase)

           return padded_inputs






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 :   Dict							      =				logging.get_logger(__name__)

# General docstring
SCREAMING_SNAKE_CASE :   str							      =				"RegNetConfig"

# Base docstring
SCREAMING_SNAKE_CASE :   Tuple							      =				"facebook/regnet-y-040"
SCREAMING_SNAKE_CASE :   Dict							      =				[1, 1088, 7, 7]

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

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






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase = 3,   lowerCamelCase = 1,   lowerCamelCase = 1,   lowerCamelCase = "relu",   **lowerCamelCase,   ) ->     int:




           """simple docstring"""

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




       def     UpperCamelCase  (      self,   lowerCamelCase) ->     List[str]:




           """simple docstring"""

           _lowercase :							str   	=	self.convolution(self.padding(lowerCamelCase))
           _lowercase :							int   	=	self.normalization(lowerCamelCase)
           _lowercase :							Optional[Any]   	=	self.activation(lowerCamelCase)
           return hidden_state






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   **lowerCamelCase) ->     Optional[int]:




           """simple docstring"""

           super().__init__(**lowerCamelCase)
           _lowercase :							Tuple   	=	config.num_channels
           _lowercase :							Tuple   	=	TFRegNetConvLayer(
               out_channels=config.embedding_size,   kernel_size=3,   stride=2,   activation=config.hidden_act,   name='embedder',   )




       def     UpperCamelCase  (      self,   lowerCamelCase) ->     Union[str, Any]:




           """simple docstring"""

           _lowercase :							Dict   	=	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)
           _lowercase :							Optional[Any]   	=	tf.transpose(lowerCamelCase,   perm=(0, 2, 3, 1))
           _lowercase :							int   	=	self.embedder(lowerCamelCase)
           return hidden_state






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase = 2,   **lowerCamelCase) ->     Optional[Any]:




           """simple docstring"""

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




       def     UpperCamelCase  (      self,   lowerCamelCase,   lowerCamelCase = False) ->     tf.Tensor:




           """simple docstring"""

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






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase,   **lowerCamelCase) ->     Any:




           """simple docstring"""

           super().__init__(**lowerCamelCase)
           _lowercase :							str   	=	tf.keras.layers.GlobalAveragePoolingaD(keepdims=lowerCamelCase,   name='pooler')
           _lowercase :							int   	=	[
               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     UpperCamelCase  (      self,   lowerCamelCase) ->     str:




           """simple docstring"""

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






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase = 1,   **lowerCamelCase) ->     Optional[int]:




           """simple docstring"""

           super().__init__(**lowerCamelCase)
           _lowercase :							Optional[Any]   	=	in_channels != out_channels or stride != 1
           _lowercase :							List[Any]   	=	max(1,   out_channels // config.groups_width)
           _lowercase :							List[str]   	=	(
               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.
           _lowercase :							str   	=	[
               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'),
           ]
           _lowercase :							Tuple   	=	ACTaFN[config.hidden_act]




       def     UpperCamelCase  (      self,   lowerCamelCase) ->     List[str]:




           """simple docstring"""

           _lowercase :							str   	=	hidden_state
           for layer_module in self.layers:
               _lowercase :							List[Any]   	=	layer_module(lowerCamelCase)
           _lowercase :							Dict   	=	self.shortcut(lowerCamelCase)
           hidden_state += residual
           _lowercase :							Tuple   	=	self.activation(lowerCamelCase)
           return hidden_state






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase = 1,   **lowerCamelCase) ->     List[str]:




           """simple docstring"""

           super().__init__(**lowerCamelCase)
           _lowercase :							Dict   	=	in_channels != out_channels or stride != 1
           _lowercase :							str   	=	max(1,   out_channels // config.groups_width)
           _lowercase :							Tuple   	=	(
               TFRegNetShortCut(lowerCamelCase,   stride=lowerCamelCase,   name='shortcut')
               if should_apply_shortcut
               else tf.keras.layers.Activation('linear',   name='shortcut')
           )
           _lowercase :							Union[str, 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'),
               TFRegNetSELayer(lowerCamelCase,   reduced_channels=int(round(in_channels / 4)),   name='layer.2'),
               TFRegNetConvLayer(lowerCamelCase,   kernel_size=1,   activation=lowerCamelCase,   name='layer.3'),
           ]
           _lowercase :							Any   	=	ACTaFN[config.hidden_act]




       def     UpperCamelCase  (      self,   lowerCamelCase) ->     List[str]:




           """simple docstring"""

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






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase,   lowerCamelCase = 2,   lowerCamelCase = 2,   **lowerCamelCase) ->     Tuple:




           """simple docstring"""

           super().__init__(**lowerCamelCase)

           _lowercase :							Any   	=	TFRegNetXLayer if config.layer_type == 'x' else TFRegNetYLayer
           _lowercase :							Any   	=	[
               # 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     UpperCamelCase  (      self,   lowerCamelCase) ->     Tuple:




           """simple docstring"""

           for layer_module in self.layers:
               _lowercase :							Tuple   	=	layer_module(lowerCamelCase)
           return hidden_state






class _lowerCamelCase(		tf.keras.layers.Layer     ):
       def __init__(      self,   lowerCamelCase,   **lowerCamelCase) ->     Any:




           """simple docstring"""

           super().__init__(**lowerCamelCase)
           _lowercase :							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',   ))
           _lowercase :							str   	=	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     UpperCamelCase  (      self,   lowerCamelCase,   lowerCamelCase = False,   lowerCamelCase = True) ->     TFBaseModelOutputWithNoAttention:




           """simple docstring"""

           _lowercase :							int   	=	() if output_hidden_states else None

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

               _lowercase :							Tuple   	=	stage_module(lowerCamelCase)

           if output_hidden_states:
               _lowercase :							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=lowerCamelCase,   hidden_states=lowerCamelCase)






@keras_serializable
class _lowerCamelCase(		tf.keras.layers.Layer     ):
       lowercase_				:			Dict									=    RegNetConfig
       def __init__(      self,   lowerCamelCase,   **lowerCamelCase) ->     str:




           """simple docstring"""

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




       @unpack_inputs
       def     UpperCamelCase  (      self,   lowerCamelCase,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase = False,   ) ->     TFBaseModelOutputWithPoolingAndNoAttention:




           """simple docstring"""

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

           _lowercase :							Dict   	=	self.embedder(lowerCamelCase,   training=lowerCamelCase)

           _lowercase :							int   	=	self.encoder(
               lowerCamelCase,   output_hidden_states=lowerCamelCase,   return_dict=lowerCamelCase,   training=lowerCamelCase)

           _lowercase :							Optional[int]   	=	encoder_outputs[0]
           _lowercase :							List[Any]   	=	self.pooler(lowerCamelCase)

           # Change to NCHW output format have uniformity in the modules
           _lowercase :							Tuple   	=	tf.transpose(lowerCamelCase,   perm=(0, 3, 1, 2))
           _lowercase :							Tuple   	=	tf.transpose(lowerCamelCase,   perm=(0, 3, 1, 2))

           # Change the other hidden state outputs to NCHW as well
           if output_hidden_states:
               _lowercase :							Union[str, Any]   	=	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 _lowerCamelCase(		_a     ):
       lowercase_				:			List[str]									=    RegNetConfig
       lowercase_				:			Optional[int]									=    """regnet"""
       lowercase_				:			int									=    """pixel_values"""
       @property
       def     UpperCamelCase  (      self) ->     int:




           """simple docstring"""

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


SCREAMING_SNAKE_CASE :   Union[str, Any]							      =				r"\n    Parameters:\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        config ([`RegNetConfig`]): 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"

SCREAMING_SNAKE_CASE :   Tuple							      =				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            [`ConveNextImageProcessor.__call__`] for details.\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"






@add_start_docstrings(
    """The bare RegNet model outputting raw features without any specific head on top.""",				_a,				)
class _lowerCamelCase(		_a     ):
       def __init__(      self,   lowerCamelCase,   *lowerCamelCase,   **lowerCamelCase) ->     Tuple:




           """simple docstring"""

           super().__init__(lowerCamelCase,   *lowerCamelCase,   **lowerCamelCase)
           _lowercase :							List[Any]   	=	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     UpperCamelCase  (      self,   lowerCamelCase,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase=False,   ) ->     Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:




           """simple docstring"""

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

           _lowercase :							str   	=	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(
    """
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """,				_a,				)
class _lowerCamelCase(		_a,				_a     ):
       def __init__(      self,   lowerCamelCase,   *lowerCamelCase,   **lowerCamelCase) ->     Any:




           """simple docstring"""

           super().__init__(lowerCamelCase,   *lowerCamelCase,   **lowerCamelCase)
           _lowercase :							Dict   	=	config.num_labels
           _lowercase :							Optional[int]   	=	TFRegNetMainLayer(lowerCamelCase,   name='regnet')
           # classification head
           _lowercase :							Tuple   	=	[
               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     UpperCamelCase  (      self,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase = None,   lowerCamelCase=False,   ) ->     Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:




           """simple docstring"""

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

           _lowercase :							Dict   	=	self.regnet(
               lowerCamelCase,   output_hidden_states=lowerCamelCase,   return_dict=lowerCamelCase,   training=lowerCamelCase)

           _lowercase :							List[str]   	=	outputs.pooler_output if return_dict else outputs[1]

           _lowercase :							Union[str, Any]   	=	self.classifier[0](lowerCamelCase)
           _lowercase :							List[Any]   	=	self.classifier[1](lowerCamelCase)

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

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

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


