



'''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, prepare_image_inputs


if is_torch_available():
	import torch

if is_vision_available():
	from PIL import Image

	from transformers import MobileNetVaImageProcessor


class 	a__     (				unittest.TestCase	):


	def __init__(self : List[str],					__UpperCAmelCase : Union[str, Any],					__UpperCAmelCase : Dict=7,					__UpperCAmelCase : Optional[Any]=3,					__UpperCAmelCase : Optional[Any]=18,					__UpperCAmelCase : str=30,					__UpperCAmelCase : Optional[Any]=400,					__UpperCAmelCase : Optional[Any]=True,					__UpperCAmelCase : str=None,					__UpperCAmelCase : Optional[int]=True,					__UpperCAmelCase : Optional[int]=None,					)     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= size if size is not None else {'''shortest_edge''': 20}
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= parent
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= batch_size
					SCREAMING_SNAKE_CASE  :						List[Any]      					= num_channels
					SCREAMING_SNAKE_CASE  :						Any      					= image_size
					SCREAMING_SNAKE_CASE  :						List[str]      					= min_resolution
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= max_resolution
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= do_resize
					SCREAMING_SNAKE_CASE  :						List[Any]      					= size
					SCREAMING_SNAKE_CASE  :						List[Any]      					= do_center_crop
					SCREAMING_SNAKE_CASE  :						int      					= crop_size






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

					"""simple docstring"""

					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					}



@require_torch
@require_vision
class 	a__     (				_lowercase,			unittest.TestCase	):
	__magic_name__		:    Optional[int]	    =     MobileNetVaImageProcessor if is_vision_available() else None


	def 				lowercase__  (self : str      )     ->			Dict:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= MobileNetVaImageProcessingTester(self      )


	@property
	def 				lowercase__  (self : Union[str, Any]      )     ->			Optional[Any]:

					"""simple docstring"""

					return self.image_processor_tester.prepare_image_processor_dict()


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

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= 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,					'''crop_size'''      )      )


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

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						str      					= self.image_processing_class.from_dict(self.image_processor_dict      )
					self.assertEqual(image_processor.size,					{'''shortest_edge''': 20}      )
					self.assertEqual(image_processor.crop_size,					{'''height''': 18, '''width''': 18}      )

					SCREAMING_SNAKE_CASE  :						Dict      					= 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 				lowercase__  (self : Optional[Any]      )     ->			str:

					"""simple docstring"""

					pass


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

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.image_processing_class(**self.image_processor_dict      )
					# create random PIL images
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= prepare_image_inputs(self.image_processor_tester,					equal_resolution=__UpperCAmelCase      )
					for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase,					Image.Image      )

					# Test not batched input
					SCREAMING_SNAKE_CASE  :						Any      					= 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
					SCREAMING_SNAKE_CASE  :						List[str]      					= 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 				lowercase__  (self : int      )     ->			List[str]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						str      					= self.image_processing_class(**self.image_processor_dict      )
					# create random numpy tensors
					SCREAMING_SNAKE_CASE  :						int      					= prepare_image_inputs(self.image_processor_tester,					equal_resolution=__UpperCAmelCase,					numpify=__UpperCAmelCase      )
					for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase,					np.ndarray      )

					# Test not batched input
					SCREAMING_SNAKE_CASE  :						Any      					= 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
					SCREAMING_SNAKE_CASE  :						str      					= 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 				lowercase__  (self : Optional[int]      )     ->			Any:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						str      					= self.image_processing_class(**self.image_processor_dict      )
					# create random PyTorch tensors
					SCREAMING_SNAKE_CASE  :						str      					= prepare_image_inputs(self.image_processor_tester,					equal_resolution=__UpperCAmelCase,					torchify=__UpperCAmelCase      )
					for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase,					torch.Tensor      )

					# Test not batched input
					SCREAMING_SNAKE_CASE  :						Tuple      					= 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
					SCREAMING_SNAKE_CASE  :						List[Any]      					= 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'''],
					    ),					)









'''simple docstring'''

from ..utils import DummyObject, requires_backends


class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Dict	    =     ["torch", "transformers", "onnx"]


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

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Optional[Any],					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : int      )     ->			int:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : Tuple      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Any	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Optional[Any]      )     ->			int:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : List[str]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : int,					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : Any      )     ->			Optional[Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[Any]	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Dict,					**__UpperCAmelCase : Any      )     ->			List[str]:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Tuple,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : int      )     ->			Optional[Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Union[str, Any],					*__UpperCAmelCase : List[str],					**__UpperCAmelCase : str      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Tuple	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Union[str, Any],					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : List[Any]      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : str,					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : Tuple      )     ->			str:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : int,					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : List[str]      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : int      )     ->			List[str]:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : List[str],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Dict      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : List[str],					**__UpperCAmelCase : List[Any]      )     ->			Dict:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Dict	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Tuple,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : List[str]      )     ->			Any:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Tuple,					*__UpperCAmelCase : Any,					**__UpperCAmelCase : Union[str, Any]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Optional[Any],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Optional[Any]      )     ->			int:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )




