import inspect
import unittest
import warnings
from math import ceil, floor

from transformers import LevitConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, 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_FOR_IMAGE_CLASSIFICATION_MAPPING,
				    MODEL_MAPPING,
				    LevitForImageClassification,
				    LevitForImageClassificationWithTeacher,
				    LevitModel,
				)
				from transformers.models.levit.modeling_levit import LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import LevitImageProcessor



class        lowerCamelCase__				(   UpperCAmelCase				):





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							self.config_class(**self.inputs_dict						)
										self.parent.assertTrue(hasattr(lowercase__  ,  'hidden_sizes'						)						)
										self.parent.assertTrue(hasattr(lowercase__  ,  'num_attention_heads'						)						)







class        lowerCamelCase__				:





			def __init__(       self	:	Optional[int]  ,  lowercase__	:	Dict  ,  lowercase__	:	int=13  ,  lowercase__	:	Dict=64  ,  lowercase__	:	List[Any]=3  ,  lowercase__	:	Optional[int]=3  ,  lowercase__	:	List[str]=2  ,  lowercase__	:	str=1  ,  lowercase__	:	Tuple=16  ,  lowercase__	:	str=[1_28, 2_56, 3_84]  ,  lowercase__	:	Any=[4, 6, 8]  ,  lowercase__	:	List[Any]=[2, 3, 4]  ,  lowercase__	:	List[Any]=[16, 16, 16]  ,  lowercase__	:	List[str]=0  ,  lowercase__	:	Tuple=[2, 2, 2]  ,  lowercase__	:	Union[str, Any]=[2, 2, 2]  ,  lowercase__	:	List[Any]=0.0_2  ,  lowercase__	:	List[str]=True  ,  lowercase__	:	List[str]=True  ,  lowercase__	:	str=2  ,  ):
										_lowerCAmelCase							=							parent
										_lowerCAmelCase							=							batch_size
										_lowerCAmelCase							=							image_size
										_lowerCAmelCase							=							num_channels
										_lowerCAmelCase							=							kernel_size
										_lowerCAmelCase							=							stride
										_lowerCAmelCase							=							padding
										_lowerCAmelCase							=							hidden_sizes
										_lowerCAmelCase							=							num_attention_heads
										_lowerCAmelCase							=							depths
										_lowerCAmelCase							=							key_dim
										_lowerCAmelCase							=							drop_path_rate
										_lowerCAmelCase							=							patch_size
										_lowerCAmelCase							=							attention_ratio
										_lowerCAmelCase							=							mlp_ratio
										_lowerCAmelCase							=							initializer_range
										_lowerCAmelCase							=							[
										    ['Subsample', key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
										    ['Subsample', key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
										]
										_lowerCAmelCase							=							is_training
										_lowerCAmelCase							=							use_labels
										_lowerCAmelCase							=							num_labels
										_lowerCAmelCase							=							initializer_range





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[int]						):
										_lowerCAmelCase							=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

										_lowerCAmelCase							=							None
										if self.use_labels:
																	_lowerCAmelCase							=							ids_tensor([self.batch_size]  ,  self.num_labels						)

										_lowerCAmelCase							=							self.get_config()
										return config, pixel_values, labels





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[int]						):
										return LevitConfig(
										    image_size=self.image_size  ,  num_channels=self.num_channels  ,  kernel_size=self.kernel_size  ,  stride=self.stride  ,  padding=self.padding  ,  patch_size=self.patch_size  ,  hidden_sizes=self.hidden_sizes  ,  num_attention_heads=self.num_attention_heads  ,  depths=self.depths  ,  key_dim=self.key_dim  ,  drop_path_rate=self.drop_path_rate  ,  mlp_ratio=self.mlp_ratio  ,  attention_ratio=self.attention_ratio  ,  initializer_range=self.initializer_range  ,  down_ops=self.down_ops  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple  ,  lowercase__	:	Tuple  ,  lowercase__	:	List[Any]  ,  lowercase__	:	Tuple						):
										_lowerCAmelCase							=							LevitModel(config=lowercase__						)
										model.to(lowercase__						)
										model.eval()
										_lowerCAmelCase							=							model(lowercase__						)
										_lowerCAmelCase							=							(self.image_size, self.image_size)
										_lowerCAmelCase			,		_lowerCAmelCase							=							image_size[0], image_size[1]
										for _ in range(4						):
																	_lowerCAmelCase							=							floor(((height + 2 * self.padding - self.kernel_size) / self.stride) + 1						)
																	_lowerCAmelCase							=							floor(((width + 2 * self.padding - self.kernel_size) / self.stride) + 1						)
										self.parent.assertEqual(
										    result.last_hidden_state.shape  ,  (self.batch_size, ceil(height / 4						) * ceil(width / 4						), self.hidden_sizes[-1])  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]  ,  lowercase__	:	List[str]  ,  lowercase__	:	List[str]  ,  lowercase__	:	Optional[int]						):
										_lowerCAmelCase							=							self.num_labels
										_lowerCAmelCase							=							LevitForImageClassification(lowercase__						)
										model.to(lowercase__						)
										model.eval()
										_lowerCAmelCase							=							model(lowercase__  ,  labels=lowercase__						)
										self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.num_labels)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							self.prepare_config_and_inputs()
										_lowerCAmelCase			,		_lowerCAmelCase			,		_lowerCAmelCase							=							config_and_inputs
										_lowerCAmelCase							=							{'pixel_values': pixel_values}
										return config, inputs_dict







@require_torch
class        lowerCamelCase__				(   UpperCAmelCase       ,UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=(
			    (LevitModel, LevitForImageClassification, LevitForImageClassificationWithTeacher)
			    if is_torch_available()
			    else ()
			)
			UpperCamelCase__    							=(
			    {
			        "feature-extraction": LevitModel,
			        "image-classification": (LevitForImageClassification, LevitForImageClassificationWithTeacher),
			    }
			    if is_torch_available()
			    else {}
			)

			UpperCamelCase__    							=False
			UpperCamelCase__    							=False
			UpperCamelCase__    							=False
			UpperCamelCase__    							=False
			UpperCamelCase__    							=False





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										_lowerCAmelCase							=							LevitModelTester(self						)
										_lowerCAmelCase							=							ConfigTester(self  ,  config_class=lowercase__  ,  has_text_modality=lowercase__  ,  hidden_size=37						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]						):
										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   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										return





			@unittest.skip(reason='Levit does not use inputs_embeds'						)
			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										pass





			@unittest.skip(reason='Levit does not support input and output embeddings'						)
			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										pass





			@unittest.skip(reason='Levit does not output attentions'						)
			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[int]						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase			,		_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																	_lowerCAmelCase							=							model_class(lowercase__						)
																	_lowerCAmelCase							=							inspect.signature(model.forward						)
																	# signature.parameters is an OrderedDict => so arg_names order is deterministic
																	_lowerCAmelCase							=							[*signature.parameters.keys()]

																	_lowerCAmelCase							=							['pixel_values']
																	self.assertListEqual(arg_names[:1]  ,  lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										def check_hidden_states_output(lowercase__	:	Optional[Any]  ,  lowercase__	:	str  ,  lowercase__	:	Tuple						):
																	_lowerCAmelCase							=							model_class(lowercase__						)
																	model.to(lowercase__						)
																	model.eval()

																	with torch.no_grad():
																								_lowerCAmelCase							=							model(**self._prepare_for_class(lowercase__  ,  lowercase__						)						)

																	_lowerCAmelCase							=							outputs.hidden_states

																	_lowerCAmelCase							=							len(self.model_tester.depths						) + 1
																	self.assertEqual(len(lowercase__						)  ,  lowercase__						)

																	_lowerCAmelCase							=							(self.model_tester.image_size, self.model_tester.image_size)
																	_lowerCAmelCase			,		_lowerCAmelCase							=							image_size[0], image_size[1]
																	for _ in range(4						):
																								_lowerCAmelCase							=							floor(
																								    (
																								        (height + 2 * self.model_tester.padding - self.model_tester.kernel_size)
																								        / self.model_tester.stride
																								    )
																								    + 1						)
																								_lowerCAmelCase							=							floor(
																								    (
																								        (width + 2 * self.model_tester.padding - self.model_tester.kernel_size)
																								        / self.model_tester.stride
																								    )
																								    + 1						)
																	# verify the first hidden states (first block)
																	self.assertListEqual(
																	    list(hidden_states[0].shape[-2:]						)  ,  [
																	        height * width,
																	        self.model_tester.hidden_sizes[0],
																	    ]  ,  )

										_lowerCAmelCase			,		_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																	_lowerCAmelCase							=							True
																	check_hidden_states_output(lowercase__  ,  lowercase__  ,  lowercase__						)

																	# check that output_hidden_states also work using config
																	del inputs_dict["output_hidden_states"]
																	_lowerCAmelCase							=							True

																	check_hidden_states_output(lowercase__  ,  lowercase__  ,  lowercase__						)





			@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'						)
			def   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	int  ,  lowercase__	:	List[Any]  ,  lowercase__	:	Optional[Any]  ,  lowercase__	:	Union[str, Any]=False						):
										_lowerCAmelCase							=							super()._prepare_for_class(lowercase__  ,  lowercase__  ,  return_labels=lowercase__						)

										if return_labels:
																	if model_class.__name__ == "LevitForImageClassificationWithTeacher":
																								del inputs_dict["labels"]

										return inputs_dict





			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										if not self.model_tester.is_training:
																	return

										_lowerCAmelCase			,		_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs_for_common()
										_lowerCAmelCase							=							True

										for model_class in self.all_model_classes:
																	# LevitForImageClassificationWithTeacher supports inference-only
																	if (
																	    model_class in get_values(lowercase__						)
																	    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
																	):
																								continue
																	_lowerCAmelCase							=							model_class(lowercase__						)
																	model.to(lowercase__						)
																	model.train()
																	_lowerCAmelCase							=							self._prepare_for_class(lowercase__  ,  lowercase__  ,  return_labels=lowercase__						)
																	_lowerCAmelCase							=							model(**lowercase__						).loss
																	loss.backward()





			def   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										_lowerCAmelCase			,		_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs_for_common()
										if not self.model_tester.is_training:
																	return

										_lowerCAmelCase							=							False
										_lowerCAmelCase							=							True

										for model_class in self.all_model_classes:
																	if model_class in get_values(lowercase__						) or not model_class.supports_gradient_checkpointing:
																								continue
																	# LevitForImageClassificationWithTeacher supports inference-only
																	if model_class.__name__ == "LevitForImageClassificationWithTeacher":
																								continue
																	_lowerCAmelCase							=							model_class(lowercase__						)
																	model.gradient_checkpointing_enable()
																	model.to(lowercase__						)
																	model.train()
																	_lowerCAmelCase							=							self._prepare_for_class(lowercase__  ,  lowercase__  ,  return_labels=lowercase__						)
																	_lowerCAmelCase							=							model(**lowercase__						).loss
																	loss.backward()





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase			,		_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs_for_common()

										_lowerCAmelCase							=							[
										    {'title': 'multi_label_classification', 'num_labels': 2, 'dtype': torch.float},
										    {'title': 'single_label_classification', 'num_labels': 1, 'dtype': torch.long},
										    {'title': 'regression', 'num_labels': 1, 'dtype': torch.float},
										]

										for model_class in self.all_model_classes:
																	if (
																	    model_class
																	    not in [
																	        *get_values(lowercase__						),
																	    ]
																	    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
																	):
																								continue

																	for problem_type in problem_types:
																								with self.subTest(msg=f'Testing {model_class} with {problem_type["title"]}'						):
																															_lowerCAmelCase							=							problem_type['title']
																															_lowerCAmelCase							=							problem_type['num_labels']

																															_lowerCAmelCase							=							model_class(lowercase__						)
																															model.to(lowercase__						)
																															model.train()

																															_lowerCAmelCase							=							self._prepare_for_class(lowercase__  ,  lowercase__  ,  return_labels=lowercase__						)

																															if problem_type["num_labels"] > 1:
																																						_lowerCAmelCase							=							inputs['labels'].unsqueeze(1						).repeat(1  ,  problem_type['num_labels']						)

																															_lowerCAmelCase							=							inputs['labels'].to(problem_type['dtype']						)

																															# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
																															# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
																															# they have the same size." which is a symptom something in wrong for the regression problem.
																															# See https://github.com/huggingface/transformers/issues/11780
																															with warnings.catch_warnings(record=lowercase__						) as warning_list:
																																						_lowerCAmelCase							=							model(**lowercase__						).loss
																															for w in warning_list:
																																						if "Using a target size that is different to the input size" in str(w.message						):
																																													raise ValueError(
																																													    f'Something is going wrong in the regression problem: intercepted {w.message}'						)

																															loss.backward()





			@slow
			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]						):
										for model_name in LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_lowerCAmelCase							=							LevitModel.from_pretrained(lowercase__						)
																	self.assertIsNotNone(lowercase__						)







def _lowerCamelCase  (		):
							_lowerCAmelCase							=							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
							return image



@require_torch
@require_vision
class        lowerCamelCase__				(   unittest.TestCase				):





			@cached_property
			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										return LevitImageProcessor.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)





			@slow
			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										_lowerCAmelCase							=							LevitForImageClassificationWithTeacher.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]						).to(
										    lowercase__						)

										_lowerCAmelCase							=							self.default_image_processor
										_lowerCAmelCase							=							prepare_img()
										_lowerCAmelCase							=							image_processor(images=lowercase__  ,  return_tensors='pt'						).to(lowercase__						)

										# forward pass
										with torch.no_grad():
																	_lowerCAmelCase							=							model(**lowercase__						)

										# verify the logits
										_lowerCAmelCase							=							torch.Size((1, 10_00)						)
										self.assertEqual(outputs.logits.shape  ,  lowercase__						)

										_lowerCAmelCase							=							torch.tensor([1.0_4_4_8, -0.3_7_4_5, -1.8_3_1_7]						).to(lowercase__						)

										self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,  lowercase__  ,  atol=1e-4						)						)







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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import ChineseCLIPImageProcessor



class        lowerCamelCase__				(   unittest.TestCase				):





			def __init__(       self	:	List[str]  ,  lowercase__	:	Any  ,  lowercase__	:	List[Any]=7  ,  lowercase__	:	List[str]=3  ,  lowercase__	:	str=18  ,  lowercase__	:	List[Any]=30  ,  lowercase__	:	Optional[int]=4_00  ,  lowercase__	:	Dict=True  ,  lowercase__	:	List[str]=None  ,  lowercase__	:	int=True  ,  lowercase__	:	Tuple=None  ,  lowercase__	:	int=True  ,  lowercase__	:	Tuple=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]  ,  lowercase__	:	Optional[int]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]  ,  lowercase__	:	Any=True  ,  ):
										_lowerCAmelCase							=							size if size is not None else {'height': 2_24, 'width': 2_24}
										_lowerCAmelCase							=							crop_size if crop_size is not None else {'height': 18, 'width': 18}
										_lowerCAmelCase							=							parent
										_lowerCAmelCase							=							batch_size
										_lowerCAmelCase							=							num_channels
										_lowerCAmelCase							=							image_size
										_lowerCAmelCase							=							min_resolution
										_lowerCAmelCase							=							max_resolution
										_lowerCAmelCase							=							do_resize
										_lowerCAmelCase							=							size
										_lowerCAmelCase							=							do_center_crop
										_lowerCAmelCase							=							crop_size
										_lowerCAmelCase							=							do_normalize
										_lowerCAmelCase							=							image_mean
										_lowerCAmelCase							=							image_std
										_lowerCAmelCase							=							do_convert_rgb





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										return {
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "do_center_crop": self.do_center_crop,
										    "crop_size": self.crop_size,
										    "do_normalize": self.do_normalize,
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_convert_rgb": self.do_convert_rgb,
										}





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]  ,  lowercase__	:	Tuple=False  ,  lowercase__	:	List[Any]=False  ,  lowercase__	:	str=False						):
										assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

										if equal_resolution:
																	_lowerCAmelCase							=							[]
																	for i in range(self.batch_size						):
																								image_inputs.append(
																								    np.random.randint(
																								        2_55  ,  size=(self.num_channels, self.max_resolution, self.max_resolution)  ,  dtype=np.uinta						)						)
										else:
																	_lowerCAmelCase							=							[]
																	for i in range(self.batch_size						):
																								_lowerCAmelCase			,		_lowerCAmelCase							=							np.random.choice(np.arange(self.min_resolution  ,  self.max_resolution						)  ,  2						)
																								image_inputs.append(np.random.randint(2_55  ,  size=(self.num_channels, width, height)  ,  dtype=np.uinta						)						)

										if not numpify and not torchify:
																	# PIL expects the channel dimension as last dimension
																	_lowerCAmelCase							=							[Image.fromarray(np.moveaxis(lowercase__  ,  0  ,  -1						)						) for x in image_inputs]

										if torchify:
																	_lowerCAmelCase							=							[torch.from_numpy(lowercase__						) for x in image_inputs]

										return image_inputs







@require_torch
@require_vision
class        lowerCamelCase__				(   UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=ChineseCLIPImageProcessor if is_vision_available() else None





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							ChineseCLIPImageProcessingTester(self  ,  do_center_crop=lowercase__						)





			@property
			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										return self.image_processor_tester.prepare_image_processor_dict()





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										self.assertTrue(hasattr(lowercase__  ,  'do_resize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'size'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_normalize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_mean'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_std'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_convert_rgb'						)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]						):
										_lowerCAmelCase							=							self.image_processing_class.from_dict(self.image_processor_dict						)
										self.assertEqual(image_processor.size  ,  {'height': 2_24, 'width': 2_24}						)
										self.assertEqual(image_processor.crop_size  ,  {'height': 18, 'width': 18}						)

										_lowerCAmelCase							=							self.image_processing_class.from_dict(self.image_processor_dict  ,  size=42  ,  crop_size=84						)
										self.assertEqual(image_processor.size  ,  {'shortest_edge': 42}						)
										self.assertEqual(image_processor.crop_size  ,  {'height': 84, 'width': 84}						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PIL images
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  Image.Image						)

										# Test not batched input
										_lowerCAmelCase							=							image_processing(image_inputs[0]  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        1,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random numpy tensors
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__  ,  numpify=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  np.ndarray						)

										# Test not batched input
										_lowerCAmelCase							=							image_processing(image_inputs[0]  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        1,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PyTorch tensors
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__  ,  torchify=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  torch.Tensor						)

										# Test not batched input
										_lowerCAmelCase							=							image_processing(image_inputs[0]  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        1,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )







@require_torch
@require_vision
class        lowerCamelCase__				(   UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=ChineseCLIPImageProcessor if is_vision_available() else None





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										_lowerCAmelCase							=							ChineseCLIPImageProcessingTester(self  ,  num_channels=4  ,  do_center_crop=lowercase__						)
										_lowerCAmelCase							=							3





			@property
			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										return self.image_processor_tester.prepare_image_processor_dict()





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										self.assertTrue(hasattr(lowercase__  ,  'do_resize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'size'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_normalize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_mean'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_std'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_convert_rgb'						)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PIL images
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  Image.Image						)

										# Test not batched input
										_lowerCAmelCase							=							image_processing(image_inputs[0]  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        1,
										        self.expected_encoded_image_num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        self.image_processor_tester.batch_size,
										        self.expected_encoded_image_num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )






