






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

class   _UpperCAmelCase     (	unittest.TestCase		):




   """simple docstring"""

   def __init__(						self					:      int , __UpperCAmelCase					:      Any , __UpperCAmelCase					:      Tuple=7 , __UpperCAmelCase					:      Tuple=3 , __UpperCAmelCase					:      List[str]=18 , __UpperCAmelCase					:      Union[str, Any]=30 , __UpperCAmelCase					:      Any=400 , __UpperCAmelCase					:      Any=True , __UpperCAmelCase					:      List[Any]=None , __UpperCAmelCase					:      Union[str, Any]=True , __UpperCAmelCase					:      Any=None , __UpperCAmelCase					:      Tuple=True , __UpperCAmelCase					:      Dict=[0.5, 0.5, 0.5] , __UpperCAmelCase					:      int=[0.5, 0.5, 0.5] , ):





         '''simple docstring'''





         _A     	=      size if size is not None else {'shortest_edge': 18}
         _A     	=      crop_size if crop_size is not None else {'height': 18, 'width': 18}
         _A     	=      parent
         _A     	=      batch_size
         _A     	=      num_channels
         _A     	=      image_size
         _A     	=      min_resolution
         _A     	=      max_resolution
         _A     	=      do_resize
         _A     	=      size
         _A     	=      do_center_crop
         _A     	=      crop_size
         _A     	=      do_normalize
         _A     	=      image_mean
         _A     	=      image_std

   def 		lowerCAmelCase					(						self					:      Any						):





         '''simple docstring'''





         return {
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_normalize": self.do_normalize,
             "do_resize": self.do_resize,
             "do_center_crop": self.do_center_crop,
             "size": self.size,
             "crop_size": self.crop_size,
         }





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




   """simple docstring"""

   snake_case       							=		LevitImageProcessor if is_vision_available() else None

   def 		lowerCAmelCase					(						self					:      Any						):





         '''simple docstring'''





         _A     	=      LevitImageProcessingTester(self						)

   @property
   def 		lowerCAmelCase					(						self					:      Optional[int]						):





         '''simple docstring'''





         return self.image_processor_tester.prepare_image_processor_dict()

   def 		lowerCAmelCase					(						self					:      List[str]						):





         '''simple docstring'''





         _A     	=      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_ , "do_center_crop"						)						)
         self.assertTrue(hasattr(a_ , "size"						)						)

   def 		lowerCAmelCase					(						self					:      Union[str, Any]						):





         '''simple docstring'''





         _A     	=      self.image_processing_class.from_dict(self.image_processor_dict						)
         self.assertEqual(image_processor.size , {"shortest_edge": 18}						)
         self.assertEqual(image_processor.crop_size , {"height": 18, "width": 18}						)

         _A     	=      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					:      int						):





         '''simple docstring'''





         pass

   def 		lowerCAmelCase					(						self					:      Tuple						):





         '''simple docstring'''





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

         # Test not batched input
         _A     	=      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
         _A     	=      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.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             ) , )

   def 		lowerCAmelCase					(						self					:      Union[str, Any]						):





         '''simple docstring'''





         _A     	=      self.image_processing_class(**self.image_processor_dict						)
         # create random numpy tensors
         _A     	=      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
         _A     	=      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
         _A     	=      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.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             ) , )

   def 		lowerCAmelCase					(						self					:      List[str]						):





         '''simple docstring'''





         _A     	=      self.image_processing_class(**self.image_processor_dict						)
         # create random PyTorch tensors
         _A     	=      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
         _A     	=      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
         _A     	=      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.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             ) , )










'''simple docstring'''

from diffusers.utils.testing_utils import require_onnxruntime






@require_onnxruntime
class 						a_		:
							pass




