"""simple docstring"""







import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import UperNetForSemanticSegmentation
       from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image

       from transformers import AutoImageProcessor







class  UpperCamelCase	:
   def __init__(    self  ,__UpperCamelCase  ,__UpperCamelCase=13  ,__UpperCamelCase=32  ,__UpperCamelCase=3  ,__UpperCamelCase=4  ,__UpperCamelCase=[10, 20, 30, 40]  ,__UpperCamelCase=[2, 2, 3, 2]  ,__UpperCamelCase=True  ,__UpperCamelCase=True  ,__UpperCamelCase=37  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=10  ,__UpperCamelCase=0.02  ,__UpperCamelCase=["stage2", "stage3", "stage4"]  ,__UpperCamelCase=3  ,__UpperCamelCase=None  ,)			->   Union[str, Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			parent
        lowercase_			:       Union[str, Any]									=			batch_size
        lowercase_			:       List[str]									=			image_size
        lowercase_			:       List[str]									=			num_channels
        lowercase_			:       Tuple									=			num_stages
        lowercase_			:       Tuple									=			hidden_sizes
        lowercase_			:       Any									=			depths
        lowercase_			:       Optional[int]									=			is_training
        lowercase_			:       List[str]									=			use_labels
        lowercase_			:       Any									=			intermediate_size
        lowercase_			:       List[str]									=			hidden_act
        lowercase_			:       Any									=			type_sequence_label_size
        lowercase_			:       str									=			initializer_range
        lowercase_			:       Optional[int]									=			out_features
        lowercase_			:       List[Any]									=			num_labels
        lowercase_			:       Dict									=			scope
        lowercase_			:       Optional[int]									=			num_stages
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

        lowercase_			:       Union[str, Any]									=			None
        if self.use_labels:
             lowercase_			:       int									=			ids_tensor([self.batch_size]  ,self.type_sequence_label_size    )

        lowercase_			:       int									=			self.get_config()

        return config, pixel_values, labels
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        return ConvNextConfig(
            num_channels=self.num_channels  ,num_stages=self.num_stages  ,hidden_sizes=self.hidden_sizes  ,depths=self.depths  ,is_training=self.is_training  ,intermediate_size=self.intermediate_size  ,hidden_act=self.hidden_act  ,out_features=self.out_features  ,)
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        return UperNetConfig(
            backbone_config=self.get_backbone_config()  ,hidden_size=512  ,pool_scales=[1, 2, 3, 6]  ,use_auxiliary_head=__UpperCamelCase  ,auxiliary_loss_weight=0.4  ,auxiliary_in_channels=40  ,auxiliary_channels=256  ,auxiliary_num_convs=1  ,auxiliary_concat_input=__UpperCamelCase  ,loss_ignore_index=255  ,num_labels=self.num_labels  ,)
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Union[str, Any]:


        '''simple docstring'''


        lowercase_			:       str									=			UperNetForSemanticSegmentation(config=__UpperCamelCase    )
        model.to(__UpperCamelCase    )
        model.eval()
        lowercase_			:       Any									=			model(__UpperCamelCase    )
        self.parent.assertEqual(
            result.logits.shape  ,(self.batch_size, self.num_labels, self.image_size, self.image_size)    )







   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       List[str]									=			self.prepare_config_and_inputs()
        (
            lowercase_						
        )			:       Optional[int]									=			config_and_inputs
        lowercase_			:       str									=			{'pixel_values': pixel_values}
        return config, inputs_dict







@require_torch
class  UpperCamelCase	(    lowercase_		,   lowercase_		,   unittest.TestCase						):
   lowercase							=						(UperNetForSemanticSegmentation,) if is_torch_available() else ()
   lowercase							=						{'image-segmentation': UperNetForSemanticSegmentation} if is_torch_available() else {}
   lowercase							=						False
   lowercase							=						False
   lowercase							=						False
   lowercase							=						False
   lowercase							=						False
   lowercase							=						False
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        lowercase_			:       int									=			UperNetModelTester(self    )
        lowercase_			:       List[str]									=			ConfigTester(self  ,config_class=__UpperCamelCase  ,has_text_modality=__UpperCamelCase  ,hidden_size=37    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        self.create_and_test_config_common_properties()
        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()
   def     _UpperCAmelCase     (    self    )			->   List[Any]:


        '''simple docstring'''


        return
   def     _UpperCAmelCase     (    self    )			->   List[Any]:


        '''simple docstring'''


        lowercase_			:       List[str]									=			self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             lowercase_			:       Union[str, Any]									=			model_class(__UpperCamelCase    )
             lowercase_			:       Optional[int]									=			inspect.signature(model.forward    )
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             lowercase_			:       Union[str, Any]									=			[*signature.parameters.keys()]

             lowercase_			:       Any									=			['pixel_values']
             self.assertListEqual(arg_names[:1]  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   str:


        '''simple docstring'''


        lowercase_			:       int									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_semantic_segmentation(*__UpperCamelCase    )
   @unittest.skip(reason='UperNet does not use inputs_embeds'    )
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        pass
   @unittest.skip(reason='UperNet does not support input and output embeddings'    )
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        pass
   @unittest.skip(reason='UperNet does not have a base model'    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        pass
   @unittest.skip(reason='UperNet does not have a base model'    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        pass
   @require_torch_multi_gpu
   @unittest.skip(reason='UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'    )
   def     _UpperCAmelCase     (    self    )			->   Any:


        '''simple docstring'''


        pass
   @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'    )
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        pass
   def     _UpperCAmelCase     (    self    )			->   str:


        '''simple docstring'''


        def check_hidden_states_output(__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    ):
             lowercase_			:       int									=			model_class(__UpperCamelCase    )
             model.to(__UpperCamelCase    )
             model.eval()

             with torch.no_grad():
                  lowercase_			:       int									=			model(**self._prepare_for_class(__UpperCamelCase  ,__UpperCamelCase    )    )

             lowercase_			:       Union[str, Any]									=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

             lowercase_			:       str									=			self.model_tester.num_stages
             self.assertEqual(len(__UpperCamelCase    )  ,expected_num_stages + 1    )

             # ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]    )  ,[self.model_tester.image_size // 4, self.model_tester.image_size // 4]  ,)

        lowercase_			:       List[Any]									=			self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             lowercase_			:       Any									=			True
             check_hidden_states_output(__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             lowercase_			:       Tuple									=			True

             check_hidden_states_output(__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        lowercase_			:       str									=			self.model_tester.prepare_config_and_inputs_for_common()

        lowercase_			:       Optional[Any]									=			_config_zero_init(__UpperCamelCase    )
        lowercase_			:       Any									=			_config_zero_init(configs_no_init.backbone_config    )
        for model_class in self.all_model_classes:
             lowercase_			:       str									=			model_class(config=__UpperCamelCase    )
             for name, param in model.named_parameters():
                  if param.requires_grad:
                       self.assertIn(
                           ((param.data.mean() * 1e9).round() / 1e9).item()  ,[0.0, 1.0]  ,msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''  ,)
   @unittest.skip(reason='UperNet does not have tied weights'    )
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        pass







   @slow
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_			:       Tuple									=			UperNetForSemanticSegmentation.from_pretrained(__UpperCamelCase    )
             self.assertIsNotNone(__UpperCamelCase    )






def     lowercase__( ):
     lowercase_			:       List[Any]									=			hf_hub_download(
         repo_id='hf-internal-testing/fixtures_ade20k'  ,    repo_type='dataset'  ,    filename='ADE_val_00000001.jpg'   )
     lowercase_			:       Union[str, Any]									=			Image.open(__SCREAMING_SNAKE_CASE   ).convert('RGB'   )
     return image







@require_torch
@require_vision
@slow
class  UpperCamelCase	(    unittest.TestCase						):
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        lowercase_			:       str									=			AutoImageProcessor.from_pretrained('openmmlab/upernet-swin-tiny'    )
        lowercase_			:       Any									=			UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-swin-tiny'    ).to(__UpperCamelCase    )

        lowercase_			:       List[str]									=			prepare_img()
        lowercase_			:       Union[str, Any]									=			processor(images=__UpperCamelCase  ,return_tensors='pt'    ).to(__UpperCamelCase    )

        with torch.no_grad():
             lowercase_			:       Any									=			model(**__UpperCamelCase    )

        lowercase_			:       Optional[Any]									=			torch.Size((1, model.config.num_labels, 512, 512)    )
        self.assertEqual(outputs.logits.shape  ,__UpperCamelCase    )

        lowercase_			:       Optional[int]									=			torch.tensor(
            [[-7.5958, -7.5958, -7.4302], [-7.5958, -7.5958, -7.4302], [-7.4797, -7.4797, -7.3068]]    ).to(__UpperCamelCase    )
        self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]  ,__UpperCamelCase  ,atol=1e-4    )    )







   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			AutoImageProcessor.from_pretrained('openmmlab/upernet-convnext-tiny'    )
        lowercase_			:       List[Any]									=			UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-convnext-tiny'    ).to(__UpperCamelCase    )

        lowercase_			:       Union[str, Any]									=			prepare_img()
        lowercase_			:       List[Any]									=			processor(images=__UpperCamelCase  ,return_tensors='pt'    ).to(__UpperCamelCase    )

        with torch.no_grad():
             lowercase_			:       str									=			model(**__UpperCamelCase    )

        lowercase_			:       Optional[int]									=			torch.Size((1, model.config.num_labels, 512, 512)    )
        self.assertEqual(outputs.logits.shape  ,__UpperCamelCase    )

        lowercase_			:       str									=			torch.tensor(
            [[-8.8110, -8.8110, -8.6521], [-8.8110, -8.8110, -8.6521], [-8.7746, -8.7746, -8.6130]]    ).to(__UpperCamelCase    )
        self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]  ,__UpperCamelCase  ,atol=1e-4    )    )


"""simple docstring"""







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

import numpy as np
import torch

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


__SCREAMING_SNAKE_CASE								=logging.get_logger(__name__)







class  UpperCamelCase	(    lowercase_						):
   lowercase							=						['input_features', 'is_longer']
   def __init__(    self  ,__UpperCamelCase=64  ,__UpperCamelCase=4_8000  ,__UpperCamelCase=480  ,__UpperCamelCase=10  ,__UpperCamelCase=1024  ,__UpperCamelCase=0.0  ,__UpperCamelCase=False  ,__UpperCamelCase = 0  ,__UpperCamelCase = 1_4000  ,__UpperCamelCase = None  ,__UpperCamelCase = "fusion"  ,__UpperCamelCase = "repeatpad"  ,**__UpperCamelCase  ,)			->   Optional[int]:


        '''simple docstring'''


        super().__init__(
            feature_size=__UpperCamelCase  ,sampling_rate=__UpperCamelCase  ,padding_value=__UpperCamelCase  ,return_attention_mask=__UpperCamelCase  ,**__UpperCamelCase  ,)
        lowercase_			:       Union[str, Any]									=			top_db
        lowercase_			:       Any									=			truncation
        lowercase_			:       str									=			padding
        lowercase_			:       Optional[Any]									=			fft_window_size
        lowercase_			:       List[Any]									=			(fft_window_size >> 1) + 1
        lowercase_			:       Any									=			hop_length
        lowercase_			:       List[Any]									=			max_length_s
        lowercase_			:       Any									=			max_length_s * sampling_rate
        lowercase_			:       Optional[int]									=			sampling_rate
        lowercase_			:       List[Any]									=			frequency_min
        lowercase_			:       str									=			frequency_max
        lowercase_			:       Any									=			mel_filter_bank(
            num_frequency_bins=self.nb_frequency_bins  ,num_mel_filters=__UpperCamelCase  ,min_frequency=__UpperCamelCase  ,max_frequency=__UpperCamelCase  ,sampling_rate=__UpperCamelCase  ,norm=__UpperCamelCase  ,mel_scale='htk'  ,)
        lowercase_			:       Optional[Any]									=			mel_filter_bank(
            num_frequency_bins=self.nb_frequency_bins  ,num_mel_filters=__UpperCamelCase  ,min_frequency=__UpperCamelCase  ,max_frequency=__UpperCamelCase  ,sampling_rate=__UpperCamelCase  ,norm='slaney'  ,mel_scale='slaney'  ,)
   def     _UpperCAmelCase     (    self    )			->   Dict[str, Any]:


        '''simple docstring'''


        lowercase_			:       int									=			copy.deepcopy(self.__dict__    )
        lowercase_			:       Any									=			self.__class__.__name__
        if "mel_filters" in output:
             del output["mel_filters"]
        if "mel_filters_slaney" in output:
             del output["mel_filters_slaney"]
        return output
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase = None    )			->   np.ndarray:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			spectrogram(
            __UpperCamelCase  ,window_function(self.fft_window_size  ,'hann'    )  ,frame_length=self.fft_window_size  ,hop_length=self.hop_length  ,power=2.0  ,mel_filters=__UpperCamelCase  ,log_mel='dB'  ,)
        return log_mel_spectrogram.T
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Any:


        '''simple docstring'''


        lowercase_			:       Dict									=			np.array_split(list(range(0  ,total_frames - chunk_frames + 1    )    )  ,3    )
        if len(ranges[1]    ) == 0:
             # if the audio is too short, we just use the first chunk
             lowercase_			:       Optional[int]									=			[0]
        if len(ranges[2]    ) == 0:
             # if the audio is too short, we just use the first chunk
             lowercase_			:       List[str]									=			[0]
        # randomly choose index for each part
        lowercase_			:       List[str]									=			np.random.choice(ranges[0]    )
        lowercase_			:       Optional[Any]									=			np.random.choice(ranges[1]    )
        lowercase_			:       Union[str, Any]									=			np.random.choice(ranges[2]    )

        lowercase_			:       Tuple									=			mel[idx_front : idx_front + chunk_frames, :]
        lowercase_			:       str									=			mel[idx_middle : idx_middle + chunk_frames, :]
        lowercase_			:       Optional[Any]									=			mel[idx_back : idx_back + chunk_frames, :]

        lowercase_			:       Tuple									=			torch.tensor(mel[None, None, :]    )
        lowercase_			:       Optional[Any]									=			torch.nn.functional.interpolate(
            __UpperCamelCase  ,size=[chunk_frames, 64]  ,mode='bilinear'  ,align_corners=__UpperCamelCase    )
        lowercase_			:       str									=			mel_shrink[0][0].numpy()
        lowercase_			:       Optional[int]									=			np.stack([mel_shrink, mel_chunk_front, mel_chunk_middle, mel_chunk_back]  ,axis=0    )
        return mel_fusion
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   np.array:


        '''simple docstring'''


        if waveform.shape[0] > max_length:
             if truncation == "rand_trunc":
                  lowercase_			:       Any									=			True
                  # random crop to max_length (for compatibility) -> this should be handled by self.pad
                  lowercase_			:       Any									=			len(__UpperCamelCase    ) - max_length
                  lowercase_			:       List[str]									=			np.random.randint(0  ,overflow + 1    )
                  lowercase_			:       Any									=			waveform[idx : idx + max_length]
                  lowercase_			:       Optional[int]									=			self._np_extract_fbank_features(__UpperCamelCase  ,self.mel_filters_slaney    )[None, :]
             elif truncation == "fusion":
                  lowercase_			:       str									=			self._np_extract_fbank_features(__UpperCamelCase  ,self.mel_filters    )
                  lowercase_			:       List[str]									=			max_length // self.hop_length + 1  # the +1 related to how the spectrogram is computed
                  lowercase_			:       Dict									=			mel.shape[0]
                  if chunk_frames == total_frames:
                       # there is a corner case where the audio length is larger than max_length but smaller than max_length+hop_length.
                       # In this case, we just use the whole audio.
                       lowercase_			:       int									=			np.stack([mel, mel, mel, mel]  ,axis=0    )
                       lowercase_			:       Optional[Any]									=			False
                  else:
                       lowercase_			:       int									=			self._random_mel_fusion(__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )
                       lowercase_			:       Tuple									=			True
             else:
                  raise NotImplementedError(f'''data_truncating {truncation} not implemented'''    )

        else:
             lowercase_			:       Dict									=			False
             # only use repeat as a new possible value for padding. you repeat the audio before applying the usual max_length padding
             if waveform.shape[0] < max_length:
                  if padding == "repeat":
                       lowercase_			:       Optional[int]									=			int(max_length / len(__UpperCamelCase    )    )
                       lowercase_			:       Any									=			np.stack(np.tile(__UpperCamelCase  ,n_repeat + 1    )    )[:max_length]
                  if padding == "repeatpad":
                       lowercase_			:       Union[str, Any]									=			int(max_length / len(__UpperCamelCase    )    )
                       lowercase_			:       int									=			np.stack(np.tile(__UpperCamelCase  ,__UpperCamelCase    )    )
                  lowercase_			:       str									=			np.pad(__UpperCamelCase  ,(0, max_length - waveform.shape[0])  ,mode='constant'  ,constant_values=0    )

             if truncation == "fusion":
                  lowercase_			:       List[str]									=			self._np_extract_fbank_features(__UpperCamelCase  ,self.mel_filters    )
                  lowercase_			:       List[str]									=			np.stack([input_mel, input_mel, input_mel, input_mel]  ,axis=0    )
             else:
                  lowercase_			:       Any									=			self._np_extract_fbank_features(__UpperCamelCase  ,self.mel_filters_slaney    )[None, :]

        return input_mel, longer







   def __call__(    self  ,__UpperCamelCase  ,__UpperCamelCase = None  ,__UpperCamelCase = None  ,__UpperCamelCase = None  ,__UpperCamelCase = None  ,__UpperCamelCase = None  ,**__UpperCamelCase  ,)			->   BatchFeature:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			truncation if truncation is not None else self.truncation
        lowercase_			:       List[Any]									=			padding if padding else self.padding

        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_			:       Tuple									=			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}'''    )
        lowercase_			:       List[str]									=			is_batched_numpy or (
            isinstance(__UpperCamelCase  ,(list, tuple)    ) and (isinstance(raw_speech[0]  ,(np.ndarray, tuple, list)    ))
        )

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

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

        # convert to mel spectrogram, truncate and pad if needed.
        lowercase_			:       List[str]									=			[
            self._get_input_mel(__UpperCamelCase  ,max_length if max_length else self.nb_max_samples  ,__UpperCamelCase  ,__UpperCamelCase    )
            for waveform in raw_speech
        ]

        lowercase_			:       int									=			[]
        lowercase_			:       int									=			[]
        for mel, longer in padded_inputs:
             input_mel.append(__UpperCamelCase    )
             is_longer.append(__UpperCamelCase    )

        if truncation == "fusion" and sum(__UpperCamelCase    ) == 0:
             # if no audio is longer than 10s, then randomly select one audio to be longer
             lowercase_			:       int									=			np.random.randint(0  ,len(__UpperCamelCase    )    )
             lowercase_			:       Tuple									=			True

        if isinstance(input_mel[0]  ,__UpperCamelCase    ):
             lowercase_			:       Union[str, Any]									=			[np.asarray(__UpperCamelCase  ,dtype=np.floataa    ) for feature in input_mel]

        # is_longer is a list of bool
        lowercase_			:       Any									=			[[longer] for longer in is_longer]

        lowercase_			:       List[Any]									=			{'input_features': input_mel, 'is_longer': is_longer}
        lowercase_			:       Union[str, Any]									=			BatchFeature(__UpperCamelCase    )

        if return_tensors is not None:
             lowercase_			:       Any									=			input_features.convert_to_tensors(__UpperCamelCase    )

        return input_features

