


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


__snake_case							      =     logging.get_logger(__name__)
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				['input_features', 'attention_mask']




		def __init__(		self    ,   UpperCamelCase_=80    ,   UpperCamelCase_=16000    ,   UpperCamelCase_=80    ,   UpperCamelCase_=0.0    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							super().__init__(feature_size=UpperCamelCase_    ,   sampling_rate=UpperCamelCase_    ,   padding_value=UpperCamelCase_    ,   **UpperCamelCase_							)
							UpperCamelCase__   :Union[str, Any]												= num_mel_bins
							UpperCamelCase__   :int												= do_ceptral_normalize
							UpperCamelCase__   :List[str]												= normalize_means
							UpperCamelCase__   :Union[str, Any]												= normalize_vars
							UpperCamelCase__   :Union[str, Any]												= True




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
							UpperCamelCase__   :Optional[int]												= torch.from_numpy(UpperCamelCase_							).unsqueeze(0							)
							UpperCamelCase__   :Tuple												= ta_kaldi.fbank(UpperCamelCase_    ,   num_mel_bins=self.num_mel_bins    ,   sample_frequency=self.sampling_rate							)
							return features.numpy()




		@staticmethod
		def     lowerCAmelCase__				(		UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_ = True    ,   UpperCamelCase_ = True    ,   UpperCamelCase_ = 0.0    ,   ):

							'''simple docstring'''


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

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

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

							return x




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= attention_mask.sum(-1							) if attention_mask is not None else [x.shape[0] for x in input_features]
							return [
							    self.utterance_cmvn(UpperCamelCase_    ,   UpperCamelCase_    ,   self.normalize_means    ,   self.normalize_vars    ,   self.padding_value							)
							    for x, n in zip(UpperCamelCase_    ,   UpperCamelCase_							)
							]




		def __call__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_ = False    ,   UpperCamelCase_ = None    ,   UpperCamelCase_ = False    ,   UpperCamelCase_ = None    ,   UpperCamelCase_ = None    ,   UpperCamelCase_ = None    ,   UpperCamelCase_ = None    ,   **UpperCamelCase_    ,   ):

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

							UpperCamelCase__   :Dict												= isinstance(UpperCamelCase_    ,   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}'''							)
							UpperCamelCase__   :Tuple												= is_batched_numpy or (
							    isinstance(UpperCamelCase_    ,   (list, tuple)							) and (isinstance(raw_speech[0]    ,   (np.ndarray, tuple, list)							))
							)

							if is_batched:
												UpperCamelCase__   :str												= [np.asarray(UpperCamelCase_    ,   dtype=np.floataa							) for speech in raw_speech]
							elif not is_batched and not isinstance(UpperCamelCase_    ,   np.ndarray							):
												UpperCamelCase__   :int												= np.asarray(UpperCamelCase_    ,   dtype=np.floataa							)
							elif isinstance(UpperCamelCase_    ,   np.ndarray							) and raw_speech.dtype is np.dtype(np.floataa							):
												UpperCamelCase__   :Optional[Any]												= raw_speech.astype(np.floataa							)

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

							# extract fbank features
							UpperCamelCase__   :Tuple												= [self._extract_fbank_features(UpperCamelCase_							) for waveform in raw_speech]

							# convert into correct format for padding
							UpperCamelCase__   :Optional[Any]												= BatchFeature({'''input_features''': features}							)

							UpperCamelCase__   :Union[str, Any]												= self.pad(
							    UpperCamelCase_    ,   padding=UpperCamelCase_    ,   max_length=UpperCamelCase_    ,   truncation=UpperCamelCase_    ,   pad_to_multiple_of=UpperCamelCase_    ,   return_attention_mask=UpperCamelCase_    ,   **UpperCamelCase_    ,   )

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

							UpperCamelCase__   :Tuple												= padded_inputs.get('''attention_mask'''							)
							if attention_mask is not None:
												UpperCamelCase__   :Optional[int]												= [np.asarray(UpperCamelCase_    ,   dtype=np.intaa							) for array in attention_mask]

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

							if return_tensors is not None:
												UpperCamelCase__   :Any												= padded_inputs.convert_to_tensors(UpperCamelCase_							)

							return padded_inputs



'''simple docstring'''
from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available, is_vision_available
from ...utils import OptionalDependencyNotAvailable


__snake_case							      =     {'''configuration_dpt''': ['''DPT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DPTConfig''']}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							      =     ['''DPTFeatureExtractor''']
		__snake_case							      =     ['''DPTImageProcessor''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							      =     [
		    '''DPT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''DPTForDepthEstimation''',
		    '''DPTForSemanticSegmentation''',
		    '''DPTModel''',
		    '''DPTPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_dpt import DPT_PRETRAINED_CONFIG_ARCHIVE_MAP, DPTConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_dpt import DPTFeatureExtractor
				from .image_processing_dpt import DPTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_dpt import (
				    DPT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DPTForDepthEstimation,
				    DPTForSemanticSegmentation,
				    DPTModel,
				    DPTPreTrainedModel,
				)


else:
		import sys

		__snake_case							      =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)