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 EfficientNetImageProcessor





class      snake_case_       (		unittest.TestCase ):







			'''simple docstring'''

			def __init__(					self			:    str							,       _UpperCamelCase			:    str							,       _UpperCamelCase			:    Tuple=1_3							,       _UpperCamelCase			:    int=3							,       _UpperCamelCase			:    List[Any]=1_8							,       _UpperCamelCase			:    str=3_0							,       _UpperCamelCase			:    Dict=4_0_0							,       _UpperCamelCase			:    int=True							,       _UpperCamelCase			:    Union[str, Any]=None							,       _UpperCamelCase			:    List[Any]=True							,       _UpperCamelCase			:    int=[0.5, 0.5, 0.5]							,       _UpperCamelCase			:    Union[str, Any]=[0.5, 0.5, 0.5]							,       )				->List[Any]:
									snake_case_       =     size if size is not None else {'''height''': 1_8, '''width''': 1_8}
									snake_case_       =     parent
									snake_case_       =     batch_size
									snake_case_       =     num_channels
									snake_case_       =     image_size
									snake_case_       =     min_resolution
									snake_case_       =     max_resolution
									snake_case_       =     do_resize
									snake_case_       =     size
									snake_case_       =     do_normalize
									snake_case_       =     image_mean
									snake_case_       =     image_std







			def     snake_case__(					self			:    List[str]							)				->Union[str, Any]:
									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									}






@require_torch
@require_vision
class      snake_case_       (		A__     ,	unittest.TestCase ):







			'''simple docstring'''

			SCREAMING_SNAKE_CASE					:       List[str]						      =    EfficientNetImageProcessor if is_vision_available() else None







			def     snake_case__(					self			:    List[str]							)				->str:
									snake_case_       =     EfficientNetImageProcessorTester(self							)







			@property
			def     snake_case__(					self			:    Optional[int]							)				->int:
									return self.image_processor_tester.prepare_image_processor_dict()







			def     snake_case__(					self			:    Any							)				->Dict:
									snake_case_       =     self.image_processing_class(**self.image_processor_dict							)
									self.assertTrue(hasattr(snake_case_							,       '''image_mean'''							)							)
									self.assertTrue(hasattr(snake_case_							,       '''image_std'''							)							)
									self.assertTrue(hasattr(snake_case_							,       '''do_normalize'''							)							)
									self.assertTrue(hasattr(snake_case_							,       '''do_resize'''							)							)
									self.assertTrue(hasattr(snake_case_							,       '''size'''							)							)







			def     snake_case__(					self			:    Tuple							)				->Union[str, Any]:
									snake_case_       =     self.image_processing_class.from_dict(self.image_processor_dict							)
									self.assertEqual(image_processor.size							,       {'''height''': 1_8, '''width''': 1_8}							)

									snake_case_       =     self.image_processing_class.from_dict(self.image_processor_dict							,       size=4_2							)
									self.assertEqual(image_processor.size							,       {'''height''': 4_2, '''width''': 4_2}							)







			def     snake_case__(					self			:    int							)				->Union[str, Any]:
									# Initialize image_processing
									snake_case_       =     self.image_processing_class(**self.image_processor_dict							)
									# create random PIL images
									snake_case_       =     prepare_image_inputs(self.image_processor_tester							,       equal_resolution=snake_case_							)
									for image in image_inputs:
															self.assertIsInstance(snake_case_							,       Image.Image							)

									# Test not batched input
									snake_case_       =     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.size['''height'''],
									        self.image_processor_tester.size['''width'''],
									    )							,       )

									# Test batched
									snake_case_       =     image_processing(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     snake_case__(					self			:    List[Any]							)				->int:
									# Initialize image_processing
									snake_case_       =     self.image_processing_class(**self.image_processor_dict							)
									# create random numpy tensors
									snake_case_       =     prepare_image_inputs(self.image_processor_tester							,       equal_resolution=snake_case_							,       numpify=snake_case_							)
									for image in image_inputs:
															self.assertIsInstance(snake_case_							,       np.ndarray							)

									# Test not batched input
									snake_case_       =     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.size['''height'''],
									        self.image_processor_tester.size['''width'''],
									    )							,       )

									# Test batched
									snake_case_       =     image_processing(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     snake_case__(					self			:    Optional[int]							)				->Union[str, Any]:
									# Initialize image_processing
									snake_case_       =     self.image_processing_class(**self.image_processor_dict							)
									# create random PyTorch tensors
									snake_case_       =     prepare_image_inputs(self.image_processor_tester							,       equal_resolution=snake_case_							,       torchify=snake_case_							)
									for image in image_inputs:
															self.assertIsInstance(snake_case_							,       torch.Tensor							)

									# Test not batched input
									snake_case_       =     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.size['''height'''],
									        self.image_processor_tester.size['''width'''],
									    )							,       )

									# Test batched
									snake_case_       =     image_processing(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   __SCREAMING_SNAKE_CASE (SCREAMING_SNAKE_CASE__	):
						snake_case_       =     5381
						for x in s:
												snake_case_       =     ((hash_value << 5) + hash_value) + ord(SCREAMING_SNAKE_CASE__	)
						return hash_value & 0xFF_FF_FF_FF