

import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
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


lowerCAmelCase__		      =       random.Random()



def     lowerCAmelCase__							(		SCREAMING_SNAKE_CASE_:							str		,				SCREAMING_SNAKE_CASE_:							Optional[int]=1.0		,				SCREAMING_SNAKE_CASE_:							Tuple=None		,				SCREAMING_SNAKE_CASE_:							Dict=None					)	->					List[Any]:




				'''simple docstring'''





				if rng is None:
								A__						=	global_rng

				A__						=	[]
				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     a__  (    unittest.TestCase	):
			"""simple docstring"""







			def __init__(			self					,					lowercase					,					lowercase=7					,					lowercase=400					,					lowercase=2000					,					lowercase=1					,					lowercase=0.0					,					lowercase=16000					,					lowercase=True					,					lowercase=80					,					lowercase=16					,					lowercase=64					,					lowercase="hann_window"					,					lowercase=80					,					lowercase=7600					,					lowercase=1e-10					,					lowercase=True					,					)     ->  Union[str, Any]:
							'''simple docstring'''






							A__						=	parent
							A__						=	batch_size
							A__						=	min_seq_length
							A__						=	max_seq_length
							A__						=	(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
							A__						=	feature_size
							A__						=	padding_value
							A__						=	sampling_rate
							A__						=	do_normalize
							A__						=	num_mel_bins
							A__						=	hop_length
							A__						=	win_length
							A__						=	win_function
							A__						=	fmin
							A__						=	fmax
							A__						=	mel_floor
							A__						=	return_attention_mask


			def    UpperCamelCase						(			self				)     ->  str:
							'''simple docstring'''






							return {
							    "feature_size": self.feature_size,
							    "padding_value": self.padding_value,
							    "sampling_rate": self.sampling_rate,
							    "do_normalize": self.do_normalize,
							    "num_mel_bins": self.num_mel_bins,
							    "hop_length": self.hop_length,
							    "win_length": self.win_length,
							    "win_function": self.win_function,
							    "fmin": self.fmin,
							    "fmax": self.fmax,
							    "mel_floor": self.mel_floor,
							    "return_attention_mask": self.return_attention_mask,
							}


			def    UpperCamelCase						(			self					,					lowercase=False					,					lowercase=False				)     ->  Union[str, Any]:
							'''simple docstring'''






							def _flatten(lowercase				):
											return list(itertools.chain(*lowercase				)				)

							if equal_length:
											A__						=	floats_list((self.batch_size, self.max_seq_length)				)
							else:
											# make sure that inputs increase in size
											A__						=	[
											    _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:
											A__						=	[np.asarray(lowercase				) for x in speech_inputs]

							return speech_inputs


			def    UpperCamelCase						(			self					,					lowercase=False					,					lowercase=False				)     ->  Union[str, Any]:
							'''simple docstring'''






							if equal_length:
											A__						=	[floats_list((self.max_seq_length, self.num_mel_bins)				) for _ in range(self.batch_size				)]
							else:
											# make sure that inputs increase in size
											A__						=	[
											    floats_list((x, self.num_mel_bins)				)
											    for x in range(self.min_seq_length					,					self.max_seq_length					,					self.seq_length_diff				)
											]

							if numpify:
											A__						=	[np.asarray(lowercase				) for x in speech_inputs]

							return speech_inputs

@require_torch
class     a__  (    snake_case							,		unittest.TestCase	):
			"""simple docstring"""







			__lowerCamelCase       				=				SpeechTaFeatureExtractor


			def    UpperCamelCase						(			self				)     ->  int:
							'''simple docstring'''






							A__						=	SpeechTaFeatureExtractionTester(self				)


			def    UpperCamelCase						(			self					,					lowercase				)     ->  Dict:
							'''simple docstring'''






							self.assertTrue(np.all(np.mean(lowercase					,					axis=0				) < 1e-3				)				)
							self.assertTrue(np.all(np.abs(np.var(lowercase					,					axis=0				) - 1				) < 1e-3				)				)


			def    UpperCamelCase						(			self				)     ->  Optional[Any]:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							# create three inputs of length 800, 1000, and 1200
							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]
							A__						=	[np.asarray(lowercase				) for speech_input in speech_inputs]

							# Test not batched input
							A__						=	feat_extract(speech_inputs[0]					,					return_tensors="np"				).input_values
							A__						=	feat_extract(np_speech_inputs[0]					,					return_tensors="np"				).input_values
							self.assertTrue(np.allclose(lowercase					,					lowercase					,					atol=1e-3				)				)

							# Test batched
							A__						=	feat_extract(lowercase					,					return_tensors="np"				).input_values
							A__						=	feat_extract(lowercase					,					return_tensors="np"				).input_values
							for enc_seq_a, enc_seq_a in zip(lowercase					,					lowercase				):
											self.assertTrue(np.allclose(lowercase					,					lowercase					,					atol=1e-3				)				)


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]

							A__						=	["longest", "max_length", "do_not_pad"]
							A__						=	[None, 1600, None]
							for max_length, padding in zip(lowercase					,					lowercase				):
											A__						=	feat_extract(lowercase					,					padding=lowercase					,					max_length=lowercase					,					return_tensors="np"				)
											A__						=	processed.input_values

											self._check_zero_mean_unit_variance(input_values[0][:800]				)
											self.assertTrue(input_values[0][800:].sum() < 1e-6				)
											self._check_zero_mean_unit_variance(input_values[1][:1000]				)
											self.assertTrue(input_values[0][1000:].sum() < 1e-6				)
											self._check_zero_mean_unit_variance(input_values[2][:1200]				)


			def    UpperCamelCase						(			self				)     ->  Dict:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							A__						=	range(800					,					1400					,					200				)
							A__						=	[floats_list((1, x)				)[0] for x in lengths]

							A__						=	["longest", "max_length", "do_not_pad"]
							A__						=	[None, 1600, None]

							for max_length, padding in zip(lowercase					,					lowercase				):
											A__						=	feat_extract(lowercase					,					max_length=lowercase					,					padding=lowercase				)
											A__						=	processed.input_values

											self._check_zero_mean_unit_variance(input_values[0][:800]				)
											self._check_zero_mean_unit_variance(input_values[1][:1000]				)
											self._check_zero_mean_unit_variance(input_values[2][:1200]				)


			def    UpperCamelCase						(			self				)     ->  Optional[int]:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]
							A__						=	feat_extract(
							    lowercase					,					truncation=lowercase					,					max_length=1000					,					padding="max_length"					,					return_tensors="np"				)
							A__						=	processed.input_values

							self._check_zero_mean_unit_variance(input_values[0, :800]				)
							self._check_zero_mean_unit_variance(input_values[1]				)
							self._check_zero_mean_unit_variance(input_values[2]				)


			def    UpperCamelCase						(			self				)     ->  str:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]
							A__						=	feat_extract(
							    lowercase					,					truncation=lowercase					,					max_length=1000					,					padding="longest"					,					return_tensors="np"				)
							A__						=	processed.input_values

							self._check_zero_mean_unit_variance(input_values[0, :800]				)
							self._check_zero_mean_unit_variance(input_values[1, :1000]				)
							self._check_zero_mean_unit_variance(input_values[2]				)

							# make sure that if max_length < longest -> then pad to max_length
							self.assertTrue(input_values.shape == (3, 1000)				)

							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]
							A__						=	feat_extract(
							    lowercase					,					truncation=lowercase					,					max_length=2000					,					padding="longest"					,					return_tensors="np"				)
							A__						=	processed.input_values

							self._check_zero_mean_unit_variance(input_values[0, :800]				)
							self._check_zero_mean_unit_variance(input_values[1, :1000]				)
							self._check_zero_mean_unit_variance(input_values[2]				)

							# make sure that if max_length > longest -> then pad to longest
							self.assertTrue(input_values.shape == (3, 1200)				)


			def    UpperCamelCase						(			self				)     ->  int:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							A__						=	np.random.rand(100				).astype(np.floataa				)
							A__						=	np_speech_inputs.tolist()

							for inputs in [py_speech_inputs, np_speech_inputs]:
											A__						=	feature_extractor.pad([{"input_values": inputs}]					,					return_tensors="np"				)
											self.assertTrue(np_processed.input_values.dtype == np.floataa				)
											A__						=	feature_extractor.pad([{"input_values": inputs}]					,					return_tensors="pt"				)
											self.assertTrue(pt_processed.input_values.dtype == torch.floataa				)


			def    UpperCamelCase						(			self				)     ->  Union[str, Any]:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
							# create three inputs of length 800, 1000, and 1200
							A__						=	[floats_list((1, x)				)[0] for x in range(800					,					1400					,					200				)]
							A__						=	[np.asarray(lowercase				) for speech_input in speech_inputs]

							# Test feature size
							A__						=	feature_extractor(audio_target=lowercase					,					padding=lowercase					,					return_tensors="np"				).input_values
							self.assertTrue(input_values.ndim == 3				)
							self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins				)

							# Test not batched input
							A__						=	feature_extractor(speech_inputs[0]					,					return_tensors="np"				).input_values
							A__						=	feature_extractor(np_speech_inputs[0]					,					return_tensors="np"				).input_values
							self.assertTrue(np.allclose(lowercase					,					lowercase					,					atol=1e-3				)				)

							# Test batched
							A__						=	feature_extractor(lowercase					,					return_tensors="np"				).input_values
							A__						=	feature_extractor(lowercase					,					return_tensors="np"				).input_values
							for enc_seq_a, enc_seq_a in zip(lowercase					,					lowercase				):
											self.assertTrue(np.allclose(lowercase					,					lowercase					,					atol=1e-3				)				)

							# Test 2-D numpy arrays are batched.
							A__						=	[floats_list((1, x)				)[0] for x in (800, 800, 800)]
							A__						=	np.asarray(lowercase				)
							A__						=	feature_extractor(lowercase					,					return_tensors="np"				).input_values
							A__						=	feature_extractor(lowercase					,					return_tensors="np"				).input_values
							for enc_seq_a, enc_seq_a in zip(lowercase					,					lowercase				):
											self.assertTrue(np.allclose(lowercase					,					lowercase					,					atol=1e-3				)				)


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	self.feat_extract_tester.prepare_inputs_for_target()
							A__						=	self.feature_extraction_class(**self.feat_extract_dict				)
							A__						=	feat_extract.model_input_names[0]

							A__						=	BatchFeature({input_name: speech_inputs}				)

							self.assertTrue(all(len(lowercase				) == len(lowercase				) for x, y in zip(lowercase					,					processed_features[input_name]				)				)				)

							A__						=	self.feat_extract_tester.prepare_inputs_for_target(equal_length=lowercase				)
							A__						=	BatchFeature({input_name: speech_inputs}					,					tensor_type="np"				)

							A__						=	processed_features[input_name]

							if len(batch_features_input.shape				) < 3:
											A__						=	batch_features_input[:, :, None]

							self.assertTrue(
							    batch_features_input.shape
							    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]				), self.feat_extract_tester.num_mel_bins)				)


			@require_torch
			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	self.feat_extract_tester.prepare_inputs_for_target(equal_length=lowercase				)
							A__						=	self.feature_extraction_class(**self.feat_extract_dict				)
							A__						=	feat_extract.model_input_names[0]

							A__						=	BatchFeature({input_name: speech_inputs}					,					tensor_type="pt"				)

							A__						=	processed_features[input_name]

							if len(batch_features_input.shape				) < 3:
											A__						=	batch_features_input[:, :, None]

							self.assertTrue(
							    batch_features_input.shape
							    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]				), self.feat_extract_tester.num_mel_bins)				)


			@require_torch
			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							A__						=	self.feature_extraction_class(**self.feat_extract_dict				)
							A__						=	self.feat_extract_tester.prepare_inputs_for_target()
							A__						=	feat_extract.model_input_names[0]

							A__						=	BatchFeature({input_name: speech_inputs}				)

							A__						=	feat_extract.num_mel_bins  # hack!

							A__						=	feat_extract.pad(lowercase					,					padding="longest"					,					return_tensors="np"				)[input_name]
							A__						=	feat_extract.pad(lowercase					,					padding="longest"					,					return_tensors="pt"				)[input_name]

							self.assertTrue(abs(input_np.astype(np.floataa				).sum() - input_pt.numpy().astype(np.floataa				).sum()				) < 1e-2				)


			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							A__						=	self.feat_extract_dict
							A__						=	True
							A__						=	self.feature_extraction_class(**lowercase				)
							A__						=	self.feat_extract_tester.prepare_inputs_for_target()
							A__						=	[len(lowercase				) for x in speech_inputs]
							A__						=	feat_extract.model_input_names[0]

							A__						=	BatchFeature({input_name: speech_inputs}				)

							A__						=	feat_extract.num_mel_bins  # hack!

							A__						=	feat_extract.pad(lowercase					,					padding="longest"					,					return_tensors="np"				)
							self.assertIn("attention_mask"					,					lowercase				)
							self.assertListEqual(list(processed.attention_mask.shape				)					,					list(processed[input_name].shape[:2]				)				)
							self.assertListEqual(processed.attention_mask.sum(-1				).tolist()					,					lowercase				)


			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							A__						=	self.feat_extract_dict
							A__						=	True
							A__						=	self.feature_extraction_class(**lowercase				)
							A__						=	self.feat_extract_tester.prepare_inputs_for_target()
							A__						=	[len(lowercase				) for x in speech_inputs]
							A__						=	feat_extract.model_input_names[0]

							A__						=	BatchFeature({input_name: speech_inputs}				)
							A__						=	min(lowercase				)

							A__						=	feat_extract.num_mel_bins  # hack!

							A__						=	feat_extract.pad(
							    lowercase					,					padding="max_length"					,					max_length=lowercase					,					truncation=lowercase					,					return_tensors="np"				)
							self.assertIn("attention_mask"					,					lowercase				)
							self.assertListEqual(
							    list(processed_pad.attention_mask.shape				)					,					[processed_pad[input_name].shape[0], max_length]				)
							self.assertListEqual(
							    processed_pad.attention_mask[:, :max_length].sum(-1				).tolist()					,					[max_length for x in speech_inputs]				)


			def    UpperCamelCase						(			self					,					lowercase				)     ->  Tuple:
							'''simple docstring'''






							from datasets import load_dataset

							A__						=	load_dataset("hf-internal-testing/librispeech_asr_dummy"					,					"clean"					,					split="validation"				)
							# automatic decoding with librispeech
							A__						=	ds.sort("id"				).select(range(lowercase				)				)[:num_samples]["audio"]

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


			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							A__						=	torch.tensor(
							    [2.38_04e-03, 2.07_52e-03, 1.98_36e-03, 2.10_57e-03, 1.61_74e-03,
							     3.05_18e-04, 9.15_53e-05, 3.35_69e-04, 9.76_56e-04, 1.83_11e-03,
							     2.01_42e-03, 2.10_57e-03, 1.73_95e-03, 4.57_76e-04, -3.96_73e-04,
							     4.57_76e-04, 1.00_71e-03, 9.15_53e-05, 4.88_28e-04, 1.15_97e-03,
							     7.32_42e-04, 9.46_04e-04, 1.80_05e-03, 1.83_11e-03, 8.85_01e-04,
							     4.27_25e-04, 4.88_28e-04, 7.32_42e-04, 1.09_86e-03, 2.10_57e-03]				)
							# fmt: on

							A__						=	self._load_datasamples(1				)
							A__						=	SpeechTaFeatureExtractor()
							A__						=	feature_extractor(lowercase					,					return_tensors="pt"				).input_values
							self.assertEquals(input_values.shape					,					(1, 93680)				)
							self.assertTrue(torch.allclose(input_values[0, :30]					,					lowercase					,					atol=1e-6				)				)


			def    UpperCamelCase						(			self				)     ->  List[str]:
							'''simple docstring'''






							A__						=	torch.tensor(
							    [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
							     -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
							     -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
							     -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]				)
							# fmt: on

							A__						=	self._load_datasamples(1				)
							A__						=	SpeechTaFeatureExtractor()
							A__						=	feature_extractor(audio_target=lowercase					,					return_tensors="pt"				).input_values
							self.assertEquals(input_values.shape					,					(1, 366, 80)				)
							self.assertTrue(torch.allclose(input_values[0, 0, :30]					,					lowercase					,					atol=1e-4				)				)


"""simple docstring"""




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
				import PIL


__lowerCamelCase							 =     logging.get_logger(__name__)






def      UpperCAmelCase    (		UpperCamelCase__				,			UpperCamelCase__ ):






							"""simple docstring"""





							A__		   =							b.T
							A__		   =							np.sum(np.square(UpperCamelCase__ )				,			axis=1 )
							A__		   =							np.sum(np.square(UpperCamelCase__ )				,			axis=0 )
							A__		   =							np.matmul(UpperCamelCase__				,			UpperCamelCase__ )
							A__		   =							aa[:, None] - 2 * ab + ba[None, :]
							return d






def      UpperCAmelCase    (		UpperCamelCase__				,			UpperCamelCase__ ):






							"""simple docstring"""





							A__		   =							x.reshape(-1				,			3 )
							A__		   =							squared_euclidean_distance(UpperCamelCase__				,			UpperCamelCase__ )
							return np.argmin(UpperCamelCase__				,			axis=1 )


class 			UpperCamelCase__(	__A       ):
						lowerCAmelCase__     :  Tuple  							=						['pixel_values']





						def __init__(				self						,__UpperCAmelCase = None						,__UpperCAmelCase = True						,__UpperCAmelCase = None						,__UpperCAmelCase = PILImageResampling.BILINEAR						,__UpperCAmelCase = True						,__UpperCAmelCase = True						,**__UpperCAmelCase						,)    -> None:
													super().__init__(**__UpperCAmelCase   )
													A__		   =							size if size is not None else {'height': 2_56, 'width': 2_56}
													A__		   =							get_size_dict(__UpperCAmelCase   )
													A__		   =							np.array(__UpperCAmelCase   ) if clusters is not None else None
													A__		   =							do_resize
													A__		   =							size
													A__		   =							resample
													A__		   =							do_normalize
													A__		   =							do_color_quantize





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase = PILImageResampling.BILINEAR						,__UpperCAmelCase = None						,**__UpperCAmelCase						,)    -> np.ndarray:
													A__		   =							get_size_dict(__UpperCAmelCase   )
													if "height" not in size or "width" not in size:
																				raise ValueError(f'''Size dictionary must contain both height and width keys. Got {size.keys()}'''   )
													return resize(
													    __UpperCAmelCase						,size=(size['height'], size['width'])						,resample=__UpperCAmelCase						,data_format=__UpperCAmelCase						,**__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase = None						,)    -> np.ndarray:
													A__		   =							rescale(image=__UpperCAmelCase						,scale=1 / 1_2_7.5						,data_format=__UpperCAmelCase   )
													A__		   =							image - 1
													return image





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = None						,__UpperCAmelCase = ChannelDimension.FIRST						,**__UpperCAmelCase						,)    -> PIL.Image.Image:
													A__		   =							do_resize if do_resize is not None else self.do_resize
													A__		   =							size if size is not None else self.size
													A__		   =							get_size_dict(__UpperCAmelCase   )
													A__		   =							resample if resample is not None else self.resample
													A__		   =							do_normalize if do_normalize is not None else self.do_normalize
													A__		   =							do_color_quantize if do_color_quantize is not None else self.do_color_quantize
													A__		   =							clusters if clusters is not None else self.clusters
													A__		   =							np.array(__UpperCAmelCase   )

													A__		   =							make_list_of_images(__UpperCAmelCase   )

													if not valid_images(__UpperCAmelCase   ):
																				raise ValueError(
																				    'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
																				    'torch.Tensor, tf.Tensor or jax.ndarray.'   )

													if do_resize and size is None or resample is None:
																				raise ValueError('Size and resample must be specified if do_resize is True.'   )

													if do_color_quantize and clusters is None:
																				raise ValueError('Clusters must be specified if do_color_quantize is True.'   )

													# All transformations expect numpy arrays.
													A__		   =							[to_numpy_array(__UpperCAmelCase   ) for image in images]

													if do_resize:
																				A__		   =							[self.resize(image=__UpperCAmelCase						,size=__UpperCAmelCase						,resample=__UpperCAmelCase   ) for image in images]

													if do_normalize:
																				A__		   =							[self.normalize(image=__UpperCAmelCase   ) for image in images]

													if do_color_quantize:
																				A__		   =							[to_channel_dimension_format(__UpperCAmelCase						,ChannelDimension.LAST   ) for image in images]
																				# color quantize from (batch_size, height, width, 3) to (batch_size, height, width)
																				A__		   =							np.array(__UpperCAmelCase   )
																				A__		   =							color_quantize(__UpperCAmelCase						,__UpperCAmelCase   ).reshape(images.shape[:-1]   )

																				# flatten to (batch_size, height*width)
																				A__		   =							images.shape[0]
																				A__		   =							images.reshape(__UpperCAmelCase						,-1   )

																				# We need to convert back to a list of images to keep consistent behaviour across processors.
																				A__		   =							list(__UpperCAmelCase   )
													else:
																				A__		   =							[to_channel_dimension_format(__UpperCAmelCase						,__UpperCAmelCase   ) for image in images]

													A__		   =							{'input_ids': images}
													return BatchFeature(data=__UpperCAmelCase						,tensor_type=__UpperCAmelCase   )





