

import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_MAPPING,
					    SegformerForImageClassification,
					    SegformerForSemanticSegmentation,
					    SegformerModel,
					)
					from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import SegformerImageProcessor

class 			a					(		UpperCAmelCase			):


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Dict							=      self.config_class(**self.inputs_dict		)
										self.parent.assertTrue(hasattr(lowerCAmelCase__  ,   "hidden_sizes"		)		)
										self.parent.assertTrue(hasattr(lowerCAmelCase__  ,   "num_attention_heads"		)		)
										self.parent.assertTrue(hasattr(lowerCAmelCase__  ,   "num_encoder_blocks"		)		)







class 			a					:


						def __init__(    self  ,   A_  ,   A_=13  ,   A_=64  ,   A_=3  ,   A_=4  ,   A_=[2, 2, 2, 2]  ,   A_=[8, 4, 2, 1]  ,   A_=[16, 32, 64, 128]  ,   A_=[1, 4, 8, 16]  ,   A_=[1, 2, 4, 8]  ,   A_=True  ,   A_=True  ,   A_="gelu"  ,   A_=0.1  ,   A_=0.1  ,   A_=0.02  ,   A_=3  ,   A_=None  ,   ):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[int]							=      parent
										_UpperCAmelCase    :						Optional[Any]							=      batch_size
										_UpperCAmelCase    :						str							=      image_size
										_UpperCAmelCase    :						Dict							=      num_channels
										_UpperCAmelCase    :						Any							=      num_encoder_blocks
										_UpperCAmelCase    :						int							=      sr_ratios
										_UpperCAmelCase    :						Dict							=      depths
										_UpperCAmelCase    :						int							=      hidden_sizes
										_UpperCAmelCase    :						List[Any]							=      downsampling_rates
										_UpperCAmelCase    :						int							=      num_attention_heads
										_UpperCAmelCase    :						Dict							=      is_training
										_UpperCAmelCase    :						List[Any]							=      use_labels
										_UpperCAmelCase    :						int							=      hidden_act
										_UpperCAmelCase    :						List[Any]							=      hidden_dropout_prob
										_UpperCAmelCase    :						Dict							=      attention_probs_dropout_prob
										_UpperCAmelCase    :						Union[str, Any]							=      initializer_range
										_UpperCAmelCase    :						Union[str, Any]							=      num_labels
										_UpperCAmelCase    :						Optional[Any]							=      scope


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


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

										_UpperCAmelCase    :						str							=      None
										if self.use_labels:
														_UpperCAmelCase    :						Dict							=      ids_tensor([self.batch_size, self.image_size, self.image_size]  ,   self.num_labels		)

										_UpperCAmelCase    :						List[str]							=      self.get_config()
										return config, pixel_values, labels


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										return SegformerConfig(
										    image_size=self.image_size  ,   num_channels=self.num_channels  ,   num_encoder_blocks=self.num_encoder_blocks  ,   depths=self.depths  ,   hidden_sizes=self.hidden_sizes  ,   num_attention_heads=self.num_attention_heads  ,   hidden_act=self.hidden_act  ,   hidden_dropout_prob=self.hidden_dropout_prob  ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,   initializer_range=self.initializer_range  ,   )


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      SegformerModel(config=lowerCAmelCase__		)
										model.to(lowerCAmelCase__		)
										model.eval()
										_UpperCAmelCase    :						Dict							=      model(lowerCAmelCase__		)
										_UpperCAmelCase    :						Optional[Any]							=      self.image_size // (self.downsampling_rates[-1] * 2)
										self.parent.assertEqual(
										    result.last_hidden_state.shape  ,   (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)		)


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						Dict							=      self.num_labels
										_UpperCAmelCase    :						Optional[int]							=      SegformerForSemanticSegmentation(lowerCAmelCase__		)
										model.to(lowerCAmelCase__		)
										model.eval()
										_UpperCAmelCase    :						Tuple							=      model(lowerCAmelCase__		)
										self.parent.assertEqual(
										    result.logits.shape  ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)		)
										_UpperCAmelCase    :						Tuple							=      model(lowerCAmelCase__  ,   labels=lowerCAmelCase__		)
										self.parent.assertEqual(
										    result.logits.shape  ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)		)
										self.parent.assertGreater(result.loss  ,   0.0		)


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						str							=      1
										_UpperCAmelCase    :						Dict							=      SegformerForSemanticSegmentation(config=lowerCAmelCase__		)
										model.to(lowerCAmelCase__		)
										model.eval()
										_UpperCAmelCase    :						Tuple							=      torch.randint(0  ,   1  ,   (self.batch_size, self.image_size, self.image_size)		).to(lowerCAmelCase__		)
										_UpperCAmelCase    :						Optional[Any]							=      model(lowerCAmelCase__  ,   labels=lowerCAmelCase__		)
										self.parent.assertGreater(result.loss  ,   0.0		)





						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[Any]							=      self.prepare_config_and_inputs()
										_UpperCAmelCase    :						Any							=      config_and_inputs
										_UpperCAmelCase    :						Tuple							=      {"pixel_values": pixel_values}
										return config, inputs_dict







@require_torch
class 			a					(		UpperCAmelCase							,	UpperCAmelCase							,	unittest.TestCase			):
						_lowercase        =     (
						    (
						        SegformerModel,
						        SegformerForSemanticSegmentation,
						        SegformerForImageClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowercase        =     (
						    {
						        '''feature-extraction''': SegformerModel,
						        '''image-classification''': SegformerForImageClassification,
						        '''image-segmentation''': SegformerForSemanticSegmentation,
						    }
						    if is_torch_available()
						    else {}
						)

						_lowercase        =     True
						_lowercase        =     False
						_lowercase        =     False
						_lowercase        =     False


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[int]							=      SegformerModelTester(self		)
										_UpperCAmelCase    :						int							=      SegformerConfigTester(self  ,   config_class=lowerCAmelCase__		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										self.config_tester.run_common_tests()


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Dict							=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						str							=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_binary_image_segmentation(*lowerCAmelCase__		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_segmentation(*lowerCAmelCase__		)


						@unittest.skip("SegFormer does not use inputs_embeds"		)
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										pass


						@unittest.skip("SegFormer does not have get_input_embeddings method and get_output_embeddings methods"		)
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										pass


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


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

										for model_class in self.all_model_classes:
														_UpperCAmelCase    :						int							=      model_class(lowerCAmelCase__		)
														_UpperCAmelCase    :						Dict							=      inspect.signature(model.forward		)
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														_UpperCAmelCase    :						List[str]							=      [*signature.parameters.keys()]

														_UpperCAmelCase    :						List[str]							=      ["pixel_values"]
														self.assertListEqual(arg_names[:1]  ,   lowerCAmelCase__		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Tuple							=      self.model_tester.prepare_config_and_inputs_for_common()
										_UpperCAmelCase    :						Optional[Any]							=      True

										for model_class in self.all_model_classes:
														_UpperCAmelCase    :						str							=      True
														_UpperCAmelCase    :						Any							=      False
														_UpperCAmelCase    :						List[str]							=      True
														_UpperCAmelCase    :						Dict							=      model_class(lowerCAmelCase__		)
														model.to(lowerCAmelCase__		)
														model.eval()
														with torch.no_grad():
																		_UpperCAmelCase    :						List[str]							=      model(**self._prepare_for_class(lowerCAmelCase__  ,   lowerCAmelCase__		)		)
														_UpperCAmelCase    :						Tuple							=      outputs.attentions

														_UpperCAmelCase    :						str							=      sum(self.model_tester.depths		)
														self.assertEqual(len(lowerCAmelCase__		)  ,   lowerCAmelCase__		)

														# check that output_attentions also work using config
														del inputs_dict["output_attentions"]
														_UpperCAmelCase    :						int							=      True
														_UpperCAmelCase    :						Optional[int]							=      model_class(lowerCAmelCase__		)
														model.to(lowerCAmelCase__		)
														model.eval()
														with torch.no_grad():
																		_UpperCAmelCase    :						Tuple							=      model(**self._prepare_for_class(lowerCAmelCase__  ,   lowerCAmelCase__		)		)
														_UpperCAmelCase    :						str							=      outputs.attentions

														self.assertEqual(len(lowerCAmelCase__		)  ,   lowerCAmelCase__		)

														# verify the first attentions (first block, first layer)
														_UpperCAmelCase    :						List[Any]							=      (self.model_tester.image_size // 4) ** 2
														_UpperCAmelCase    :						Union[str, Any]							=      (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
														self.assertListEqual(
														    list(attentions[0].shape[-3:]		)  ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]  ,   )

														# verify the last attentions (last block, last layer)
														_UpperCAmelCase    :						Any							=      (self.model_tester.image_size // 32) ** 2
														_UpperCAmelCase    :						Union[str, Any]							=      (self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
														self.assertListEqual(
														    list(attentions[-1].shape[-3:]		)  ,   [self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]  ,   )
														_UpperCAmelCase    :						Dict							=      len(lowerCAmelCase__		)

														# Check attention is always last and order is fine
														_UpperCAmelCase    :						Optional[Any]							=      True
														_UpperCAmelCase    :						Optional[int]							=      True
														_UpperCAmelCase    :						str							=      model_class(lowerCAmelCase__		)
														model.to(lowerCAmelCase__		)
														model.eval()
														with torch.no_grad():
																		_UpperCAmelCase    :						Tuple							=      model(**self._prepare_for_class(lowerCAmelCase__  ,   lowerCAmelCase__		)		)

														self.assertEqual(out_len + 1  ,   len(lowerCAmelCase__		)		)

														_UpperCAmelCase    :						Dict							=      outputs.attentions

														self.assertEqual(len(lowerCAmelCase__		)  ,   lowerCAmelCase__		)
														# verify the first attentions (first block, first layer)
														_UpperCAmelCase    :						Dict							=      (self.model_tester.image_size // 4) ** 2
														_UpperCAmelCase    :						List[str]							=      (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
														self.assertListEqual(
														    list(self_attentions[0].shape[-3:]		)  ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]  ,   )


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										def check_hidden_states_output(A_  ,   A_  ,   A_		):
														_UpperCAmelCase    :						List[str]							=      model_class(lowerCAmelCase__		)
														model.to(lowerCAmelCase__		)
														model.eval()

														with torch.no_grad():
																		_UpperCAmelCase    :						Tuple							=      model(**self._prepare_for_class(lowerCAmelCase__  ,   lowerCAmelCase__		)		)

														_UpperCAmelCase    :						str							=      outputs.hidden_states

														_UpperCAmelCase    :						int							=      self.model_tester.num_encoder_blocks
														self.assertEqual(len(lowerCAmelCase__		)  ,   lowerCAmelCase__		)

														# verify the first hidden states (first block)
														self.assertListEqual(
														    list(hidden_states[0].shape[-3:]		)  ,   [
														        self.model_tester.hidden_sizes[0],
														        self.model_tester.image_size // 4,
														        self.model_tester.image_size // 4,
														    ]  ,   )

										_UpperCAmelCase    :						Optional[int]							=      self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														_UpperCAmelCase    :						Dict							=      True
														check_hidden_states_output(lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__		)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														_UpperCAmelCase    :						Optional[Any]							=      True

														check_hidden_states_output(lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										if not self.model_tester.is_training:
														return

										_UpperCAmelCase    :						Any							=      self.model_tester.prepare_config_and_inputs_for_common()
										_UpperCAmelCase    :						Optional[Any]							=      True

										for model_class in self.all_model_classes:
														if model_class in get_values(lowerCAmelCase__		):
																		continue

														_UpperCAmelCase    :						Optional[int]							=      model_class(lowerCAmelCase__		)
														model.to(lowerCAmelCase__		)
														model.train()
														_UpperCAmelCase    :						Dict							=      self._prepare_for_class(lowerCAmelCase__  ,   lowerCAmelCase__  ,   return_labels=lowerCAmelCase__		)
														_UpperCAmelCase    :						Tuple							=      model(**lowerCAmelCase__		).loss
														loss.backward()


						@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										pass





						@slow
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														_UpperCAmelCase    :						str							=      SegformerModel.from_pretrained(lowerCAmelCase__		)
														self.assertIsNotNone(lowerCAmelCase__		)







def 							__SCREAMING_SNAKE_CASE							(			)				->    Optional[Any]:
				_UpperCAmelCase    :						str							=      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
				return image



@require_torch
class 			a					(		unittest.TestCase			):


						@slow
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      SegformerImageProcessor(
										    image_scale=(512, 512)  ,   keep_ratio=lowerCAmelCase__  ,   align=lowerCAmelCase__  ,   do_random_crop=lowerCAmelCase__		)
										_UpperCAmelCase    :						Union[str, Any]							=      SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"		).to(
										    lowerCAmelCase__		)

										_UpperCAmelCase    :						Optional[int]							=      prepare_img()
										_UpperCAmelCase    :						List[Any]							=      image_processor(images=lowerCAmelCase__  ,   return_tensors="pt"		)
										_UpperCAmelCase    :						List[str]							=      encoded_inputs.pixel_values.to(lowerCAmelCase__		)

										with torch.no_grad():
														_UpperCAmelCase    :						Dict							=      model(lowerCAmelCase__		)

										_UpperCAmelCase    :						Union[str, Any]							=      torch.Size((1, model.config.num_labels, 128, 128)		)
										self.assertEqual(outputs.logits.shape  ,   lowerCAmelCase__		)

										_UpperCAmelCase    :						Tuple							=      torch.tensor(
										    [
										        [[-4.63_10, -5.52_32, -6.23_56], [-5.19_21, -6.14_44, -6.59_96], [-5.44_24, -6.27_90, -6.75_74]],
										        [[-12.13_91, -13.31_22, -13.95_54], [-12.87_32, -13.93_52, -14.35_63], [-12.94_38, -13.82_26, -14.25_13]],
										        [[-12.51_34, -13.46_86, -14.49_15], [-12.86_69, -14.43_43, -14.77_58], [-13.25_23, -14.58_19, -15.06_94]],
										    ]		).to(lowerCAmelCase__		)
										self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]  ,   lowerCAmelCase__  ,   atol=1e-4		)		)


						@slow
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      SegformerImageProcessor(
										    image_scale=(512, 512)  ,   keep_ratio=lowerCAmelCase__  ,   align=lowerCAmelCase__  ,   do_random_crop=lowerCAmelCase__		)
										_UpperCAmelCase    :						int							=      SegformerForSemanticSegmentation.from_pretrained(
										    "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"		).to(lowerCAmelCase__		)

										_UpperCAmelCase    :						Dict							=      prepare_img()
										_UpperCAmelCase    :						Optional[Any]							=      image_processor(images=lowerCAmelCase__  ,   return_tensors="pt"		)
										_UpperCAmelCase    :						List[str]							=      encoded_inputs.pixel_values.to(lowerCAmelCase__		)

										with torch.no_grad():
														_UpperCAmelCase    :						int							=      model(lowerCAmelCase__		)

										_UpperCAmelCase    :						Dict							=      torch.Size((1, model.config.num_labels, 128, 128)		)
										self.assertEqual(outputs.logits.shape  ,   lowerCAmelCase__		)

										_UpperCAmelCase    :						Union[str, Any]							=      torch.tensor(
										    [
										        [[-13.57_48, -13.91_11, -12.65_00], [-14.35_00, -15.36_83, -14.23_28], [-14.75_32, -16.04_24, -15.60_87]],
										        [[-17.16_51, -15.87_25, -12.96_53], [-17.25_80, -17.37_18, -14.82_23], [-16.60_58, -16.87_83, -16.74_52]],
										        [[-3.64_56, -3.02_09, -1.42_03], [-3.07_97, -3.19_59, -2.00_00], [-1.87_57, -1.92_17, -1.69_97]],
										    ]		).to(lowerCAmelCase__		)
										self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]  ,   lowerCAmelCase__  ,   atol=1e-1		)		)





						@slow
						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[int]							=      SegformerImageProcessor(
										    image_scale=(512, 512)  ,   keep_ratio=lowerCAmelCase__  ,   align=lowerCAmelCase__  ,   do_random_crop=lowerCAmelCase__		)
										_UpperCAmelCase    :						Any							=      SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"		).to(
										    lowerCAmelCase__		)

										_UpperCAmelCase    :						List[str]							=      prepare_img()
										_UpperCAmelCase    :						Union[str, Any]							=      image_processor(images=lowerCAmelCase__  ,   return_tensors="pt"		)
										_UpperCAmelCase    :						Any							=      encoded_inputs.pixel_values.to(lowerCAmelCase__		)

										with torch.no_grad():
														_UpperCAmelCase    :						Tuple							=      model(lowerCAmelCase__		)

										_UpperCAmelCase    :						Any							=      outputs.logits.detach().cpu()

										_UpperCAmelCase    :						Any							=      image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase__  ,   target_sizes=[(500, 300)]		)
										_UpperCAmelCase    :						Dict							=      torch.Size((500, 300)		)
										self.assertEqual(segmentation[0].shape  ,   lowerCAmelCase__		)

										_UpperCAmelCase    :						int							=      image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase__		)
										_UpperCAmelCase    :						Any							=      torch.Size((128, 128)		)
										self.assertEqual(segmentation[0].shape  ,   lowerCAmelCase__		)





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
					from transformers import TvltImageProcessor

if is_speech_available():
					from transformers import TvltFeatureExtractor

from transformers import TvltProcessor

@require_torch
class 			a					(		unittest.TestCase			):


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						int							=      "ZinengTang/tvlt-base"
										_UpperCAmelCase    :						int							=      tempfile.mkdtemp()


						def     _UpperCAmelCase			(    self  ,   **A_		):







										'''simple docstring'''


										return TvltImageProcessor.from_pretrained(self.checkpoint  ,   **A_		)


						def     _UpperCAmelCase			(    self  ,   **A_		):







										'''simple docstring'''


										return TvltFeatureExtractor.from_pretrained(self.checkpoint  ,   **A_		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										shutil.rmtree(self.tmpdirname		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Dict							=      self.get_image_processor()
										_UpperCAmelCase    :						Optional[int]							=      self.get_feature_extractor()

										_UpperCAmelCase    :						Tuple							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)
										processor.save_pretrained(self.tmpdirname		)
										_UpperCAmelCase    :						str							=      TvltProcessor.from_pretrained(self.tmpdirname		)

										self.assertIsInstance(processor.feature_extractor  ,   A_		)
										self.assertIsInstance(processor.image_processor  ,   A_		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[Any]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

										_UpperCAmelCase    :						Tuple							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)

										_UpperCAmelCase    :						List[str]							=      np.ones([12000]		)

										_UpperCAmelCase    :						int							=      feature_extractor(A_  ,   return_tensors="np"		)
										_UpperCAmelCase    :						int							=      processor(audio=A_  ,   return_tensors="np"		)

										for key in audio_dict.keys():
														self.assertAlmostEqual(audio_dict[key].sum()  ,   input_processor[key].sum()  ,   delta=1e-2		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[str]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

										_UpperCAmelCase    :						Optional[Any]							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)

										_UpperCAmelCase    :						Union[str, Any]							=      np.ones([3, 224, 224]		)

										_UpperCAmelCase    :						Tuple							=      image_processor(A_  ,   return_tensors="np"		)
										_UpperCAmelCase    :						List[str]							=      processor(images=A_  ,   return_tensors="np"		)

										for key in image_dict.keys():
														self.assertAlmostEqual(image_dict[key].sum()  ,   input_processor[key].sum()  ,   delta=1e-2		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[str]							=      self.get_image_processor()
										_UpperCAmelCase    :						Any							=      self.get_feature_extractor()

										_UpperCAmelCase    :						Dict							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)

										_UpperCAmelCase    :						str							=      np.ones([12000]		)
										_UpperCAmelCase    :						Optional[Any]							=      np.ones([3, 224, 224]		)

										_UpperCAmelCase    :						List[Any]							=      processor(audio=A_  ,   images=A_		)

										self.assertListEqual(list(inputs.keys()		)  ,   ["audio_values", "audio_mask", "pixel_values", "pixel_mask"]		)

										# test if it raises when no input is passed
										with pytest.raises(A_		):
														processor()





						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

										_UpperCAmelCase    :						str							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)

										self.assertListEqual(
										    processor.model_input_names  ,   image_processor.model_input_names + feature_extractor.model_input_names  ,   msg="`processor` and `image_processor`+`feature_extractor` model input names do not match"  ,   )


