


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


snake_case							:       Tuple     			=      logging.get_logger(__name__)







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    List[Any]          =			['''input_features''', '''attention_mask''']
					def __init__(      self   :int			,__snake_case   :Tuple=80			,__snake_case   :Tuple=1_60_00			,__snake_case   :str=0.0			,__snake_case   :Tuple=10			,__snake_case   :Dict=25			,__snake_case   :Any="hamming_window"			,__snake_case   :int=3_27_68.0			,__snake_case   :List[str]=0.97			,__snake_case   :int=1.0			,__snake_case   :int=True			,__snake_case   :Optional[Any]=True			,__snake_case   :List[str]=False			,**__snake_case   :List[str]			,)					->    Tuple:
												super().__init__(feature_size=__snake_case			,sampling_rate=__snake_case			,padding_value=__snake_case			,**__snake_case      )

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

												a__             =     win_length * sampling_rate // 10_00
												a__             =     hop_length * sampling_rate // 10_00

												a__             =     optimal_fft_length(self.sample_size      )
												a__             =     (self.n_fft // 2) + 1
					def  lowerCamelCase__(      self   :int			,__snake_case   :np.array      )					->    np.ndarray:
												if self.win_function == "hamming_window":
																			a__             =     window_function(window_length=self.sample_size			,name=self.win_function			,periodic=__snake_case      )
												else:
																			a__             =     window_function(window_length=self.sample_size			,name=self.win_function      )

												a__             =     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			,)

												a__             =     spectrogram(
												    one_waveform * self.frame_signal_scale			,window=__snake_case			,frame_length=self.sample_size			,hop_length=self.sample_stride			,fft_length=self.n_fft			,center=__snake_case			,preemphasis=self.preemphasis_coeff			,mel_filters=__snake_case			,mel_floor=self.mel_floor			,log_mel='log'			,)
												return msfc_features.T
					def  lowerCamelCase__(      self   :str			,__snake_case   :List[str]			,__snake_case   :Any			,__snake_case   :Any      )					->    int:
												# make sure we normalize float32 arrays
												if self.normalize_means:
																			a__             =     x[:input_length].mean(axis=0      )
																			a__             =     np.subtract(__snake_case			,__snake_case      )
												if self.normalize_vars:
																			a__             =     x[:input_length].std(axis=0      )
																			a__             =     np.divide(__snake_case			,__snake_case      )

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

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

												return x
					def  lowerCamelCase__(      self   :Optional[int]			,__snake_case   :List[np.ndarray]			,__snake_case   :Optional[np.ndarray] = None      )					->    List[np.ndarray]:
												a__             =     attention_mask.sum(-1      ) if attention_mask is not None else [x.shape[0] for x in input_features]
												return [self._normalize_one(__snake_case			,__snake_case			,self.padding_value      ) for x, n in zip(__snake_case			,__snake_case      )]



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

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

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

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

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

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

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

												a__             =     self.pad(
												    __snake_case			,padding=__snake_case			,max_length=__snake_case			,truncation=__snake_case			,pad_to_multiple_of=__snake_case			,return_attention_mask=__snake_case			,**__snake_case			,)
												# make sure list is in array format
												a__             =     padded_inputs.get('input_features'      )
												if isinstance(input_features[0]			,__snake_case      ):
																			a__             =     [np.asarray(__snake_case			,dtype=np.floataa      ) for feature in input_features]

												a__             =     padded_inputs.get('attention_mask'      )
												if attention_mask is not None:
																			a__             =     [np.asarray(__snake_case			,dtype=np.intaa      ) for array in attention_mask]

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

												if return_tensors is not None:
																			a__             =     padded_inputs.convert_to_tensors(__snake_case      )

												return padded_inputs








from collections import OrderedDict
from typing import Mapping

from packaging import version

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


snake_case							:       Union[str, Any]     			=      logging.get_logger(__name__)

snake_case							:       str     			=      {
    '''google/mobilenet_v2_1.4_224''': '''https://huggingface.co/google/mobilenet_v2_1.4_224/resolve/main/config.json''',
    '''google/mobilenet_v2_1.0_224''': '''https://huggingface.co/google/mobilenet_v2_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v2_0.75_160''': '''https://huggingface.co/google/mobilenet_v2_0.75_160/resolve/main/config.json''',
    '''google/mobilenet_v2_0.35_96''': '''https://huggingface.co/google/mobilenet_v2_0.35_96/resolve/main/config.json''',
    # See all MobileNetV2 models at https://huggingface.co/models?filter=mobilenet_v2
}







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    str          =			'''mobilenet_v2'''
					def __init__(      self   :Optional[Any]			,__snake_case   :List[Any]=3			,__snake_case   :Any=2_24			,__snake_case   :Dict=1.0			,__snake_case   :str=8			,__snake_case   :Union[str, Any]=8			,__snake_case   :Optional[Any]=6			,__snake_case   :str=32			,__snake_case   :Tuple=True			,__snake_case   :Union[str, Any]=True			,__snake_case   :Any="relu6"			,__snake_case   :List[str]=True			,__snake_case   :Dict=0.8			,__snake_case   :Optional[int]=0.02			,__snake_case   :Tuple=0.0_01			,__snake_case   :Dict=2_55			,**__snake_case   :Dict			,)					->    Any:
												super().__init__(**__snake_case      )

												if depth_multiplier <= 0:
																			raise ValueError('depth_multiplier must be greater than zero.'      )

												a__             =     num_channels
												a__             =     image_size
												a__             =     depth_multiplier
												a__             =     depth_divisible_by
												a__             =     min_depth
												a__             =     expand_ratio
												a__             =     output_stride
												a__             =     first_layer_is_expansion
												a__             =     finegrained_output
												a__             =     hidden_act
												a__             =     tf_padding
												a__             =     classifier_dropout_prob
												a__             =     initializer_range
												a__             =     layer_norm_eps
												a__             =     semantic_loss_ignore_index







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    Tuple          =			version.parse('''1.11'''      )
					@property
					def  lowerCamelCase__(      self   :Any      )					->    Mapping[str, Mapping[int, str]]:
												return OrderedDict([('pixel_values', {0: 'batch'})]      )
					@property
					def  lowerCamelCase__(      self   :List[str]      )					->    Mapping[str, Mapping[int, str]]:
												if self.task == "image-classification":
																			return OrderedDict([('logits', {0: 'batch'})]      )
												else:
																			return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]      )



					@property
					def  lowerCamelCase__(      self   :Any      )					->    float:
												return 1E-4




