




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


			def __init__(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE=7			,	SCREAMING_SNAKE_CASE=3			,	SCREAMING_SNAKE_CASE=18			,	SCREAMING_SNAKE_CASE=30			,	SCREAMING_SNAKE_CASE=400			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=None			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=None			,	):



					"""simple docstring"""







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



			def 							lowerCamelCase_			(       self							):



					"""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      lowerCamelCase__      (					lowerCamelCase_			,					unittest.TestCase     ):
			a__	: Optional[Any]        =       MobileNetVaImageProcessor if is_vision_available() else None


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  int        =			MobileNetVaImageProcessingTester(self							)


			@property
			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					return self.image_processor_tester.prepare_image_processor_dict()


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			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_center_crop"							)							)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE			,	"center_crop"							)							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			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}							)

					snake_case						:  List[Any]        =			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							):



					"""simple docstring"""







					pass


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  int        =			self.image_processing_class(**self.image_processor_dict							)
					# create random PIL images
					snake_case						:  Optional[int]        =			prepare_image_inputs(self.image_processor_tester			,	equal_resolution=SCREAMING_SNAKE_CASE							)
					for image in image_inputs:
							self.assertIsInstance(SCREAMING_SNAKE_CASE			,	Image.Image							)

					# Test not batched input
					snake_case						:  List[str]        =			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
					snake_case						:  str        =			image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )			,	)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Optional[int]        =			self.image_processing_class(**self.image_processor_dict							)
					# create random numpy tensors
					snake_case						:  List[Any]        =			prepare_image_inputs(self.image_processor_tester			,	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
					snake_case						:  List[str]        =			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
					snake_case						:  Tuple        =			image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )			,	)



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Optional[int]        =			self.image_processing_class(**self.image_processor_dict							)
					# create random PyTorch tensors
					snake_case						:  int        =			prepare_image_inputs(self.image_processor_tester			,	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
					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
					snake_case						:  Any        =			image_processing(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.crop_size["height"],
					        self.image_processor_tester.crop_size["width"],
					    )			,	)







"""simple docstring"""

def 					UpperCamelCase__       (						lowercase__					:       set    ,       lowercase__					:       set				):
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_a={set_a}] is not a set'''
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_b={set_b}] is not a set'''

		return {a + b for a in set_a for b in set_b}


if __name__ == "__main__":
							from doctest import testmod

							testmod()

