code: 
  
  
  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
  
  
  if is_torch_available():
      import torch
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import SwinaSRImageProcessor
      from transformers.image_transforms import get_image_size
  
  
  
  
  
  class   __lowerCamelCase (unittest.TestCase	):
  
  
  
  
  
  
  
         def __init__( self:   Tuple,A_:   Union[str, Any],A_:   Optional[int]=7,A_:   Tuple=3,A_:   Any=18,A_:   str=30,A_:   Tuple=400,A_:   Optional[Any]=True,A_:   Union[str, Any]=1 / 255,A_:   int=True,A_:   List[str]=8,):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = parent
              __UpperCamelCase   = batch_size
              __UpperCamelCase   = num_channels
              __UpperCamelCase   = image_size
              __UpperCamelCase   = min_resolution
              __UpperCamelCase   = max_resolution
              __UpperCamelCase   = do_rescale
              __UpperCamelCase   = rescale_factor
              __UpperCamelCase   = do_pad
              __UpperCamelCase   = pad_size
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Tuple				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              return {
                  "do_rescale": self.do_rescale,
                  "rescale_factor": self.rescale_factor,
                  "do_pad": self.do_pad,
                  "pad_size": self.pad_size,
              }
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   int,A_:   Tuple=False,A_:   str=False,A_:   Dict=False				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
              if equal_resolution:
                   __UpperCamelCase   = []
                   for i in range(self.batch_size				):
                        image_inputs.append(
                            np.random.randint(
                                255,size=(self.num_channels, self.max_resolution, self.max_resolution),dtype=np.uinta				)				)
              else:
                   __UpperCamelCase   = []
                   for i in range(self.batch_size				):
                        __UpperCamelCase,						__UpperCamelCase   = np.random.choice(np.arange(self.min_resolution,self.max_resolution				),2				)
                        image_inputs.append(np.random.randint(255,size=(self.num_channels, width, height),dtype=np.uinta				)				)
  
              if not numpify and not torchify:
                   # PIL expects the channel dimension as last dimension
                   __UpperCamelCase   = [Image.fromarray(np.moveaxis(A_,0,-1				)				) for x in image_inputs]
  
              if torchify:
                   __UpperCamelCase   = [torch.from_numpy(A_				) for x in image_inputs]
  
              return image_inputs
  
  
  
  
  
  @require_torch
  @require_vision
  class   __lowerCamelCase (_a							,			unittest.TestCase	):
         _lowercase       							=    SwinaSRImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   List[Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = SwinaSRImageProcessingTester(self				)
  
  
  
  
  
  
  
         @property
         def 		snake_case_  ( self:   Union[str, Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Tuple				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              self.assertTrue(hasattr(A_,'do_rescale'				)				)
              self.assertTrue(hasattr(A_,'rescale_factor'				)				)
              self.assertTrue(hasattr(A_,'do_pad'				)				)
              self.assertTrue(hasattr(A_,'pad_size'				)				)
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   str				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              pass
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[int],A_:   List[Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase,						__UpperCamelCase   = get_image_size(A_				)
              __UpperCamelCase   = self.image_processor_tester.pad_size
  
              __UpperCamelCase   = (old_height // size + 1) * size - old_height
              __UpperCamelCase   = (old_width // size + 1) * size - old_width
              return old_height + pad_height, old_width + pad_width
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[int]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random PIL images
              __UpperCamelCase   = self.image_processor_tester.prepare_inputs(equal_resolution=A_				)
              for image in image_inputs:
                   self.assertIsInstance(A_,Image.Image				)
  
              # Test not batched input
              __UpperCamelCase   = image_processor(image_inputs[0],return_tensors='pt'				).pixel_values
              __UpperCamelCase,						__UpperCamelCase   = self.calculate_expected_size(np.array(image_inputs[0]				)				)
              self.assertEqual(
                  encoded_images.shape,(
                      1,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  ),)
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Tuple				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random numpy tensors
              __UpperCamelCase   = self.image_processor_tester.prepare_inputs(equal_resolution=A_,numpify=A_				)
              for image in image_inputs:
                   self.assertIsInstance(A_,np.ndarray				)
  
              # Test not batched input
              __UpperCamelCase   = image_processor(image_inputs[0],return_tensors='pt'				).pixel_values
              __UpperCamelCase,						__UpperCamelCase   = self.calculate_expected_size(image_inputs[0]				)
              self.assertEqual(
                  encoded_images.shape,(
                      1,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  ),)
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Union[str, Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random PyTorch tensors
              __UpperCamelCase   = self.image_processor_tester.prepare_inputs(equal_resolution=A_,torchify=A_				)
              for image in image_inputs:
                   self.assertIsInstance(A_,torch.Tensor				)
  
              # Test not batched input
              __UpperCamelCase   = image_processor(image_inputs[0],return_tensors='pt'				).pixel_values
              __UpperCamelCase,						__UpperCamelCase   = self.calculate_expected_size(image_inputs[0]				)
              self.assertEqual(
                  encoded_images.shape,(
                      1,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  ),)
  
  
  
style_context: 
  
  
  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 DeiTImageProcessor
  
  
  
  class   __lowerCamelCase (unittest.TestCase	):
  
  
  
  
  
  
  
         def __init__( self:   List[str],A_:   List[Any],A_:   List[Any]=7,A_:   str=3,A_:   Tuple=18,A_:   Union[str, Any]=30,A_:   Union[str, Any]=400,A_:   List[str]=True,A_:   List[Any]=None,A_:   Tuple=True,A_:   Union[str, Any]=None,A_:   int=True,A_:   Any=[0.5, 0.5, 0.5],A_:   Optional[Any]=[0.5, 0.5, 0.5],):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = size if size is not None else {'height': 20, 'width': 20}
              __UpperCamelCase   = crop_size if crop_size is not None else {'height': 18, 'width': 18}
  
              __UpperCamelCase   = parent
              __UpperCamelCase   = batch_size
              __UpperCamelCase   = num_channels
              __UpperCamelCase   = image_size
              __UpperCamelCase   = min_resolution
              __UpperCamelCase   = max_resolution
              __UpperCamelCase   = do_resize
              __UpperCamelCase   = size
              __UpperCamelCase   = do_center_crop
              __UpperCamelCase   = crop_size
              __UpperCamelCase   = do_normalize
              __UpperCamelCase   = image_mean
              __UpperCamelCase   = image_std
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   List[str]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              return {
                  "do_resize": self.do_resize,
                  "size": self.size,
                  "do_center_crop": self.do_center_crop,
                  "crop_size": self.crop_size,
                  "do_normalize": self.do_normalize,
                  "image_mean": self.image_mean,
                  "image_std": self.image_std,
              }
  
  
  
  @require_torch
  @require_vision
  class   __lowerCamelCase (_a							,			unittest.TestCase	):
         _lowercase       							=    DeiTImageProcessor if is_vision_available() else None
         _lowercase       							=    True
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   List[Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = DeiTImageProcessingTester(self				)
  
  
  
  
  
  
  
         @property
         def 		snake_case_  ( self:   Optional[int]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Union[str, Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              self.assertTrue(hasattr(A_,'do_resize'				)				)
              self.assertTrue(hasattr(A_,'size'				)				)
              self.assertTrue(hasattr(A_,'do_center_crop'				)				)
              self.assertTrue(hasattr(A_,'center_crop'				)				)
              self.assertTrue(hasattr(A_,'do_normalize'				)				)
              self.assertTrue(hasattr(A_,'image_mean'				)				)
              self.assertTrue(hasattr(A_,'image_std'				)				)
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[int]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class.from_dict(self.image_processor_dict				)
              self.assertEqual(image_processor.size,{'height': 20, 'width': 20}				)
              self.assertEqual(image_processor.crop_size,{'height': 18, 'width': 18}				)
  
              __UpperCamelCase   = self.image_processing_class.from_dict(self.image_processor_dict,size=42,crop_size=84				)
              self.assertEqual(image_processor.size,{'height': 42, 'width': 42}				)
              self.assertEqual(image_processor.crop_size,{'height': 84, 'width': 84}				)
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Tuple				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              pass
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[int]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random PIL images
              __UpperCamelCase   = prepare_image_inputs(self.image_processor_tester,equal_resolution=A_				)
              for image in image_inputs:
                   self.assertIsInstance(A_,Image.Image				)
  
              # Test not batched input
              __UpperCamelCase   = 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
              __UpperCamelCase   = 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 		snake_case_  ( self:   List[str]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random numpy tensors
              __UpperCamelCase   = 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
              __UpperCamelCase   = 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
              __UpperCamelCase   = 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 		snake_case_  ( self:   Any				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = self.image_processing_class(**self.image_processor_dict				)
              # create random PyTorch tensors
              __UpperCamelCase   = 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
              __UpperCamelCase   = 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
              __UpperCamelCase   = 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'],
                  ),)
  
  
  