'''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 DeiTImageProcessor
class 							lowercase_    (     unittest.TestCase						):







    def __init__(	self       ,     UpperCamelCase__       ,     UpperCamelCase__=7       ,     UpperCamelCase__=3       ,     UpperCamelCase__=1_8       ,     UpperCamelCase__=3_0       ,     UpperCamelCase__=4_0_0       ,     UpperCamelCase__=True       ,     UpperCamelCase__=None       ,     UpperCamelCase__=True       ,     UpperCamelCase__=None       ,     UpperCamelCase__=True       ,     UpperCamelCase__=[0.5, 0.5, 0.5]       ,     UpperCamelCase__=[0.5, 0.5, 0.5]       ,     )				->       Any:





     """simple docstring"""

     UpperCAmelCase_				       =					size if size is not None else {"height": 2_0, "width": 2_0}
     UpperCAmelCase_				       =					crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}

     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   lowerCamelCase_    (	self				)				->       Union[str, Any]:





     """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 							lowercase_    (     _A ,  unittest.TestCase						):
    a_             =   DeiTImageProcessor if is_vision_available() else None
    a_             =   True







    def   lowerCamelCase_    (	self				)				->       int:





     """simple docstring"""

     UpperCAmelCase_				       =					DeiTImageProcessingTester(self				)







    @property
    def   lowerCamelCase_    (	self				)				->       int:





     """simple docstring"""

     return self.image_processor_tester.prepare_image_processor_dict()







    def   lowerCamelCase_    (	self				)				->       List[Any]:





     """simple docstring"""

     UpperCAmelCase_				       =					self.image_processing_class(**self.image_processor_dict				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "do_resize"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "size"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "do_center_crop"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "center_crop"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "do_normalize"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "image_mean"				)				)
     self.assertTrue(hasattr(UpperCamelCase__       ,     "image_std"				)				)







    def   lowerCamelCase_    (	self				)				->       int:





     """simple docstring"""

     UpperCAmelCase_				       =					self.image_processing_class.from_dict(self.image_processor_dict				)
     self.assertEqual(image_processor.size       ,     {"height": 2_0, "width": 2_0}				)
     self.assertEqual(image_processor.crop_size       ,     {"height": 1_8, "width": 1_8}				)

     UpperCAmelCase_				       =					self.image_processing_class.from_dict(self.image_processor_dict       ,     size=4_2       ,     crop_size=8_4				)
     self.assertEqual(image_processor.size       ,     {"height": 4_2, "width": 4_2}				)
     self.assertEqual(image_processor.crop_size       ,     {"height": 8_4, "width": 8_4}				)







    def   lowerCamelCase_    (	self				)				->       Union[str, Any]:





     """simple docstring"""

     pass







    def   lowerCamelCase_    (	self				)				->       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=UpperCamelCase__				)
     for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__       ,     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(UpperCamelCase__       ,     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				)				->       int:





     """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=UpperCamelCase__       ,     numpify=UpperCamelCase__				)
     for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__       ,     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(UpperCamelCase__       ,     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				)				->       Optional[int]:





     """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=UpperCamelCase__       ,     torchify=UpperCamelCase__				)
     for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__       ,     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(UpperCamelCase__       ,     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 ..utils import DummyObject, requires_backends
class 							lowercase_    (     metaclass=_A						):
    a_             =   ["""torch""", """librosa"""]







    def __init__(	self       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       int:





     """simple docstring"""

     requires_backends(self       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Union[str, Any]:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Dict:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)


class 							lowercase_    (     metaclass=_A						):
    a_             =   ["""torch""", """librosa"""]







    def __init__(	self       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       str:





     """simple docstring"""

     requires_backends(self       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Union[str, Any]:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       int:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)
