





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

       def __init__(		self:			Union[str, Any]       , _SCREAMING_SNAKE_CASE:			str       , _SCREAMING_SNAKE_CASE:			Optional[int]=7       , _SCREAMING_SNAKE_CASE:			Any=3       , _SCREAMING_SNAKE_CASE:			Any=18       , _SCREAMING_SNAKE_CASE:			str=30       , _SCREAMING_SNAKE_CASE:			List[Any]=400       , _SCREAMING_SNAKE_CASE:			Tuple=True       , _SCREAMING_SNAKE_CASE:			Optional[int]=None       , _SCREAMING_SNAKE_CASE:			Tuple=True       , _SCREAMING_SNAKE_CASE:			List[str]=None       , _SCREAMING_SNAKE_CASE:			Optional[int]=True       , _SCREAMING_SNAKE_CASE:			List[Any]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]       , _SCREAMING_SNAKE_CASE:			int=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]       , _SCREAMING_SNAKE_CASE:			Union[str, 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 lowercase			(		self:			List[str]		)							->			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 				_UpperCamelCase       (						_a	,    unittest.TestCase  ):
       _UpperCamelCase					:       int       = OwlViTImageProcessor if is_vision_available() else None

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




              """simple docstring"""


              UpperCamelCase_ 							=	OwlViTImageProcessingTester(self		)

       @property
       def lowercase			(		self:			Union[str, Any]		)							->			Any:




              """simple docstring"""


              return self.image_processor_tester.prepare_image_processor_dict()

       def lowercase			(		self:			Union[str, Any]		)							->			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"		)		)
              self.assertTrue(hasattr(_UpperCAmelCase       , "do_convert_rgb"		)		)

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




              """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 lowercase			(		self:			Any		)							->			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 lowercase			(		self:			Tuple		)							->			Optional[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 lowercase			(		self:			str		)							->			List[str]:




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


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"],
            ),					)




