





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


lowerCamelCase_       =		logging.get_logger(__name__)






class  _SCREAMING_SNAKE_CASE(       lowerCAmelCase__  ):
       SCREAMING_SNAKE_CASE_       :				Any     						=  ["input_features", "attention_mask"]




       def __init__(						self		,SCREAMING_SNAKE_CASE__=80		,SCREAMING_SNAKE_CASE__=1_60_00		,SCREAMING_SNAKE_CASE__=80		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,**SCREAMING_SNAKE_CASE__		,)      ->				List[str]:





             """simple docstring"""






             super().__init__(feature_size=_SCREAMING_SNAKE_CASE		,sampling_rate=_SCREAMING_SNAKE_CASE		,padding_value=_SCREAMING_SNAKE_CASE		,**_SCREAMING_SNAKE_CASE							)
             __SCREAMING_SNAKE_CASE       :str		    =  num_mel_bins
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  do_ceptral_normalize
             __SCREAMING_SNAKE_CASE       :int		    =  normalize_means
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  normalize_vars
             __SCREAMING_SNAKE_CASE       :Tuple		    =  True




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,)      ->				np.ndarray:





             """simple docstring"""






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




       @staticmethod
       def    _UpperCamelCase					(						SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__ = True		,SCREAMING_SNAKE_CASE__ = True		,SCREAMING_SNAKE_CASE__ = 0.0		,)      ->				np.ndarray:





             """simple docstring"""






             if normalize_means:
                   __SCREAMING_SNAKE_CASE       :str		    =  x[:input_length].mean(axis=0							)
                   __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  np.subtract(_SCREAMING_SNAKE_CASE		,_SCREAMING_SNAKE_CASE							)
             if normalize_vars:
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  x[:input_length].std(axis=0							)
                   __SCREAMING_SNAKE_CASE       :str		    =  np.divide(_SCREAMING_SNAKE_CASE		,_SCREAMING_SNAKE_CASE							)

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

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

             return x




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__ = None							)      ->				List[np.ndarray]:





             """simple docstring"""






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




       def __call__(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__ = False		,SCREAMING_SNAKE_CASE__ = None		,SCREAMING_SNAKE_CASE__ = False		,SCREAMING_SNAKE_CASE__ = None		,SCREAMING_SNAKE_CASE__ = None		,SCREAMING_SNAKE_CASE__ = None		,SCREAMING_SNAKE_CASE__ = None		,**SCREAMING_SNAKE_CASE__		,)      ->				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.'''							)

             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  isinstance(_SCREAMING_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}'''							)
             __SCREAMING_SNAKE_CASE       :int		    =  is_batched_numpy or (
                 isinstance(_SCREAMING_SNAKE_CASE		,(list, tuple)							) and (isinstance(raw_speech[0]		,(np.ndarray, tuple, list)							))
             )

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

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

             # extract fbank features
             __SCREAMING_SNAKE_CASE       :int		    =  [self._extract_fbank_features(_SCREAMING_SNAKE_CASE							) for waveform in raw_speech]

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

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

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

             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  padded_inputs.get('''attention_mask'''							)
             if attention_mask is not None:
                   __SCREAMING_SNAKE_CASE       :Optional[int]		    =  [np.asarray(_SCREAMING_SNAKE_CASE		,dtype=np.intaa							) for array in attention_mask]

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

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

             return padded_inputs






"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase_       =		logging.get_logger(__name__)

lowerCamelCase_       =		{
    "google/vivit-b-16x2-kinetics400": (
        "https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}






class  _SCREAMING_SNAKE_CASE(       A  ):
       SCREAMING_SNAKE_CASE_       :				Optional[Any]     						=  '''vivit'''




       def __init__(						self		,SCREAMING_SNAKE_CASE__=2_24		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=[2, 16, 16]		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=7_68		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=30_72		,SCREAMING_SNAKE_CASE__="gelu_fast"		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-06		,SCREAMING_SNAKE_CASE__=True		,**SCREAMING_SNAKE_CASE__		,)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  hidden_size
             __SCREAMING_SNAKE_CASE       :List[str]		    =  num_hidden_layers
             __SCREAMING_SNAKE_CASE       :List[str]		    =  num_attention_heads
             __SCREAMING_SNAKE_CASE       :Any		    =  intermediate_size
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  hidden_act
             __SCREAMING_SNAKE_CASE       :int		    =  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE       :Dict		    =  initializer_range
             __SCREAMING_SNAKE_CASE       :Dict		    =  layer_norm_eps

             __SCREAMING_SNAKE_CASE       :Any		    =  image_size
             __SCREAMING_SNAKE_CASE       :Any		    =  num_frames
             __SCREAMING_SNAKE_CASE       :Any		    =  tubelet_size
             __SCREAMING_SNAKE_CASE       :Tuple		    =  num_channels
             __SCREAMING_SNAKE_CASE       :List[str]		    =  qkv_bias

             super().__init__(**SCREAMING_SNAKE_CASE__							)