


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):
					def __init__(						self       :						List[str]	,      _lowerCAmelCase       :						Dict	,      _lowerCAmelCase       :						Dict=1_3	,      _lowerCAmelCase       :						Union[str, Any]=3	,      _lowerCAmelCase       :						str=1_8	,      _lowerCAmelCase       :						Optional[int]=3_0	,      _lowerCAmelCase       :						List[Any]=4_0_0	,      _lowerCAmelCase       :						Optional[Any]=True	,      _lowerCAmelCase       :						str=None	,      _lowerCAmelCase       :						Any=True	,      _lowerCAmelCase       :						int=[0.5, 0.5, 0.5]	,      _lowerCAmelCase       :						List[Any]=[0.5, 0.5, 0.5]	,      )							->					Any:



											'''simple docstring'''





											__magic_name__					=      size if size is not None else {'height': 1_8, 'width': 1_8}
											__magic_name__					=      parent
											__magic_name__					=      batch_size
											__magic_name__					=      num_channels
											__magic_name__					=      image_size
											__magic_name__					=      min_resolution
											__magic_name__					=      max_resolution
											__magic_name__					=      do_resize
											__magic_name__					=      size
											__magic_name__					=      do_normalize
											__magic_name__					=      image_mean
											__magic_name__					=      image_std







					def 	a			(						self       :						Optional[int]  )							->					Dict:



											'''simple docstring'''





											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				(   _UpperCAmelCase	,      unittest.TestCase):
					SCREAMING_SNAKE_CASE_		:       int								=			EfficientNetImageProcessor if is_vision_available() else None
					def 	a			(						self       :						str  )							->					List[str]:



											'''simple docstring'''





											__magic_name__					=      EfficientNetImageProcessorTester(self  )
					@property
					def 	a			(						self       :						Any  )							->					Union[str, Any]:



											'''simple docstring'''





											return self.image_processor_tester.prepare_image_processor_dict()
					def 	a			(						self       :						List[str]  )							->					int:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class(**self.image_processor_dict  )
											self.assertTrue(hasattr(_lowerCAmelCase	,      'image_mean'  )  )
											self.assertTrue(hasattr(_lowerCAmelCase	,      'image_std'  )  )
											self.assertTrue(hasattr(_lowerCAmelCase	,      'do_normalize'  )  )
											self.assertTrue(hasattr(_lowerCAmelCase	,      'do_resize'  )  )
											self.assertTrue(hasattr(_lowerCAmelCase	,      'size'  )  )
					def 	a			(						self       :						List[Any]  )							->					Tuple:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class.from_dict(self.image_processor_dict  )
											self.assertEqual(image_processor.size	,      {'height': 1_8, 'width': 1_8}  )

											__magic_name__					=      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 	a			(						self       :						str  )							->					Tuple:



											'''simple docstring'''





											__magic_name__					=      self.image_processing_class(**self.image_processor_dict  )
											# create random PIL images
											__magic_name__					=      prepare_image_inputs(self.image_processor_tester	,      equal_resolution=_lowerCAmelCase  )
											for image in image_inputs:
																	self.assertIsInstance(_lowerCAmelCase	,      Image.Image  )

											# Test not batched input
											__magic_name__					=      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
											__magic_name__					=      image_processing(_lowerCAmelCase	,      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 	a			(						self       :						Optional[Any]  )							->					List[str]:



											'''simple docstring'''





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

											# Test not batched input
											__magic_name__					=      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
											__magic_name__					=      image_processing(_lowerCAmelCase	,      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 	a			(						self       :						List[str]  )							->					List[str]:



											'''simple docstring'''





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

											# Test not batched input
											__magic_name__					=      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
											__magic_name__					=      image_processing(_lowerCAmelCase	,      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'],
											    )	,      )





from ..utils import DummyObject, requires_backends

class      __snake_case				(   metaclass=_UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:       str								=			["torch", "transformers", "k_diffusion"]
					def __init__(						self       :						Tuple	,      *_lowerCAmelCase       :						Union[str, Any]	,      **_lowerCAmelCase       :						Union[str, Any]  )							->					Dict:



											'''simple docstring'''





											requires_backends(self	,      ['torch', 'transformers', 'k_diffusion']  )
					@classmethod
					def 	a			(						cls       :						Optional[int]	,      *_lowerCAmelCase       :						Any	,      **_lowerCAmelCase       :						Optional[Any]  )							->					Optional[Any]:



											'''simple docstring'''





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







					@classmethod
					def 	a			(						cls       :						Union[str, Any]	,      *_lowerCAmelCase       :						Tuple	,      **_lowerCAmelCase       :						str  )							->					Tuple:



											'''simple docstring'''





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

