
"""simple docstring"""



import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
	from PIL import Image

	from transformers import OwlViTImageProcessor, OwlViTProcessor
@require_vision
class        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def 				__lowerCamelCase	(					self	:			int  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			tempfile.mkdtemp()

											# fmt: off
											_lowerCAmelCase							=			['', 'l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
											# fmt: on
											_lowerCAmelCase							=			dict(zip(UpperCAmelCase_				,     range(len(UpperCAmelCase_  )  )  )  )
											_lowerCAmelCase							=			['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>', '']
											_lowerCAmelCase							=			{'unk_token': '<unk>'}

											_lowerCAmelCase							=			os.path.join(self.tmpdirname				,     VOCAB_FILES_NAMES['vocab_file']  )
											_lowerCAmelCase							=			os.path.join(self.tmpdirname				,     VOCAB_FILES_NAMES['merges_file']  )
											with open(self.vocab_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		fp.write(json.dumps(UpperCAmelCase_  ) + '\n'  )
											with open(self.merges_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		fp.write('\n'.join(UpperCAmelCase_  )  )

											_lowerCAmelCase							=			{
											    'do_resize': True,
											    'size': 20,
											    'do_center_crop': True,
											    'crop_size': 18,
											    'do_normalize': True,
											    'image_mean': [0.48145466, 0.4578275, 0.40821073],
											    'image_std': [0.26862954, 0.26130258, 0.27577711],
											}
											_lowerCAmelCase							=			os.path.join(self.tmpdirname				,     UpperCAmelCase_  )
											with open(self.image_processor_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		json.dump(UpperCAmelCase_				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]				,     **UpperCAmelCase_	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											return CLIPTokenizer.from_pretrained(self.tmpdirname				,     pad_token='!'				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[Any]				,     **UpperCAmelCase_	:			List[str]  )		->  Union[str, Any]:







											"""simple docstring"""




											return CLIPTokenizerFast.from_pretrained(self.tmpdirname				,     pad_token='!'				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Union[str, Any]				,     **UpperCAmelCase_	:			Dict  )		->  List[Any]:







											"""simple docstring"""




											return OwlViTImageProcessor.from_pretrained(self.tmpdirname				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[Any]:







											"""simple docstring"""




											shutil.rmtree(self.tmpdirname  )


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase							=			[np.random.randint(255				,     size=(3, 30, 400)				,     dtype=np.uinta  )]

											_lowerCAmelCase							=			[Image.fromarray(np.moveaxis(UpperCAmelCase_				,     0				,     -1  )  ) for x in image_inputs]

											return image_inputs


				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_tokenizer()
											_lowerCAmelCase							=			self.get_rust_tokenizer()
											_lowerCAmelCase							=			self.get_image_processor()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )
											processor_slow.save_pretrained(self.tmpdirname  )
											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(self.tmpdirname				,     use_fast=UpperCAmelCase_  )

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )
											processor_fast.save_pretrained(self.tmpdirname  )
											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(self.tmpdirname  )

											self.assertEqual(processor_slow.tokenizer.get_vocab()				,     tokenizer_slow.get_vocab()  )
											self.assertEqual(processor_fast.tokenizer.get_vocab()				,     tokenizer_fast.get_vocab()  )
											self.assertEqual(tokenizer_slow.get_vocab()				,     tokenizer_fast.get_vocab()  )
											self.assertIsInstance(processor_slow.tokenizer				,     UpperCAmelCase_  )
											self.assertIsInstance(processor_fast.tokenizer				,     UpperCAmelCase_  )

											self.assertEqual(processor_slow.image_processor.to_json_string()				,     image_processor.to_json_string()  )
											self.assertEqual(processor_fast.image_processor.to_json_string()				,     image_processor.to_json_string()  )
											self.assertIsInstance(processor_slow.image_processor				,     UpperCAmelCase_  )
											self.assertIsInstance(processor_fast.image_processor				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=self.get_tokenizer()				,     image_processor=self.get_image_processor()  )
											processor.save_pretrained(self.tmpdirname  )

											_lowerCAmelCase							=			self.get_tokenizer(bos_token='(BOS)'				,     eos_token='(EOS)'  )
											_lowerCAmelCase							=			self.get_image_processor(do_normalize=UpperCAmelCase_  )

											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(
											    self.tmpdirname				,     bos_token='(BOS)'				,     eos_token='(EOS)'				,     do_normalize=UpperCAmelCase_  )

											self.assertEqual(processor.tokenizer.get_vocab()				,     tokenizer_add_kwargs.get_vocab()  )
											self.assertIsInstance(processor.tokenizer				,     UpperCAmelCase_  )

											self.assertEqual(processor.image_processor.to_json_string()				,     image_processor_add_kwargs.to_json_string()  )
											self.assertIsInstance(processor.image_processor				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_image_processor()
											_lowerCAmelCase							=			self.get_tokenizer()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase							=			self.prepare_image_inputs()

											_lowerCAmelCase							=			image_processor(UpperCAmelCase_				,     return_tensors='np'  )
											_lowerCAmelCase							=			processor(images=UpperCAmelCase_				,     return_tensors='np'  )

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


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_image_processor()
											_lowerCAmelCase							=			self.get_tokenizer()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase							=			'lower newer'

											_lowerCAmelCase							=			processor(text=UpperCAmelCase_				,     return_tensors='np'  )

											_lowerCAmelCase							=			tokenizer(UpperCAmelCase_				,     return_tensors='np'  )

											for key in encoded_tok.keys():
																		self.assertListEqual(encoded_tok[key][0].tolist()				,     encoded_processor[key][0].tolist()  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Any:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_image_processor()
											_lowerCAmelCase							=			self.get_tokenizer()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase							=			'lower newer'
											_lowerCAmelCase							=			self.prepare_image_inputs()

											_lowerCAmelCase							=			processor(text=UpperCAmelCase_				,     images=UpperCAmelCase_  )

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask', 'pixel_values']  )

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


				def 				__lowerCamelCase	(					self	:			str  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase							=			'google/owlvit-base-patch32'
											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase							=			['cat', 'nasa badge']
											_lowerCAmelCase							=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase							=			16
											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (2, seq_length)  )

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


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase							=			'google/owlvit-base-patch32'
											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase							=			[['cat', 'nasa badge'], ['person']]
											_lowerCAmelCase							=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase							=			16
											_lowerCAmelCase							=			len(UpperCAmelCase_  )
											_lowerCAmelCase							=			max([len(UpperCAmelCase_  ) for texts in input_texts]  )

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (batch_size * num_max_text_queries, seq_length)  )

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


				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase							=			'google/owlvit-base-patch32'
											_lowerCAmelCase							=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase							=			['cat', 'nasa badge']
											_lowerCAmelCase							=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase							=			16
											_lowerCAmelCase							=			inputs['input_ids']
											_lowerCAmelCase							=			[
											    [49_406, 2_368, 49_407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
											    [49_406, 6_841, 11_301, 49_407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
											]

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (2, seq_length)  )
											self.assertListEqual(list(input_ids[0]  )				,     predicted_ids[0]  )
											self.assertListEqual(list(input_ids[1]  )				,     predicted_ids[1]  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_image_processor()
											_lowerCAmelCase							=			self.get_tokenizer()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase							=			self.prepare_image_inputs()
											_lowerCAmelCase							=			self.prepare_image_inputs()

											_lowerCAmelCase							=			processor(images=UpperCAmelCase_				,     query_images=UpperCAmelCase_  )

											self.assertListEqual(list(inputs.keys()  )				,     ['query_pixel_values', 'pixel_values']  )

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







				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase							=			self.get_image_processor()
											_lowerCAmelCase							=			self.get_tokenizer()

											_lowerCAmelCase							=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase							=			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

											_lowerCAmelCase							=			processor.batch_decode(UpperCAmelCase_  )
											_lowerCAmelCase							=			tokenizer.batch_decode(UpperCAmelCase_  )

											self.assertListEqual(UpperCAmelCase_				,     UpperCAmelCase_  )








"""simple docstring"""



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        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def __init__(					self	:			Optional[Any]				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			Dict=7				,     UpperCAmelCase_	:			List[Any]=3				,     UpperCAmelCase_	:			Tuple=18				,     UpperCAmelCase_	:			List[str]=30				,     UpperCAmelCase_	:			Union[str, Any]=400				,     UpperCAmelCase_	:			Optional[Any]=True				,     UpperCAmelCase_	:			Tuple=None				,     UpperCAmelCase_	:			Optional[int]=True				,     UpperCAmelCase_	:			Any=None				,     UpperCAmelCase_	:			Tuple=True				,     UpperCAmelCase_	:			List[Any]=[0.48145466, 0.4578275, 0.40821073]				,     UpperCAmelCase_	:			List[Any]=[0.26862954, 0.26130258, 0.27577711]				,     UpperCAmelCase_	:			Optional[int]=True				,     )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			size if size is not None else {'height': 224, 'width': 224}
											_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 				__lowerCamelCase	(					self	:			Optional[int]  )		->  int:







											"""simple docstring"""




											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 				__lowerCamelCase	(					self	:			Dict				,     UpperCAmelCase_	:			Dict=False				,     UpperCAmelCase_	:			int=False				,     UpperCAmelCase_	:			Dict=False  )		->  str:







											"""simple docstring"""




											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(
																									        255				,     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(255				,     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(UpperCAmelCase_				,     0				,     -1  )  ) for x in image_inputs]

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

											return image_inputs






@require_torch
@require_vision
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							List[Any]							=					ChineseCLIPImageProcessor if is_vision_available() else None


				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			ChineseCLIPImageProcessingTester(self				,     do_center_crop=UpperCAmelCase_  )


				@property
				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  int:







											"""simple docstring"""




											return self.image_processor_tester.prepare_image_processor_dict()


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_resize'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'size'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_center_crop'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'center_crop'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_normalize'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'image_mean'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'image_std'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_convert_rgb'  )  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			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': 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 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  List[str]:







											"""simple docstring"""




											pass


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random PIL images
											_lowerCAmelCase  	=			self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_  )
											for image in image_inputs:
																		self.assertIsInstance(UpperCAmelCase_				,     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(UpperCAmelCase_				,     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 				__lowerCamelCase	(					self	:			List[str]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random numpy tensors
											_lowerCAmelCase  	=			self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_				,     numpify=UpperCAmelCase_  )
											for image in image_inputs:
																		self.assertIsInstance(UpperCAmelCase_				,     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(UpperCAmelCase_				,     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 				__lowerCamelCase	(					self	:			List[Any]  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random PyTorch tensors
											_lowerCAmelCase  	=			self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_				,     torchify=UpperCAmelCase_  )
											for image in image_inputs:
																		self.assertIsInstance(UpperCAmelCase_				,     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(UpperCAmelCase_				,     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        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							str							=					ChineseCLIPImageProcessor if is_vision_available() else None


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			ChineseCLIPImageProcessingTester(self				,     num_channels=4				,     do_center_crop=UpperCAmelCase_  )
											_lowerCAmelCase  	=			3


				@property
				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Dict:







											"""simple docstring"""




											return self.image_processor_tester.prepare_image_processor_dict()


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_resize'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'size'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_center_crop'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'center_crop'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_normalize'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'image_mean'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'image_std'  )  )
											self.assertTrue(hasattr(UpperCAmelCase_				,     'do_convert_rgb'  )  )


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[int]:







											"""simple docstring"""




											pass







				def 				__lowerCamelCase	(					self	:			int  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random PIL images
											_lowerCAmelCase  	=			self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_  )
											for image in image_inputs:
																		self.assertIsInstance(UpperCAmelCase_				,     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(UpperCAmelCase_				,     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'],
											    )				,     )






