






'''simple docstring'''







import itertools
import random
import unittest

import numpy as np

from transformers import EncodecFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
  import torch


UpperCamelCase_					=				random.Random()






def  lowerCAmelCase__		(					a_  :     Tuple			,						a_  :     int=1.0			,						a_  :     Optional[Any]=None			,						a_  :     int=None			)   -> Any:
       if rng is None:
              UpperCAmelCase__	:   List[Any]												=	global_rng

       UpperCAmelCase__	:   str												=	[]
       for batch_idx in range(shape[0]			):
              values.append([]			)
              for _ in range(shape[1]			):
                     values[-1].append(rng.random() * scale			)

       return values




@require_torch
class 					__UpperCAmelCase (		unittest.TestCase	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase=7  ,		_UpperCAmelCase=400  ,		_UpperCAmelCase=2000  ,		_UpperCAmelCase=1  ,		_UpperCAmelCase=0.0  ,		_UpperCAmelCase=2_4000  ,		_UpperCAmelCase=True  ,		):
             UpperCAmelCase__	:   str												=	parent
             UpperCAmelCase__	:   Optional[Any]												=	batch_size
             UpperCAmelCase__	:   Dict												=	min_seq_length
             UpperCAmelCase__	:   Union[str, Any]												=	max_seq_length
             UpperCAmelCase__	:   Tuple												=	(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
             UpperCAmelCase__	:   List[Any]												=	feature_size
             UpperCAmelCase__	:   str												=	padding_value
             UpperCAmelCase__	:   List[Any]												=	sampling_rate
             UpperCAmelCase__	:   Optional[Any]												=	return_attention_mask




      def 							lowerCamelCase     (					self						):
             return {
                 "feature_size": self.feature_size,
                 "padding_value": self.padding_value,
                 "sampling_rate": self.sampling_rate,
                 "return_attention_mask": self.return_attention_mask,
             }




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase=False  ,		_UpperCAmelCase=False						):
             def _flatten(_UpperCAmelCase						):
                    return list(itertools.chain(*_UpperCAmelCase						)						)

             if equal_length:
                    UpperCAmelCase__	:   Dict												=	floats_list((self.batch_size, self.max_seq_length)						)
             else:
                    # make sure that inputs increase in size
                    UpperCAmelCase__	:   Any												=	[
                        _flatten(floats_list((x, self.feature_size)						)						)
                        for x in range(self.min_seq_length  ,		self.max_seq_length  ,		self.seq_length_diff						)
                    ]

             if numpify:
                    UpperCAmelCase__	:   str												=	[np.asarray(_UpperCAmelCase						) for x in audio_inputs]

             return audio_inputs




@require_torch
class 					__UpperCAmelCase (		UpperCamelCase__      ,				unittest.TestCase	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    Tuple				       =					EncodecFeatureExtractor




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   str												=	EnCodecFeatureExtractionTester(self						)




      def 							lowerCamelCase     (					self						):
             # Tests that all call wrap to encode_plus and batch_encode_plus
             UpperCAmelCase__	:   Optional[Any]												=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
             # create three inputs of length 800, 1000, and 1200
             UpperCAmelCase__	:   Optional[int]												=	[floats_list((1, x)						)[0] for x in range(800  ,		1400  ,		200						)]
             UpperCAmelCase__	:   Optional[int]												=	[np.asarray(_UpperCAmelCase						) for audio_input in audio_inputs]

             # Test not batched input
             UpperCAmelCase__	:   List[str]												=	feat_extract(audio_inputs[0]  ,		return_tensors='''np'''						).input_values
             UpperCAmelCase__	:   Union[str, Any]												=	feat_extract(np_audio_inputs[0]  ,		return_tensors='''np'''						).input_values
             self.assertTrue(np.allclose(_UpperCAmelCase  ,		_UpperCAmelCase  ,		atol=1E-3						)						)

             # Test batched
             UpperCAmelCase__	:   Dict												=	feat_extract(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''np'''						).input_values
             UpperCAmelCase__	:   int												=	feat_extract(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''np'''						).input_values
             for enc_seq_a, enc_seq_a in zip(_UpperCAmelCase  ,		_UpperCAmelCase						):
                    self.assertTrue(np.allclose(_UpperCAmelCase  ,		_UpperCAmelCase  ,		atol=1E-3						)						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Optional[Any]												=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
             UpperCAmelCase__	:   Optional[int]												=	np.random.rand(100						).astype(np.floataa						)
             UpperCAmelCase__	:   Tuple												=	np_audio_inputs.tolist()

             for inputs in [py_audio_inputs, np_audio_inputs]:
                    UpperCAmelCase__	:   Optional[Any]												=	feature_extractor.pad([{'''input_values''': inputs}]  ,		return_tensors='''np'''						)
                    self.assertTrue(np_processed.input_values.dtype == np.floataa						)
                    UpperCAmelCase__	:   Tuple												=	feature_extractor.pad([{'''input_values''': inputs}]  ,		return_tensors='''pt'''						)
                    self.assertTrue(pt_processed.input_values.dtype == torch.floataa						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             from datasets import load_dataset

             UpperCAmelCase__	:   Tuple												=	load_dataset('''hf-internal-testing/librispeech_asr_dummy'''  ,		'''clean'''  ,		split='''validation'''						)
             # automatic decoding with librispeech
             UpperCAmelCase__	:   List[Any]												=	ds.sort('''id'''						).select(range(_UpperCAmelCase						)						)[:num_samples]['''audio''']

             return [x["array"] for x in audio_samples]




      def 							lowerCamelCase     (					self						):
             # fmt: off
             UpperCAmelCase__	:   List[Any]												=	torch.tensor(
                 [2.3804E-03, 2.0752E-03, 1.9836E-03, 2.1057E-03, 1.6174E-03,
                  3.0518E-04, 9.1553E-05, 3.3569E-04, 9.7656E-04, 1.8311E-03,
                  2.0142E-03, 2.1057E-03, 1.7395E-03, 4.5776E-04, -3.9673E-04,
                  4.5776E-04, 1.0071E-03, 9.1553E-05, 4.8828E-04, 1.1597E-03,
                  7.3242E-04, 9.4604E-04, 1.8005E-03, 1.8311E-03, 8.8501E-04,
                  4.2725E-04, 4.8828E-04, 7.3242E-04, 1.0986E-03, 2.1057E-03]						)
             # fmt: on
             UpperCAmelCase__	:   Optional[int]												=	self._load_datasamples(1						)
             UpperCAmelCase__	:   Optional[Any]												=	EncodecFeatureExtractor()
             UpperCAmelCase__	:   Optional[int]												=	feature_extractor(_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(input_values.shape  ,		(1, 1, 9_3680)						)
             self.assertTrue(torch.allclose(input_values[0, 0, :30]  ,		_UpperCAmelCase  ,		atol=1E-6						)						)




      def 							lowerCamelCase     (					self						):
             # fmt: off
             UpperCAmelCase__	:   Dict												=	torch.tensor(
                 [2.3804E-03, 2.0752E-03, 1.9836E-03, 2.1057E-03, 1.6174E-03,
                  3.0518E-04, 9.1553E-05, 3.3569E-04, 9.7656E-04, 1.8311E-03,
                  2.0142E-03, 2.1057E-03, 1.7395E-03, 4.5776E-04, -3.9673E-04,
                  4.5776E-04, 1.0071E-03, 9.1553E-05, 4.8828E-04, 1.1597E-03,
                  7.3242E-04, 9.4604E-04, 1.8005E-03, 1.8311E-03, 8.8501E-04,
                  4.2725E-04, 4.8828E-04, 7.3242E-04, 1.0986E-03, 2.1057E-03]						)
             # fmt: on
             UpperCAmelCase__	:   Tuple												=	self._load_datasamples(1						)
             UpperCAmelCase__	:   Any												=	[np.tile(input_audio[0][None]  ,		reps=(2, 1)						)]
             input_audio[0][1] *= 0.5
             UpperCAmelCase__	:   List[Any]												=	EncodecFeatureExtractor(feature_size=2						)
             UpperCAmelCase__	:   Dict												=	feature_extractor(_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(input_values.shape  ,		(1, 2, 9_3680)						)
             self.assertTrue(torch.allclose(input_values[0, 0, :30]  ,		_UpperCAmelCase  ,		atol=1E-6						)						)
             self.assertTrue(torch.allclose(input_values[0, 1, :30]  ,		EXPECTED_INPUT_VALUES * 0.5  ,		atol=1E-6						)						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   str												=	self._load_datasamples(2						)
             # would be easier if the stride was like
             UpperCAmelCase__	:   Tuple												=	EncodecFeatureExtractor(feature_size=1  ,		chunk_length_s=1  ,		overlap=0.01						)

             # pad and trunc raise an error ?
             with self.assertRaisesRegex(
                 _UpperCAmelCase  ,		'''^Both padding and truncation were set. Make sure you only set one.$'''  ,		):
                    UpperCAmelCase__	:   Optional[Any]												=	feature_extractor(
                        _UpperCAmelCase  ,		padding='''max_length'''  ,		truncation=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values

             # truncate to chunk
             UpperCAmelCase__	:   Any												=	feature_extractor(_UpperCAmelCase  ,		truncation=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(2, 1, 7_1520)						)  # 2 chunks

             # force truncate to max_length
             UpperCAmelCase__	:   Any												=	feature_extractor(
                 _UpperCAmelCase  ,		truncation=_UpperCAmelCase  ,		max_length=4_8000  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(2, 1, 4_8000)						)

             # pad to chunk
             UpperCAmelCase__	:   Optional[Any]												=	feature_extractor(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(padded_outputs.shape  ,		(2, 1, 9_5280)						)

             # pad to chunk
             UpperCAmelCase__	:   str												=	feature_extractor(_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(2, 1, 9_5280)						)

             # force pad to max length
             UpperCAmelCase__	:   Any												=	feature_extractor(
                 _UpperCAmelCase  ,		padding='''max_length'''  ,		max_length=10_0000  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(2, 1, 10_0000)						)

             # force no pad
             with self.assertRaisesRegex(
                 _UpperCAmelCase  ,		'''^Unable to create tensor, you should probably activate padding with \'padding=True\' to have batched tensors with the same length.$'''  ,		):
                    UpperCAmelCase__	:   str												=	feature_extractor(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values

             UpperCAmelCase__	:   Union[str, Any]												=	feature_extractor(input_audio[0]  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(1, 1, 9_3680)						)

             # no pad if no chunk_length_s
             UpperCAmelCase__	:   int												=	None
             with self.assertRaisesRegex(
                 _UpperCAmelCase  ,		'''^Unable to create tensor, you should probably activate padding with \'padding=True\' to have batched tensors with the same length.$'''  ,		):
                    UpperCAmelCase__	:   Union[str, Any]												=	feature_extractor(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values

             UpperCAmelCase__	:   int												=	feature_extractor(input_audio[0]  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(1, 1, 9_3680)						)

             # no pad if no overlap
             UpperCAmelCase__	:   Optional[int]												=	2
             UpperCAmelCase__	:   Optional[Any]												=	None
             with self.assertRaisesRegex(
                 _UpperCAmelCase  ,		'''^Unable to create tensor, you should probably activate padding with \'padding=True\' to have batched tensors with the same length.$'''  ,		):
                    UpperCAmelCase__	:   Tuple												=	feature_extractor(_UpperCAmelCase  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values

             UpperCAmelCase__	:   Union[str, Any]												=	feature_extractor(input_audio[0]  ,		padding=_UpperCAmelCase  ,		return_tensors='''pt'''						).input_values
             self.assertEquals(truncated_outputs.shape  ,		(1, 1, 9_3680)						)





import random
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		import PIL

		from transformers import FlavaImageProcessor
		from transformers.image_utils import PILImageResampling
		from transformers.models.flava.image_processing_flava import (
		    FLAVA_CODEBOOK_MEAN,
		    FLAVA_CODEBOOK_STD,
		    FLAVA_IMAGE_MEAN,
		    FLAVA_IMAGE_STD,
		)
else:
		__A    :				List[str]    						=	None




class       UpperCAmelCase_   ( unittest.TestCase							):




							'''simple docstring'''



							def __init__(       self							:						Dict							,  a							:						List[Any]							,  a							:						Tuple=7							,  a							:						Dict=3							,  a							:						List[Any]=30							,  a							:						List[Any]=400							,  a							:						Optional[Any]=True							,  a							:						Optional[int]=None							,  a							:						Any=True							,  a							:						Union[str, Any]=None							,  a							:						Union[str, Any]=None							,  a							:						List[Any]=True							,  a							:						Union[str, Any]=1 / 255							,  a							:						Optional[Any]=True							,  a							:						int=FLAVA_IMAGE_MEAN							,  a							:						int=FLAVA_IMAGE_STD							,  a							:						Tuple=14							,  a							:						str=75							,  a							:						str=None							,  a							:						int=16							,  a							:						List[str]=0.3							,  a							:						Optional[Any]=None							,  a							:						int=True							,  a							:						int=None							,  a							:						Optional[int]=None							,  a							:						Optional[Any]=True							,  a							:						List[Any]=None							,  a							:						str=True							,  a							:						int=True							,  a							:						str=FLAVA_CODEBOOK_MEAN							,  a							:						str=FLAVA_CODEBOOK_STD							,  )      ->       List[str]:
										SCREAMING_SNAKE_CASE     =       size if size is not None else {"""height""": 224, """width""": 224}
										SCREAMING_SNAKE_CASE     =       crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
										SCREAMING_SNAKE_CASE     =       codebook_size if codebook_size is not None else {"""height""": 112, """width""": 112}
										SCREAMING_SNAKE_CASE     =       codebook_crop_size if codebook_crop_size is not None else {"""height""": 112, """width""": 112}

										SCREAMING_SNAKE_CASE     =       parent
										SCREAMING_SNAKE_CASE     =       batch_size
										SCREAMING_SNAKE_CASE     =       num_channels
										SCREAMING_SNAKE_CASE     =       do_resize
										SCREAMING_SNAKE_CASE     =       do_rescale
										SCREAMING_SNAKE_CASE     =       rescale_factor
										SCREAMING_SNAKE_CASE     =       min_resolution
										SCREAMING_SNAKE_CASE     =       max_resolution
										SCREAMING_SNAKE_CASE     =       size
										SCREAMING_SNAKE_CASE     =       resample if resample is not None else PILImageResampling.BICUBIC
										SCREAMING_SNAKE_CASE     =       do_normalize
										SCREAMING_SNAKE_CASE     =       image_mean
										SCREAMING_SNAKE_CASE     =       image_std
										SCREAMING_SNAKE_CASE     =       do_center_crop
										SCREAMING_SNAKE_CASE     =       crop_size

										SCREAMING_SNAKE_CASE     =       input_size_patches
										SCREAMING_SNAKE_CASE     =       total_mask_patches
										SCREAMING_SNAKE_CASE     =       mask_group_max_patches
										SCREAMING_SNAKE_CASE     =       mask_group_min_patches
										SCREAMING_SNAKE_CASE     =       mask_group_min_aspect_ratio
										SCREAMING_SNAKE_CASE     =       mask_group_max_aspect_ratio

										SCREAMING_SNAKE_CASE     =       codebook_do_resize
										SCREAMING_SNAKE_CASE     =       codebook_size
										SCREAMING_SNAKE_CASE     =       codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
										SCREAMING_SNAKE_CASE     =       codebook_do_center_crop
										SCREAMING_SNAKE_CASE     =       codebook_crop_size
										SCREAMING_SNAKE_CASE     =       codebook_do_map_pixels
										SCREAMING_SNAKE_CASE     =       codebook_do_normalize
										SCREAMING_SNAKE_CASE     =       codebook_image_mean
										SCREAMING_SNAKE_CASE     =       codebook_image_std





							def  _UpperCAmelCase  (       self							:						str      )      ->       str:
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "resample": self.resample,
										    "do_rescale": self.do_rescale,
										    "rescale_factor": self.rescale_factor,
										    "do_center_crop": self.do_center_crop,
										    "crop_size": self.crop_size,
										    "input_size_patches": self.input_size_patches,
										    "total_mask_patches": self.total_mask_patches,
										    "mask_group_max_patches": self.mask_group_max_patches,
										    "mask_group_min_patches": self.mask_group_min_patches,
										    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
										    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
										    "codebook_do_resize": self.codebook_do_resize,
										    "codebook_size": self.codebook_size,
										    "codebook_resample": self.codebook_resample,
										    "codebook_do_center_crop": self.codebook_do_center_crop,
										    "codebook_crop_size": self.codebook_crop_size,
										    "codebook_do_map_pixels": self.codebook_do_map_pixels,
										    "codebook_do_normalize": self.codebook_do_normalize,
										    "codebook_image_mean": self.codebook_image_mean,
										    "codebook_image_std": self.codebook_image_std,
										}





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       List[Any]:
										return (self.size["height"], self.size["width"])





							def  _UpperCAmelCase  (       self							:						int      )      ->       int:
										return (
										    (self.input_size_patches, self.input_size_patches)
										    if not isinstance(self.input_size_patches							,  a      )
										    else self.input_size_patches
										)







							def  _UpperCAmelCase  (       self							:						str      )      ->       List[Any]:
										return (self.codebook_size["height"], self.codebook_size["width"])





@require_torch
@require_vision
class       UpperCAmelCase_   ( A		,   unittest.TestCase							):




							'''simple docstring'''



							a__    	=  FlavaImageProcessor if is_vision_available() else None
							a__    	=  None





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Any:
										SCREAMING_SNAKE_CASE     =       FlavaImageProcessingTester(self      )





							@property
							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Any:
										return self.image_processor_tester.prepare_image_processor_dict()





							def  _UpperCAmelCase  (       self							:						Optional[int]      )      ->       str:
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										self.assertTrue(hasattr(a							,  """image_mean"""      )      )
										self.assertTrue(hasattr(a							,  """image_std"""      )      )
										self.assertTrue(hasattr(a							,  """do_normalize"""      )      )
										self.assertTrue(hasattr(a							,  """do_resize"""      )      )
										self.assertTrue(hasattr(a							,  """resample"""      )      )
										self.assertTrue(hasattr(a							,  """crop_size"""      )      )
										self.assertTrue(hasattr(a							,  """do_center_crop"""      )      )
										self.assertTrue(hasattr(a							,  """do_rescale"""      )      )
										self.assertTrue(hasattr(a							,  """rescale_factor"""      )      )
										self.assertTrue(hasattr(a							,  """masking_generator"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_resize"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_size"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_resample"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_center_crop"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_crop_size"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_map_pixels"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_normalize"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_image_mean"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_image_std"""      )      )





							def  _UpperCAmelCase  (       self							:						Union[str, Any]      )      ->       Optional[Any]:
										SCREAMING_SNAKE_CASE     =       self.image_processing_class.from_dict(self.image_processor_dict      )
										self.assertEqual(image_processor.size							,  {"""height""": 224, """width""": 224}      )
										self.assertEqual(image_processor.crop_size							,  {"""height""": 224, """width""": 224}      )
										self.assertEqual(image_processor.codebook_size							,  {"""height""": 112, """width""": 112}      )
										self.assertEqual(image_processor.codebook_crop_size							,  {"""height""": 112, """width""": 112}      )

										SCREAMING_SNAKE_CASE     =       self.image_processing_class.from_dict(
										    self.image_processor_dict							,  size=42							,  crop_size=84							,  codebook_size=33							,  codebook_crop_size=66      )
										self.assertEqual(image_processor.size							,  {"""height""": 42, """width""": 42}      )
										self.assertEqual(image_processor.crop_size							,  {"""height""": 84, """width""": 84}      )
										self.assertEqual(image_processor.codebook_size							,  {"""height""": 33, """width""": 33}      )
										self.assertEqual(image_processor.codebook_crop_size							,  {"""height""": 66, """width""": 66}      )





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





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       Union[str, Any]:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random PIL images
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  PIL.Image.Image      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_tensors="""pt"""      )

										# Test no bool masked pos
										self.assertFalse("""bool_masked_pos""" in encoded_images      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()

										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()

										# Test no bool masked pos
										self.assertFalse("""bool_masked_pos""" in encoded_images      )

										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )





							def  _UpperCAmelCase  (       self							:						Any							,  a							:						List[str]							,  a							:						Tuple      )      ->       Union[str, Any]:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random tensors
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a							,  **a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  a      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_image_mask=a							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_mask_size()
										self.assertEqual(
										    encoded_images.bool_masked_pos.shape							,  (
										        self.image_processor_tester.batch_size,
										        expected_height,
										        expected_width,
										    )							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_tensors="""pt"""      ).pixel_values

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										# Test masking
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_image_mask=a							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_mask_size()
										self.assertEqual(
										    encoded_images.bool_masked_pos.shape							,  (
										        self.image_processor_tester.batch_size,
										        expected_height,
										        expected_width,
										    )							,  )





							def  _UpperCAmelCase  (       self							:						Optional[int]      )      ->       Dict:
										self._test_call_framework(np.ndarray							,  prepare_kwargs={"""numpify""": True}      )





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Dict:
										self._test_call_framework(torch.Tensor							,  prepare_kwargs={"""torchify""": True}      )





							def  _UpperCAmelCase  (       self							:						str      )      ->       Optional[int]:
										# Initialize image_processing
										random.seed(1_234      )
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a							,  torchify=a      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_image_mask=a							,  return_tensors="""pt"""      )
										self.assertEqual(encoded_images.bool_masked_pos.sum().item()							,  75      )







							def  _UpperCAmelCase  (       self							:						List[str]      )      ->       Tuple:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random PIL images
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  PIL.Image.Image      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_codebook_pixels=a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_codebook_image_size()
										self.assertEqual(
										    encoded_images.codebook_pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_codebook_pixels=a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_codebook_image_size()
										self.assertEqual(
										    encoded_images.codebook_pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )






