"""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 BlipImageProcessor
class 							snake_case			(					unittest.TestCase							):




					"""simple docstring"""

					def __init__(							self  :      Union[str, Any]       ,lowerCamelCase__  :      int       ,lowerCamelCase__  :      List[str]=7       ,lowerCamelCase__  :      Any=3       ,lowerCamelCase__  :      Optional[Any]=18       ,lowerCamelCase__  :      int=30       ,lowerCamelCase__  :      str=400       ,lowerCamelCase__  :      Optional[Any]=True       ,lowerCamelCase__  :      List[str]=None       ,lowerCamelCase__  :      str=True       ,lowerCamelCase__  :      Dict=False       ,lowerCamelCase__  :      Union[str, Any]=[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]       ,lowerCamelCase__  :      List[str]=[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]       ,lowerCamelCase__  :      Dict=True       ,):
									UpperCAmelCase__			 =				size if size is not None else {'height': 20, 'width': 20}
									UpperCAmelCase__			 =				parent
									UpperCAmelCase__			 =				batch_size
									UpperCAmelCase__			 =				num_channels
									UpperCAmelCase__			 =				image_size
									UpperCAmelCase__			 =				min_resolution
									UpperCAmelCase__			 =				max_resolution
									UpperCAmelCase__			 =				do_resize
									UpperCAmelCase__			 =				size
									UpperCAmelCase__			 =				do_normalize
									UpperCAmelCase__			 =				image_mean
									UpperCAmelCase__			 =				image_std
									UpperCAmelCase__			 =				do_pad
									UpperCAmelCase__			 =				do_convert_rgb







					def 						__lowerCAmelCase		(							self  :      Any     ):
									return {
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "do_normalize": self.do_normalize,
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_convert_rgb": self.do_convert_rgb,
									    "do_pad": self.do_pad,
									}







					def 						__lowerCAmelCase		(							self  :      Any       ,lowerCamelCase__  :      int=False       ,lowerCamelCase__  :      Union[str, Any]=False       ,lowerCamelCase__  :      Any=False     ):
									assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

									if equal_resolution:
													UpperCAmelCase__			 =				[]
													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:
													UpperCAmelCase__			 =				[]
													for i in range(self.batch_size     ):
																	UpperCAmelCase__ ,      UpperCAmelCase__			 =				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
													UpperCAmelCase__			 =				[Image.fromarray(np.moveaxis(__SCREAMING_SNAKE_CASE       ,0       ,-1     )     ) for x in image_inputs]

									if torchify:
													UpperCAmelCase__			 =				[torch.from_numpy(__SCREAMING_SNAKE_CASE     ) for x in image_inputs]

									return image_inputs






@require_torch
@require_vision
class 							snake_case			(					_A ,       unittest.TestCase							):




					"""simple docstring"""

					snake_case__							       =					BlipImageProcessor if is_vision_available() else None







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				BlipImageProcessingTester(self     )







					@property
					def 						__lowerCAmelCase		(							self  :      Union[str, Any]     ):
									return self.image_processor_tester.prepare_image_processor_dict()







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_resize'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'size'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_normalize'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'image_mean'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'image_std'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_convert_rgb'     )     )







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									pass







					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									# Initialize image_processor
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									# create random PIL images
									UpperCAmelCase__			 =				self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE     )
									for image in image_inputs:
													self.assertIsInstance(__SCREAMING_SNAKE_CASE       ,Image.Image     )

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

									# Test batched
									UpperCAmelCase__			 =				image_processor(__SCREAMING_SNAKE_CASE       ,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.size['height'],
									        self.image_processor_tester.size['width'],
									    )       ,)







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									# Initialize image_processor
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									# create random numpy tensors
									UpperCAmelCase__			 =				self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE       ,numpify=__SCREAMING_SNAKE_CASE     )
									for image in image_inputs:
													self.assertIsInstance(__SCREAMING_SNAKE_CASE       ,np.ndarray     )

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

									# Test batched
									UpperCAmelCase__			 =				image_processor(__SCREAMING_SNAKE_CASE       ,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.size['height'],
									        self.image_processor_tester.size['width'],
									    )       ,)







					def 						__lowerCAmelCase		(							self  :      Any     ):
									# Initialize image_processor
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									# create random PyTorch tensors
									UpperCAmelCase__			 =				self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE       ,torchify=__SCREAMING_SNAKE_CASE     )
									for image in image_inputs:
													self.assertIsInstance(__SCREAMING_SNAKE_CASE       ,torch.Tensor     )

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

									# Test batched
									UpperCAmelCase__			 =				image_processor(__SCREAMING_SNAKE_CASE       ,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.size['height'],
									        self.image_processor_tester.size['width'],
									    )       ,)






@require_torch
@require_vision
class 							snake_case			(					_A ,       unittest.TestCase							):




					"""simple docstring"""

					snake_case__							       =					BlipImageProcessor if is_vision_available() else None







					def 						__lowerCAmelCase		(							self  :      List[Any]     ):
									UpperCAmelCase__			 =				BlipImageProcessingTester(self       ,num_channels=4     )
									UpperCAmelCase__			 =				3







					@property
					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									return self.image_processor_tester.prepare_image_processor_dict()







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_resize'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'size'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_normalize'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'image_mean'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'image_std'     )     )
									self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,'do_convert_rgb'     )     )







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									pass







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									# Initialize image_processor
									UpperCAmelCase__			 =				self.image_processing_class(**self.image_processor_dict     )
									# create random PIL images
									UpperCAmelCase__			 =				self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE     )
									for image in image_inputs:
													self.assertIsInstance(__SCREAMING_SNAKE_CASE       ,Image.Image     )

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

									# Test batched
									UpperCAmelCase__			 =				image_processor(__SCREAMING_SNAKE_CASE       ,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.size['height'],
									        self.image_processor_tester.size['width'],
									    )       ,)






"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__A	:       Dict        =						{'configuration_cvt': ['CVT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CvtConfig']}


try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A	:       Any        =						[
	    'CVT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'CvtForImageClassification',
	    'CvtModel',
	    'CvtPreTrainedModel',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A	:       List[str]        =						[
	    'TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFCvtForImageClassification',
	    'TFCvtModel',
	    'TFCvtPreTrainedModel',
	]

if TYPE_CHECKING:
	from .configuration_cvt import CVT_PRETRAINED_CONFIG_ARCHIVE_MAP, CvtConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_cvt import (
		    CVT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    CvtForImageClassification,
		    CvtModel,
		    CvtPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_cvt import (
		    TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFCvtForImageClassification,
		    TFCvtModel,
		    TFCvtPreTrainedModel,
		)


else:
	import sys

	__A	:       str        =						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





