





'''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        __lowerCAmelCase  (					unittest.TestCase				):






       """simple docstring"""





       def __init__(							self     :	Union[str, Any] ,				lowerCAmelCase__     :	List[Any] ,				lowerCAmelCase__     :	List[str]=7 ,				lowerCAmelCase__     :	Union[str, Any]=3 ,				lowerCAmelCase__     :	Any=18 ,				lowerCAmelCase__     :	int=30 ,				lowerCAmelCase__     :	List[Any]=400 ,				lowerCAmelCase__     :	Union[str, Any]=True ,				lowerCAmelCase__     :	int=None ,				lowerCAmelCase__     :	int=True ,				lowerCAmelCase__     :	List[Any]=None ,				lowerCAmelCase__     :	Union[str, Any]=True ,				lowerCAmelCase__     :	Dict=[0.48145466, 0.4578275, 0.40821073] ,				lowerCAmelCase__     :	Optional[Any]=[0.26862954, 0.26130258, 0.27577711] ,				lowerCAmelCase__     :	List[Any]=True ,				)					->  List[Any]:

            '''simple docstring'''




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







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

@require_torch
@require_vision
class        __lowerCAmelCase  (					__magic_name__		,		unittest.TestCase				):






       """simple docstring"""
       _snake_case			:  Optional[int]		       =					OwlViTImageProcessor if is_vision_available() else None





       def snake_case__		(							self     :	Optional[int]  )					->  Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase       					= OwlViTImageProcessingTester(self  )





       @property
       def snake_case__		(							self     :	List[str]  )					->  str:

            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()





       def snake_case__		(							self     :	str  )					->  Tuple:

            '''simple docstring'''




            _UpperCamelCase       					= self.image_processing_class(**self.image_processor_dict  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''do_resize'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''size'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''do_center_crop'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''center_crop'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''do_normalize'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''image_mean'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''image_std'''  )  )
            self.assertTrue(hasattr(lowerCAmelCase__ ,				'''do_convert_rgb'''  )  )





       def snake_case__		(							self     :	Optional[Any]  )					->  List[str]:

            '''simple docstring'''




            _UpperCamelCase       					= 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}  )

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

            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__ ,				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(lowerCAmelCase__ ,				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]  )					->  List[Any]:

            '''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=lowerCAmelCase__ ,				numpify=lowerCAmelCase__  )
            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__ ,				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(lowerCAmelCase__ ,				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  )					->  List[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=lowerCAmelCase__ ,				torchify=lowerCAmelCase__  )
            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__ ,				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(lowerCAmelCase__ ,				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'''

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 snake_case__		(							self     :	str  )					->  Any:

            '''simple docstring'''




            _UpperCamelCase					,       _UpperCamelCase       					= self.prepare_init_args_and_inputs_for_common()

            _UpperCamelCase       					= self.model_class(**lowerCAmelCase__  )
            _UpperCamelCase       					= model.init(inputs_dict['''prng_key'''] ,				inputs_dict['''sample''']  )
            jax.lax.stop_gradient(lowerCAmelCase__  )

            _UpperCamelCase       					= model.apply(lowerCAmelCase__ ,				inputs_dict['''sample''']  )

            if isinstance(lowerCAmelCase__ ,				lowerCAmelCase__  ):
                 _UpperCamelCase       					= output.sample

            self.assertIsNotNone(lowerCAmelCase__  )
            _UpperCamelCase       					= inputs_dict['''sample'''].shape
            self.assertEqual(output.shape ,				lowerCAmelCase__ ,				'''Input and output shapes do not match'''  )





       def snake_case__		(							self     :	Any  )					->  int:

            '''simple docstring'''




            _UpperCamelCase					,       _UpperCamelCase       					= self.prepare_init_args_and_inputs_for_common()

            _UpperCamelCase       					= 16
            _UpperCamelCase       					= (16, 32)

            _UpperCamelCase       					= self.model_class(**lowerCAmelCase__  )
            _UpperCamelCase       					= model.init(inputs_dict['''prng_key'''] ,				inputs_dict['''sample''']  )
            jax.lax.stop_gradient(lowerCAmelCase__  )

            _UpperCamelCase       					= model.apply(lowerCAmelCase__ ,				inputs_dict['''sample''']  )

            if isinstance(lowerCAmelCase__ ,				lowerCAmelCase__  ):
                 _UpperCamelCase       					= output.sample

            self.assertIsNotNone(lowerCAmelCase__  )
            _UpperCamelCase       					= inputs_dict['''sample'''].shape
            self.assertEqual(output.shape ,				lowerCAmelCase__ ,				'''Input and output shapes do not match'''  )







       def snake_case__		(							self     :	int  )					->  int:

            '''simple docstring'''




            _UpperCamelCase       					= '''kwargs''' in inspect.signature(self.model_class.__init__  ).parameters
            _UpperCamelCase       					= 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>]`'''  )



