



"""simple docstring"""
import inspect

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
						import jax
@require_flax
class 							lowerCamelCase    :






					'''simple docstring'''





					def   lowerCAmelCase_							(			self:				Optional[Any]		)  ->      Optional[Any]:
											snake_case_,			snake_case_					:Dict		=     self.prepare_init_args_and_inputs_for_common()

											snake_case_					:int		=     self.model_class(**snake_case		)
											snake_case_					:str		=     model.init(inputs_dict["""prng_key"""]		,	inputs_dict["""sample"""]		)
											jax.lax.stop_gradient(snake_case		)

											snake_case_					:List[Any]		=     model.apply(snake_case		,	inputs_dict["""sample"""]		)

											if isinstance(snake_case		,	snake_case		):
																	snake_case_					:Optional[Any]		=     output.sample

											self.assertIsNotNone(snake_case		)
											snake_case_					:List[Any]		=     inputs_dict["""sample"""].shape
											self.assertEqual(output.shape		,	snake_case		,	"""Input and output shapes do not match"""		)






					def   lowerCAmelCase_							(			self:				List[Any]		)  ->      str:
											snake_case_,			snake_case_					:Tuple		=     self.prepare_init_args_and_inputs_for_common()

											snake_case_					:Tuple		=     16
											snake_case_					:Optional[int]		=     (16, 32)

											snake_case_					:Any		=     self.model_class(**snake_case		)
											snake_case_					:Optional[int]		=     model.init(inputs_dict["""prng_key"""]		,	inputs_dict["""sample"""]		)
											jax.lax.stop_gradient(snake_case		)

											snake_case_					:List[str]		=     model.apply(snake_case		,	inputs_dict["""sample"""]		)

											if isinstance(snake_case		,	snake_case		):
																	snake_case_					:Optional[Any]		=     output.sample

											self.assertIsNotNone(snake_case		)
											snake_case_					:List[str]		=     inputs_dict["""sample"""].shape
											self.assertEqual(output.shape		,	snake_case		,	"""Input and output shapes do not match"""		)






					def   lowerCAmelCase_							(			self:				Optional[Any]		)  ->      Optional[int]:
											snake_case_					:Dict		=     """kwargs""" in inspect.signature(self.model_class.__init__		).parameters
											snake_case_					:Optional[Any]		=     len(self.model_class._deprecated_kwargs		) > 0

											if has_kwarg_in_model_class and not has_deprecated_kwarg:
																	raise ValueError(
																	    f"""{self.model_class} has `**kwargs` in its __init__ method but has not defined any deprecated kwargs"""
																	    """ under the `_deprecated_kwargs` class attribute. Make sure to either remove `**kwargs` if there are"""
																	    """ no deprecated arguments or add the deprecated argument with `_deprecated_kwargs ="""
																	    """ [<deprecated_argument>]`"""		)

											if not has_kwarg_in_model_class and has_deprecated_kwarg:
																	raise ValueError(
																	    f"""{self.model_class} doesn't have `**kwargs` in its __init__ method but has defined deprecated kwargs"""
																	    """ under the `_deprecated_kwargs` class attribute. Make sure to either add the `**kwargs` argument to"""
																	    f""" {self.model_class}.__init__ if there are deprecated arguments or remove the deprecated argument"""
																	    """ from `_deprecated_kwargs = [<deprecated_argument>]`"""		)

"""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 OwlViTImageProcessor






class  a__     ( unittest.TestCase						):


   def __init__(  self,					_UpperCAmelCase,					_UpperCAmelCase=7,					_UpperCAmelCase=3,					_UpperCAmelCase=18,					_UpperCAmelCase=30,					_UpperCAmelCase=400,					_UpperCAmelCase=True,					_UpperCAmelCase=None,					_UpperCAmelCase=True,					_UpperCAmelCase=None,					_UpperCAmelCase=True,					_UpperCAmelCase=[0.48_145_466, 0.4_578_275, 0.40_821_073],					_UpperCAmelCase=[0.26_862_954, 0.26_130_258, 0.27_577_711],					_UpperCAmelCase=True,					):
        '''simple docstring'''



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


   def 						snake_case__						(  self	):
        '''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,
            "do_convert_rgb": self.do_convert_rgb,
        }






@require_torch
@require_vision
class  a__     ( _a       ,       unittest.TestCase						):
   snake_case_				=   OwlViTImageProcessor if is_vision_available() else None


   def 						snake_case__						(  self	):
        '''simple docstring'''



        lowercase__								=				OwlViTImageProcessingTester(self	)


   @property
   def 						snake_case__						(  self	):
        '''simple docstring'''



        return self.image_processor_tester.prepare_image_processor_dict()


   def 						snake_case__						(  self	):
        '''simple docstring'''



        lowercase__								=				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"	)	)
        self.assertTrue(hasattr(_UpperCAmelCase,					"do_convert_rgb"	)	)


   def 						snake_case__						(  self	):
        '''simple docstring'''



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

        lowercase__								=				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	):
        '''simple docstring'''



        lowercase__								=				self.image_processing_class(**self.image_processor_dict	)
        # create random PIL images
        lowercase__								=				prepare_image_inputs(self.image_processor_tester,					equal_resolution=_UpperCAmelCase	)

        for image in image_inputs:
             self.assertIsInstance(_UpperCAmelCase,					Image.Image	)

        # Test not batched input
        lowercase__								=				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
        lowercase__								=				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 						snake_case__						(  self	):
        '''simple docstring'''



        lowercase__								=				self.image_processing_class(**self.image_processor_dict	)
        # create random numpy tensors
        lowercase__								=				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
        lowercase__								=				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
        lowercase__								=				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 						snake_case__						(  self	):
        '''simple docstring'''



        lowercase__								=				self.image_processing_class(**self.image_processor_dict	)
        # create random PyTorch tensors
        lowercase__								=				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
        lowercase__								=				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
        lowercase__								=				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"],
            ),					)




