





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


lowerCAmelCase :					int 							=logging.get_logger(__name__)

# General docstring
lowerCAmelCase :					Any 							='''RegNetConfig'''

# Base docstring
lowerCAmelCase :					Optional[Any] 							='''facebook/regnet-y-040'''
lowerCAmelCase :					Optional[int] 							=[1, 1_088, 7, 7]

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

lowerCAmelCase :					Optional[int] 							=[
    '''facebook/regnet-y-040''',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]
class 				a_       (    tf.keras.layers.Layer							):





     def __init__(			self		: Optional[int]     ,				lowercase		: int     ,				lowercase		: int = 3     ,				lowercase		: int = 1     ,				lowercase		: int = 1     ,				lowercase		: Optional[str] = "relu"     ,				**lowercase		: List[str]     ,				):





        """simple docstring"""




        super().__init__(**lowercase						)
        # 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_      :Optional[Any]         =			tf.keras.layers.ConvaD(
            filters=lowercase     ,				kernel_size=lowercase     ,				strides=lowercase     ,				padding="VALID"     ,				groups=lowercase     ,				use_bias=lowercase     ,				name="convolution"     ,				)
        lowercase_      :Union[str, Any]         =			tf.keras.layers.BatchNormalization(epsilon=1e-5     ,				momentum=0.9     ,				name="normalization"						)
        lowercase_      :Dict         =			ACTaFN[activation] if activation is not None else tf.identity







     def 							lowercase__				(			self		: Any     ,				lowercase		: Union[str, Any]						):





        """simple docstring"""




        lowercase_      :Tuple         =			self.convolution(self.padding(lowercase						)						)
        lowercase_      :Any         =			self.normalization(lowercase						)
        lowercase_      :Dict         =			self.activation(lowercase						)
        return hidden_state







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





     def __init__(			self		: Dict     ,				lowercase		: RegNetConfig     ,				**lowercase		: int						):





        """simple docstring"""




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







     def 							lowercase__				(			self		: Dict     ,				lowercase		: int						):





        """simple docstring"""




        lowercase_      :List[Any]         =			shape_list(lowercase						)[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_      :Dict         =			tf.transpose(lowercase     ,				perm=(0, 2, 3, 1)						)
        lowercase_      :Optional[Any]         =			self.embedder(lowercase						)
        return hidden_state







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





     def __init__(			self		: str     ,				lowercase		: int     ,				lowercase		: int = 2     ,				**lowercase		: List[str]						):





        """simple docstring"""




        super().__init__(**lowercase						)
        lowercase_      :Union[str, Any]         =			tf.keras.layers.ConvaD(
            filters=lowercase     ,				kernel_size=1     ,				strides=lowercase     ,				use_bias=lowercase     ,				name="convolution"						)
        lowercase_      :Tuple         =			tf.keras.layers.BatchNormalization(epsilon=1e-5     ,				momentum=0.9     ,				name="normalization"						)







     def 							lowercase__				(			self		: str     ,				lowercase		: tf.Tensor     ,				lowercase		: bool = False						):





        """simple docstring"""




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







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





     def __init__(			self		: Dict     ,				lowercase		: int     ,				lowercase		: int     ,				**lowercase		: Union[str, Any]						):





        """simple docstring"""




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







     def 							lowercase__				(			self		: Dict     ,				lowercase		: Dict						):





        """simple docstring"""




        lowercase_      :str         =			self.pooler(lowercase						)
        for layer_module in self.attention:
           lowercase_      :Tuple         =			layer_module(lowercase						)
        lowercase_      :str         =			hidden_state * pooled
        return hidden_state







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





     def __init__(			self		: str     ,				lowercase		: RegNetConfig     ,				lowercase		: int     ,				lowercase		: int     ,				lowercase		: int = 1     ,				**lowercase		: Any						):





        """simple docstring"""




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







     def 							lowercase__				(			self		: Any     ,				lowercase		: str						):





        """simple docstring"""




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







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





     def __init__(			self		: Dict     ,				lowercase		: RegNetConfig     ,				lowercase		: int     ,				lowercase		: int     ,				lowercase		: int = 1     ,				**lowercase		: str						):





        """simple docstring"""




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







     def 							lowercase__				(			self		: int     ,				lowercase		: List[str]						):





        """simple docstring"""




        lowercase_      :Optional[Any]         =			hidden_state
        for layer_module in self.layers:
           lowercase_      :Tuple         =			layer_module(lowercase						)
        lowercase_      :str         =			self.shortcut(lowercase						)
        hidden_state += residual
        lowercase_      :Tuple         =			self.activation(lowercase						)
        return hidden_state







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





     def __init__(			self		: Any     ,				lowercase		: RegNetConfig     ,				lowercase		: int     ,				lowercase		: int     ,				lowercase		: int = 2     ,				lowercase		: int = 2     ,				**lowercase		: Optional[Any]						):





        """simple docstring"""




        super().__init__(**lowercase						)

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







     def 							lowercase__				(			self		: Union[str, Any]     ,				lowercase		: Dict						):





        """simple docstring"""




        for layer_module in self.layers:
           lowercase_      :Any         =			layer_module(lowercase						)
        return hidden_state







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





     def __init__(			self		: Dict     ,				lowercase		: RegNetConfig     ,				**lowercase		: Optional[Any]						):





        """simple docstring"""




        super().__init__(**lowercase						)
        lowercase_      :Tuple         =			[]
        # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
        self.stages.append(
            TFRegNetStage(
                lowercase     ,				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_      :Optional[int]         =			zip(config.hidden_sizes     ,				config.hidden_sizes[1:]						)
        for i, ((in_channels, out_channels), depth) in enumerate(zip(lowercase     ,				config.depths[1:]						)						):
           self.stages.append(TFRegNetStage(lowercase     ,				lowercase     ,				lowercase     ,				depth=lowercase     ,				name=F'stages.{i+1}'						)						)







     def 							lowercase__				(			self		: List[Any]     ,				lowercase		: tf.Tensor     ,				lowercase		: bool = False     ,				lowercase		: bool = True						):





        """simple docstring"""




        lowercase_      :List[Any]         =			() if output_hidden_states else None

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

           lowercase_      :List[Any]         =			stage_module(lowercase						)

        if output_hidden_states:
           lowercase_      :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=lowercase     ,				hidden_states=lowercase						)







@keras_serializable
class 				a_       (    tf.keras.layers.Layer							):
     __A								=      RegNetConfig





     def __init__(			self		: str     ,				lowercase		: Optional[int]     ,				**lowercase		: int						):





        """simple docstring"""




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







     @unpack_inputs
     def 							lowercase__				(			self		: int     ,				lowercase		: tf.Tensor     ,				lowercase		: Optional[bool] = None     ,				lowercase		: Optional[bool] = None     ,				lowercase		: bool = False     ,				):





        """simple docstring"""




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

        lowercase_      :str         =			self.embedder(lowercase     ,				training=lowercase						)

        lowercase_      :Tuple         =			self.encoder(
            lowercase     ,				output_hidden_states=lowercase     ,				return_dict=lowercase     ,				training=lowercase						)

        lowercase_      :List[str]         =			encoder_outputs[0]
        lowercase_      :Optional[Any]         =			self.pooler(lowercase						)

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

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







class 				a_       (    _lowerCAmelCase							):
     __A								=      RegNetConfig
     __A								=      "regnet"
     __A								=      "pixel_values"





     @property
     def 							lowercase__				(			self		: Tuple						):





        """simple docstring"""




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







lowerCAmelCase :					str 							=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.
'''

lowerCAmelCase :					List[Any] 							=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 				a_       (    _lowerCAmelCase							):





     def __init__(			self		: Any     ,				lowercase		: RegNetConfig     ,				*lowercase		: Optional[int]     ,				**lowercase		: Any						):





        """simple docstring"""




        super().__init__(lowercase     ,				*lowercase     ,				**lowercase						)
        lowercase_      :Optional[Any]         =			TFRegNetMainLayer(lowercase     ,				name="regnet"						)







     @unpack_inputs
     @add_start_docstrings_to_model_forward(lowercase						)
     @add_code_sample_docstrings(
         checkpoint=_CHECKPOINT_FOR_DOC     ,				output_type=lowercase     ,				config_class=_CONFIG_FOR_DOC     ,				modality="vision"     ,				expected_output=_EXPECTED_OUTPUT_SHAPE     ,				)
     def 							lowercase__				(			self		: Union[str, Any]     ,				lowercase		: tf.Tensor     ,				lowercase		: Optional[bool] = None     ,				lowercase		: Optional[bool] = None     ,				lowercase		: Union[str, Any]=False     ,				):





        """simple docstring"""




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

        lowercase_      :Dict         =			self.regnet(
            pixel_values=lowercase     ,				output_hidden_states=lowercase     ,				return_dict=lowercase     ,				training=lowercase     ,				)
        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 				a_       (    _lowerCAmelCase     ,						_lowerCAmelCase							):





     def __init__(			self		: Optional[Any]     ,				lowercase		: RegNetConfig     ,				*lowercase		: List[Any]     ,				**lowercase		: Optional[Any]						):





        """simple docstring"""




        super().__init__(lowercase     ,				*lowercase     ,				**lowercase						)
        lowercase_      :List[Any]         =			config.num_labels
        lowercase_      :Any         =			TFRegNetMainLayer(lowercase     ,				name="regnet"						)
        # classification head
        lowercase_      :Optional[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(lowercase						)
     @add_code_sample_docstrings(
         checkpoint=_IMAGE_CLASS_CHECKPOINT     ,				output_type=lowercase     ,				config_class=_CONFIG_FOR_DOC     ,				expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT     ,				)
     def 							lowercase__				(			self		: Optional[int]     ,				lowercase		: tf.Tensor = None     ,				lowercase		: tf.Tensor = None     ,				lowercase		: bool = None     ,				lowercase		: bool = None     ,				lowercase		: List[str]=False     ,				):





        """simple docstring"""




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

        lowercase_      :Any         =			self.regnet(
            lowercase     ,				output_hidden_states=lowercase     ,				return_dict=lowercase     ,				training=lowercase						)

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

        lowercase_      :Union[str, Any]         =			self.classifier[0](lowercase						)
        lowercase_      :Optional[Any]         =			self.classifier[1](lowercase						)

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

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

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









'''simple docstring'''


import copy
from typing import Any, Dict, List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, spectrogram, window_function
from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import TensorType, logging


lowerCAmelCase :					Optional[int] 							=logging.get_logger(__name__)
class 				a_       (    _lowerCAmelCase							):
     __A								=      ["input_features"]





     def __init__(			self		: Any     ,				lowercase		: Tuple=80     ,				lowercase		: Optional[int]=16_000     ,				lowercase		: Optional[Any]=160     ,				lowercase		: Optional[int]=30     ,				lowercase		: List[Any]=400     ,				lowercase		: Dict=0.0     ,				lowercase		: Tuple=False     ,				**lowercase		: Optional[int]     ,				):





        """simple docstring"""




        super().__init__(
            feature_size=lowercase     ,				sampling_rate=lowercase     ,				padding_value=lowercase     ,				return_attention_mask=lowercase     ,				**lowercase     ,				)
        lowercase_      :Optional[int]         =			n_fft
        lowercase_      :List[Any]         =			hop_length
        lowercase_      :Tuple         =			chunk_length
        lowercase_      :List[str]         =			chunk_length * sampling_rate
        lowercase_      :Optional[Any]         =			self.n_samples // hop_length
        lowercase_      :Any         =			sampling_rate
        lowercase_      :List[Any]         =			mel_filter_bank(
            num_frequency_bins=1 + n_fft // 2     ,				num_mel_filters=lowercase     ,				min_frequency=0.0     ,				max_frequency=80_00.0     ,				sampling_rate=lowercase     ,				norm="slaney"     ,				mel_scale="slaney"     ,				)





     def 							lowercase__				(			self		: str     ,				lowercase		: np.array						):





        """simple docstring"""




        lowercase_      :Any         =			spectrogram(
            lowercase     ,				window_function(self.n_fft     ,				"hann"						)     ,				frame_length=self.n_fft     ,				hop_length=self.hop_length     ,				power=2.0     ,				mel_filters=self.mel_filters     ,				log_mel="log10"     ,				)
        lowercase_      :Any         =			log_spec[:, :-1]
        lowercase_      :List[Any]         =			np.maximum(lowercase     ,				log_spec.max() - 8.0						)
        lowercase_      :Dict         =			(log_spec + 4.0) / 4.0
        return log_spec





     @staticmethod
     # Copied from transformers.models.wav2vec2.feature_extraction_wav2vec2.Wav2Vec2FeatureExtractor.zero_mean_unit_var_norm
     def 							lowercase__				(			lowercase		: List[np.ndarray]     ,				lowercase		: List[np.ndarray]     ,				lowercase		: float = 0.0						):





        """simple docstring"""




        if attention_mask is not None:
           lowercase_      :Optional[int]         =			np.array(lowercase     ,				np.intaa						)
           lowercase_      :Any         =			[]

           for vector, length in zip(lowercase     ,				attention_mask.sum(-1						)						):
              lowercase_      :Dict         =			(vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1e-7						)
              if length < normed_slice.shape[0]:
                 lowercase_      :List[Any]         =			padding_value

              normed_input_values.append(lowercase						)
        else:
           lowercase_      :List[Any]         =			[(x - x.mean()) / np.sqrt(x.var() + 1e-7						) for x in input_values]

        return normed_input_values





     def __call__(			self		: Tuple     ,				lowercase		: Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]     ,				lowercase		: bool = True     ,				lowercase		: Optional[int] = None     ,				lowercase		: Optional[Union[str, TensorType]] = None     ,				lowercase		: Optional[bool] = None     ,				lowercase		: Optional[str] = "max_length"     ,				lowercase		: Optional[int] = None     ,				lowercase		: Optional[int] = None     ,				lowercase		: Optional[bool] = None     ,				**lowercase		: Union[str, Any]     ,				):





        """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.__class__.__name__} was trained using a'
                  F' sampling rate of {self.sampling_rate}. Please make sure that the provided `raw_speech` input'
                  F' was sampled with {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_      :List[str]         =			isinstance(lowercase     ,				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_      :Optional[Any]         =			is_batched_numpy or (
            isinstance(lowercase     ,				(list, tuple)						) and (isinstance(raw_speech[0]     ,				(np.ndarray, tuple, list)						))
        )

        if is_batched:
           lowercase_      :Any         =			[np.asarray([speech]     ,				dtype=np.floataa						).T for speech in raw_speech]
        elif not is_batched and not isinstance(lowercase     ,				np.ndarray						):
           lowercase_      :List[Any]         =			np.asarray(lowercase     ,				dtype=np.floataa						)
        elif isinstance(lowercase     ,				np.ndarray						) and raw_speech.dtype is np.dtype(np.floataa						):
           lowercase_      :Union[str, Any]         =			raw_speech.astype(np.floataa						)

        # always return batch
        if not is_batched:
           lowercase_      :Optional[int]         =			[np.asarray([raw_speech]						).T]

        lowercase_      :int         =			BatchFeature({"input_features": raw_speech}						)

        # convert into correct format for padding

        lowercase_      :Tuple         =			self.pad(
            lowercase     ,				padding=lowercase     ,				max_length=max_length if max_length else self.n_samples     ,				truncation=lowercase     ,				pad_to_multiple_of=lowercase     ,				return_attention_mask=return_attention_mask or do_normalize     ,				)

        # zero-mean and unit-variance normalization
        if do_normalize:
           lowercase_      :Union[str, Any]         =			self.zero_mean_unit_var_norm(
               padded_inputs["input_features"]     ,				attention_mask=padded_inputs["attention_mask"]     ,				padding_value=self.padding_value     ,				)
           lowercase_      :List[Any]         =			np.stack(padded_inputs["input_features"]     ,				axis=0						)

        # make sure list is in array format
        lowercase_      :Union[str, Any]         =			padded_inputs.get("input_features"						).transpose(2     ,				0     ,				1						)

        lowercase_      :List[str]         =			[self._np_extract_fbank_features(lowercase						) for waveform in input_features[0]]

        if isinstance(input_features[0]     ,				lowercase						):
           lowercase_      :Tuple         =			[np.asarray(lowercase     ,				dtype=np.floataa						) for feature in input_features]
        else:
           lowercase_      :Union[str, Any]         =			input_features

        if return_attention_mask:
           # rescale from sample (48000) to feature (3000)
           lowercase_      :Dict         =			padded_inputs["attention_mask"][:, :: self.hop_length]

        if return_tensors is not None:
           lowercase_      :Tuple         =			padded_inputs.convert_to_tensors(lowercase						)

        return padded_inputs







     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			copy.deepcopy(self.__dict__						)
        lowercase_      :List[str]         =			self.__class__.__name__
        if "mel_filters" in output:
           del output["mel_filters"]
        return output


