




'''simple docstring'''



from typing import List, Optional, Union

import numpy as np

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


lowerCamelCase_			=						logging.get_logger(__name__)




class 		lowercase_   (			A       ):


   """simple docstring"""

   lowerCamelCase_      =						['''input_features''', '''attention_mask''']



   def __init__(   self :     Tuple  ,				__lowerCamelCase :     List[str]=8_0  ,				__lowerCamelCase :     Dict=1_6_0_0_0  ,				__lowerCamelCase :     int=0.0  ,				__lowerCamelCase :     int=1_0  ,				__lowerCamelCase :     Optional[Any]=2_5  ,				__lowerCamelCase :     Tuple="hamming_window"  ,				__lowerCamelCase :     Dict=3_2_7_6_8.0  ,				__lowerCamelCase :     List[Any]=0.9_7  ,				__lowerCamelCase :     Dict=1.0  ,				__lowerCamelCase :     Optional[Any]=True  ,				__lowerCamelCase :     int=True  ,				__lowerCamelCase :     Optional[int]=False  ,				**__lowerCamelCase :     str  ,				):

      """simple docstring"""
      super().__init__(feature_size=__lowerCamelCase  ,				sampling_rate=__lowerCamelCase  ,				padding_value=__lowerCamelCase  ,				**__lowerCamelCase   )

      _SCREAMING_SNAKE_CASE	=				feature_size
      _SCREAMING_SNAKE_CASE	=				sampling_rate
      _SCREAMING_SNAKE_CASE	=				padding_value
      _SCREAMING_SNAKE_CASE	=				hop_length
      _SCREAMING_SNAKE_CASE	=				win_length
      _SCREAMING_SNAKE_CASE	=				frame_signal_scale
      _SCREAMING_SNAKE_CASE	=				preemphasis_coeff
      _SCREAMING_SNAKE_CASE	=				mel_floor
      _SCREAMING_SNAKE_CASE	=				normalize_means
      _SCREAMING_SNAKE_CASE	=				normalize_vars
      _SCREAMING_SNAKE_CASE	=				win_function
      _SCREAMING_SNAKE_CASE	=				return_attention_mask

      _SCREAMING_SNAKE_CASE	=				win_length * sampling_rate // 1_0_0_0
      _SCREAMING_SNAKE_CASE	=				hop_length * sampling_rate // 1_0_0_0

      _SCREAMING_SNAKE_CASE	=				optimal_fft_length(self.sample_size   )
      _SCREAMING_SNAKE_CASE	=				(self.n_fft // 2) + 1



   def 							lowerCAmelCase_      (   self :     Optional[Any]  ,				__lowerCamelCase :     np.array   ):

      """simple docstring"""
      if self.win_function == "hamming_window":
         _SCREAMING_SNAKE_CASE	=				window_function(window_length=self.sample_size  ,				name=self.win_function  ,				periodic=__lowerCamelCase   )
      else:
         _SCREAMING_SNAKE_CASE	=				window_function(window_length=self.sample_size  ,				name=self.win_function   )

      _SCREAMING_SNAKE_CASE	=				mel_filter_bank(
          num_frequency_bins=self.n_freqs  ,				num_mel_filters=self.feature_size  ,				min_frequency=0.0  ,				max_frequency=self.sampling_rate / 2.0  ,				sampling_rate=self.sampling_rate  ,				)

      _SCREAMING_SNAKE_CASE	=				spectrogram(
          one_waveform * self.frame_signal_scale  ,				window=__lowerCamelCase  ,				frame_length=self.sample_size  ,				hop_length=self.sample_stride  ,				fft_length=self.n_fft  ,				center=__lowerCamelCase  ,				preemphasis=self.preemphasis_coeff  ,				mel_filters=__lowerCamelCase  ,				mel_floor=self.mel_floor  ,				log_mel="log"  ,				)
      return msfc_features.T



   def 							lowerCAmelCase_      (   self :     List[str]  ,				__lowerCamelCase :     Dict  ,				__lowerCamelCase :     Optional[int]  ,				__lowerCamelCase :     Dict   ):

      """simple docstring"""
      # make sure we normalize float32 arrays
      if self.normalize_means:
         _SCREAMING_SNAKE_CASE	=				x[:input_length].mean(axis=0   )
         _SCREAMING_SNAKE_CASE	=				np.subtract(__lowerCamelCase  ,				__lowerCamelCase   )
      if self.normalize_vars:
         _SCREAMING_SNAKE_CASE	=				x[:input_length].std(axis=0   )
         _SCREAMING_SNAKE_CASE	=				np.divide(__lowerCamelCase  ,				__lowerCamelCase   )

      if input_length < x.shape[0]:
         _SCREAMING_SNAKE_CASE	=				padding_value

      # make sure array is in float32
      _SCREAMING_SNAKE_CASE	=				x.astype(np.floataa   )

      return x



   def 							lowerCAmelCase_      (   self :     List[str]  ,				__lowerCamelCase :     List[np.ndarray]  ,				__lowerCamelCase :     Optional[np.ndarray] = None   ):

      """simple docstring"""
      _SCREAMING_SNAKE_CASE	=				attention_mask.sum(-1   ) if attention_mask is not None else [x.shape[0] for x in input_features]
      return [self._normalize_one(__lowerCamelCase  ,				__lowerCamelCase  ,				self.padding_value   ) for x, n in zip(__lowerCamelCase  ,				__lowerCamelCase   )]



   def __call__(   self :     Optional[int]  ,				__lowerCamelCase :     Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]  ,				__lowerCamelCase :     Union[bool, str, PaddingStrategy] = False  ,				__lowerCamelCase :     Optional[int] = None  ,				__lowerCamelCase :     bool = False  ,				__lowerCamelCase :     Optional[int] = None  ,				__lowerCamelCase :     Optional[bool] = None  ,				__lowerCamelCase :     Optional[Union[str, TensorType]] = None  ,				__lowerCamelCase :     Optional[int] = None  ,				**__lowerCamelCase :     int  ,				):

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

      _SCREAMING_SNAKE_CASE	=				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}"""   )
      _SCREAMING_SNAKE_CASE	=				is_batched_numpy or (
          isinstance(__lowerCamelCase  ,				(list, tuple)   ) and (isinstance(raw_speech[0]  ,				(np.ndarray, tuple, list)   ))
      )

      if is_batched:
         _SCREAMING_SNAKE_CASE	=				[np.asarray(__lowerCamelCase  ,				dtype=np.floataa   ) for speech in raw_speech]
      elif not is_batched and not isinstance(__lowerCamelCase  ,				np.ndarray   ):
         _SCREAMING_SNAKE_CASE	=				np.asarray(__lowerCamelCase  ,				dtype=np.floataa   )
      elif isinstance(__lowerCamelCase  ,				np.ndarray   ) and raw_speech.dtype is np.dtype(np.floataa   ):
         _SCREAMING_SNAKE_CASE	=				raw_speech.astype(np.floataa   )

      # always return batch
      if not is_batched:
         _SCREAMING_SNAKE_CASE	=				[raw_speech]

      # extract fbank features
      _SCREAMING_SNAKE_CASE	=				[self._extract_mfsc_features(__lowerCamelCase   ) for one_waveform in raw_speech]

      # convert into correct format for padding
      _SCREAMING_SNAKE_CASE	=				BatchFeature({"input_features": features}   )

      _SCREAMING_SNAKE_CASE	=				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
      _SCREAMING_SNAKE_CASE	=				padded_inputs.get("input_features"   )
      if isinstance(input_features[0]  ,				__lowerCamelCase   ):
         _SCREAMING_SNAKE_CASE	=				[np.asarray(__lowerCamelCase  ,				dtype=np.floataa   ) for feature in input_features]

      _SCREAMING_SNAKE_CASE	=				padded_inputs.get("attention_mask"   )
      if attention_mask is not None:
         _SCREAMING_SNAKE_CASE	=				[np.asarray(__lowerCamelCase  ,				dtype=np.intaa   ) for array in attention_mask]

      if self.normalize_means or self.normalize_vars:
         _SCREAMING_SNAKE_CASE	=				(
             np.array(__lowerCamelCase  ,				dtype=np.intaa   )
             if self._get_padding_strategies(__lowerCamelCase  ,				max_length=__lowerCamelCase   ) is not PaddingStrategy.DO_NOT_PAD
             and padding
             else None
         )
         _SCREAMING_SNAKE_CASE	=				self.normalize(
             padded_inputs["input_features"]  ,				attention_mask=__lowerCamelCase   )

      if return_tensors is not None:
         _SCREAMING_SNAKE_CASE	=				padded_inputs.convert_to_tensors(__lowerCamelCase   )

      return padded_inputs







'''simple docstring'''



from collections import OrderedDict
from typing import List, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase_			=						logging.get_logger(__name__)

lowerCamelCase_			=						{
    'google/efficientnet-b7': 'https://huggingface.co/google/efficientnet-b7/resolve/main/config.json',
}







class 		lowercase_   (			A       ):


   """simple docstring"""

   lowerCamelCase_      =						'''efficientnet'''



   def __init__(   self :     Optional[Any]  ,				__lowerCamelCase :     int = 3  ,				__lowerCamelCase :     int = 6_0_0  ,				__lowerCamelCase :     float = 2.0  ,				__lowerCamelCase :     float = 3.1  ,				__lowerCamelCase :     int = 8  ,				__lowerCamelCase :     List[int] = [3, 3, 5, 3, 5, 5, 3]  ,				__lowerCamelCase :     List[int] = [3_2, 1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2]  ,				__lowerCamelCase :     List[int] = [1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2, 3_2_0]  ,				__lowerCamelCase :     List[int] = []  ,				__lowerCamelCase :     List[int] = [1, 2, 2, 2, 1, 2, 1]  ,				__lowerCamelCase :     List[int] = [1, 2, 2, 3, 3, 4, 1]  ,				__lowerCamelCase :     List[int] = [1, 6, 6, 6, 6, 6, 6]  ,				__lowerCamelCase :     float = 0.2_5  ,				__lowerCamelCase :     str = "swish"  ,				__lowerCamelCase :     int = 2_5_6_0  ,				__lowerCamelCase :     str = "mean"  ,				__lowerCamelCase :     float = 0.0_2  ,				__lowerCamelCase :     float = 0.0_0_1  ,				__lowerCamelCase :     float = 0.9_9  ,				__lowerCamelCase :     float = 0.5  ,				__lowerCamelCase :     float = 0.2  ,				**__lowerCamelCase :     Tuple  ,				):

      """simple docstring"""
      super().__init__(**__lowerCamelCase   )

      _SCREAMING_SNAKE_CASE	=				num_channels
      _SCREAMING_SNAKE_CASE	=				image_size
      _SCREAMING_SNAKE_CASE	=				width_coefficient
      _SCREAMING_SNAKE_CASE	=				depth_coefficient
      _SCREAMING_SNAKE_CASE	=				depth_divisor
      _SCREAMING_SNAKE_CASE	=				kernel_sizes
      _SCREAMING_SNAKE_CASE	=				in_channels
      _SCREAMING_SNAKE_CASE	=				out_channels
      _SCREAMING_SNAKE_CASE	=				depthwise_padding
      _SCREAMING_SNAKE_CASE	=				strides
      _SCREAMING_SNAKE_CASE	=				num_block_repeats
      _SCREAMING_SNAKE_CASE	=				expand_ratios
      _SCREAMING_SNAKE_CASE	=				squeeze_expansion_ratio
      _SCREAMING_SNAKE_CASE	=				hidden_act
      _SCREAMING_SNAKE_CASE	=				hidden_dim
      _SCREAMING_SNAKE_CASE	=				pooling_type
      _SCREAMING_SNAKE_CASE	=				initializer_range
      _SCREAMING_SNAKE_CASE	=				batch_norm_eps
      _SCREAMING_SNAKE_CASE	=				batch_norm_momentum
      _SCREAMING_SNAKE_CASE	=				dropout_rate
      _SCREAMING_SNAKE_CASE	=				drop_connect_rate
      _SCREAMING_SNAKE_CASE	=				sum(__lowerCamelCase   ) * 4







class 		lowercase_   (			A       ):


   """simple docstring"""

   lowerCamelCase_      =						version.parse('''1.11'''       )



   @property
   def 							lowerCAmelCase_      (   self :     Optional[Any]   ):

      """simple docstring"""
      return OrderedDict(
          [
              ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
          ]   )



   @property
   def 							lowerCAmelCase_      (   self :     List[Any]   ):

      """simple docstring"""
      return 1e-5

