




'''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 EfficientNetImageProcessor

class 	SCREAMING_SNAKE_CASE_		(							unittest.TestCase					):



 def __init__(	self ,		A ,		A=13 ,		A=3 ,		A=18 ,		A=30 ,		A=400 ,		A=True ,		A=None ,		A=True ,		A=[0.5, 0.5, 0.5] ,		A=[0.5, 0.5, 0.5] ,		):






        '''simple docstring'''




        lowercase	:		Optional[Any]    =   size if size is not None else {'''height''': 18, '''width''': 18}
        lowercase	:		str    =   parent
        lowercase	:		Optional[int]    =   batch_size
        lowercase	:		Optional[int]    =   num_channels
        lowercase	:		Any    =   image_size
        lowercase	:		List[Any]    =   min_resolution
        lowercase	:		Any    =   max_resolution
        lowercase	:		List[str]    =   do_resize
        lowercase	:		Tuple    =   size
        lowercase	:		Dict    =   do_normalize
        lowercase	:		Optional[Any]    =   image_mean
        lowercase	:		Tuple    =   image_std





 def  SCREAMING_SNAKE_CASE(	self			):






        '''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 	SCREAMING_SNAKE_CASE_		(							lowerCamelCase_		,  unittest.TestCase					):
 __snake_case						:  Optional[int]       =   EfficientNetImageProcessor if is_vision_available() else None



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        lowercase	:		List[str]    =   EfficientNetImageProcessorTester(self			)



 @property
 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        return self.image_processor_tester.prepare_image_processor_dict()



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        lowercase	:		Tuple    =   self.image_processing_class(**self.image_processor_dict			)
        self.assertTrue(hasattr(A ,		'''image_mean'''			)			)
        self.assertTrue(hasattr(A ,		'''image_std'''			)			)
        self.assertTrue(hasattr(A ,		'''do_normalize'''			)			)
        self.assertTrue(hasattr(A ,		'''do_resize'''			)			)
        self.assertTrue(hasattr(A ,		'''size'''			)			)



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        lowercase	:		List[Any]    =   self.image_processing_class.from_dict(self.image_processor_dict			)
        self.assertEqual(image_processor.size ,		{'''height''': 18, '''width''': 18}			)

        lowercase	:		Union[str, Any]    =   self.image_processing_class.from_dict(self.image_processor_dict ,		size=42			)
        self.assertEqual(image_processor.size ,		{'''height''': 42, '''width''': 42}			)



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




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

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

        # Test batched
        lowercase	:		str    =   image_processing(A ,		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(	self			):






        '''simple docstring'''




        lowercase	:		int    =   self.image_processing_class(**self.image_processor_dict			)
        # create random numpy tensors
        lowercase	:		Optional[int]    =   prepare_image_inputs(self.image_processor_tester ,		equal_resolution=A ,		numpify=A			)
        for image in image_inputs:
               self.assertIsInstance(A ,		np.ndarray			)

        # Test not batched input
        lowercase	:		int    =   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
        lowercase	:		Dict    =   image_processing(A ,		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(	self			):






        '''simple docstring'''




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

        # Test not batched input
        lowercase	:		Optional[int]    =   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
        lowercase	:		Optional[int]    =   image_processing(A ,		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'''],
            ) ,		)










'''simple docstring'''






from __future__ import annotations

from enum import Enum, unique
from typing import TypeVar

# Create a generic variable that can be 'Enum', or any subclass.
lowercase						:   Any      						=							TypeVar('''T''', bound='''Enum''')

@unique
class 	SCREAMING_SNAKE_CASE_		(							lowerCamelCase_					):
 __snake_case						:  Union[str, Any]       =   8_0
 __snake_case						:  Optional[Any]       =   7_0
 __snake_case						:  List[str]       =   6_0
 __snake_case						:  str       =   5_0
 __snake_case						:  Tuple       =   4_0
 __snake_case						:  Union[str, Any]       =   3_0
 __snake_case						:  Dict       =   2_0
 __snake_case						:  str       =   1_0






@unique
class 	SCREAMING_SNAKE_CASE_		(							lowerCamelCase_					):
 __snake_case						:  Optional[Any]       =   2_4
 __snake_case						:  List[str]       =   2_1
 __snake_case						:  Any       =   1_8
 __snake_case						:  Union[str, Any]       =   1_5
 __snake_case						:  Dict       =   1_2
 __snake_case						:  Union[str, Any]       =   9
 __snake_case						:  List[str]       =   6
 __snake_case						:  Optional[int]       =   3
 __snake_case						:  Tuple       =   2
 __snake_case						:  Any       =   1
 __snake_case						:  Optional[int]       =   -1
 __snake_case						:  Optional[int]       =   -2
 __snake_case						:  str       =   -3
 __snake_case						:  Optional[Any]       =   -6
 __snake_case						:  Optional[int]       =   -9
 __snake_case						:  List[Any]       =   -1_2
 __snake_case						:  str       =   -1_5
 __snake_case						:  str       =   -1_8
 __snake_case						:  Dict       =   -2_1
 __snake_case						:  int       =   -2_4



 @classmethod
 def  SCREAMING_SNAKE_CASE(	cls			):






        '''simple docstring'''




        return {unit.name: unit.value for unit in cls if unit.value > 0}





 @classmethod
 def  SCREAMING_SNAKE_CASE(	cls			):






        '''simple docstring'''




        return {unit.name: unit.value for unit in cls if unit.value < 0}






def 		a_(			lowerCamelCase   )					->str:






       '''simple docstring'''




       lowercase	:		Tuple    =   SIUnit.get_positive() if value > 0 else SIUnit.get_negative()
       for name_prefix, value_prefix in prefixes.items():
              lowercase	:		Dict    =   value / (10**value_prefix)
              if numerical_part > 1:
                     return f"""{numerical_part!s} {name_prefix}"""
       return str(lowerCamelCase   )




def 		a_(			lowerCamelCase   )					->str:






       '''simple docstring'''




       for prefix in BinaryUnit:
              lowercase	:		Dict    =   value / (2**prefix.value)
              if numerical_part > 1:
                     return f"""{numerical_part!s} {prefix.name}"""
       return str(lowerCamelCase   )


if __name__ == "__main__":
      import doctest

      doctest.testmod()




