




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 			A			(		unittest.TestCase		):
     """simple docstring"""

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




     def  __snake_case   (    self  :   str			)				->       Dict:
           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 			A			(		_lowerCAmelCase			,						unittest.TestCase		):
     """simple docstring"""

     _snake_case:	Any     =EfficientNetImageProcessor if is_vision_available() else None




     def  __snake_case   (    self  :   Optional[Any]			)				->       List[Any]:
           lowerCamelCase__        =				EfficientNetImageProcessorTester(self			)




     @property
     def  __snake_case   (    self  :   Optional[Any]			)				->       Tuple:
           return self.image_processor_tester.prepare_image_processor_dict()




     def  __snake_case   (    self  :   List[str]			)				->       Tuple:
           lowerCamelCase__        =				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  __snake_case   (    self  :   Union[str, Any]			)				->       int:
           lowerCamelCase__        =				self.image_processing_class.from_dict(self.image_processor_dict			)
           self.assertEqual(image_processor.size	,  {'height': 1_8, 'width': 1_8}			)

           lowerCamelCase__        =				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  :   Tuple			)				->       Union[str, Any]:
           # Initialize image_processing
           lowerCamelCase__        =				self.image_processing_class(**self.image_processor_dict			)
           # create random PIL images
           lowerCamelCase__        =				prepare_image_inputs(self.image_processor_tester	,  equal_resolution=A__			)
           for image in image_inputs:
                 self.assertIsInstance(A__	,  Image.Image			)

           # Test not batched input
           lowerCamelCase__        =				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
           lowerCamelCase__        =				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  __snake_case   (    self  :   Dict			)				->       str:
           # Initialize image_processing
           lowerCamelCase__        =				self.image_processing_class(**self.image_processor_dict			)
           # create random numpy tensors
           lowerCamelCase__        =				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
           lowerCamelCase__        =				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
           lowerCamelCase__        =				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  __snake_case   (    self  :   Dict			)				->       List[Any]:
           # Initialize image_processing
           lowerCamelCase__        =				self.image_processing_class(**self.image_processor_dict			)
           # create random PyTorch tensors
           lowerCamelCase__        =				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
           lowerCamelCase__        =				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
           lowerCamelCase__        =				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'],
               )	,  )





from ..utils import DummyObject, requires_backends






class 			A			(		metaclass=_lowerCAmelCase		):
     """simple docstring"""

     _snake_case:	Optional[Any]     =["torch", "transformers", "invisible_watermark"]




     def __init__(    self  :   Dict	,  *A__  :   Optional[int]	,  **A__  :   Dict			)				->       Union[str, Any]:
           requires_backends(self	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   Optional[int]	,  *A__  :   Dict	,  **A__  :   List[str]			)				->       Union[str, Any]:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   Optional[Any]	,  *A__  :   Dict	,  **A__  :   List[Any]			)				->       Dict:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)






class 			A			(		metaclass=_lowerCAmelCase		):
     """simple docstring"""

     _snake_case:	Dict     =["torch", "transformers", "invisible_watermark"]




     def __init__(    self  :   List[str]	,  *A__  :   str	,  **A__  :   int			)				->       List[Any]:
           requires_backends(self	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   str	,  *A__  :   Any	,  **A__  :   Dict			)				->       Optional[Any]:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   List[str]	,  *A__  :   Optional[Any]	,  **A__  :   int			)				->       Dict:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)