



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    ,  lowercase_    ,  lowercase_=7    ,  lowercase_=3    ,  lowercase_=18    ,  lowercase_=30    ,  lowercase_=400    ,  lowercase_=True    ,  lowercase_=None    ,  lowercase_=True    ,  lowercase_=None    ,  lowercase_=True    ,  lowercase_=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]    ,  lowercase_=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]    ,  lowercase_=True    ,  )	->					Tuple:
									lowerCAmelCase	:   Tuple					     =					parent
									lowerCAmelCase	:   Optional[Any]					     =					batch_size
									lowerCAmelCase	:   str					     =					num_channels
									lowerCAmelCase	:   List[Any]					     =					image_size
									lowerCAmelCase	:   Dict					     =					min_resolution
									lowerCAmelCase	:   Union[str, Any]					     =					max_resolution
									lowerCAmelCase	:   Dict					     =					do_resize
									lowerCAmelCase	:   str					     =					size if size is not None else {"""height""": 18, """width""": 18}
									lowerCAmelCase	:   int					     =					do_center_crop
									lowerCAmelCase	:   Optional[Any]					     =					crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
									lowerCAmelCase	:   Optional[Any]					     =					do_normalize
									lowerCAmelCase	:   List[str]					     =					image_mean
									lowerCAmelCase	:   str					     =					image_std
									lowerCAmelCase	:   str					     =					do_convert_rgb






			def 							_snake_case   (    self )	->					Dict:
									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			(      __snake_case     , unittest.TestCase  ):
			_UpperCamelCase:   Optional[int]	     =		OwlViTImageProcessor if is_vision_available() else None






			def 							_snake_case   (    self )	->					Dict:
									lowerCAmelCase	:   Union[str, Any]					     =					OwlViTImageProcessingTester(self )






			@property
			def 							_snake_case   (    self )	->					Tuple:
									return self.image_processor_tester.prepare_image_processor_dict()






			def 							_snake_case   (    self )	->					Union[str, Any]:
									lowerCAmelCase	:   Tuple					     =					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 )	->					int:
									lowerCAmelCase	:   Optional[Any]					     =					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} )

									lowerCAmelCase	:   int					     =					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 )	->					Optional[Any]:
									lowerCAmelCase	:   Any					     =					self.image_processing_class(**self.image_processor_dict )
									# create random PIL images
									lowerCAmelCase	:   Optional[Any]					     =					prepare_image_inputs(self.image_processor_tester    ,  equal_resolution=__lowerCamelCase )

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

									# Test not batched input
									lowerCAmelCase	:   int					     =					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
									lowerCAmelCase	:   str					     =					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 )	->					Union[str, Any]:
									lowerCAmelCase	:   Tuple					     =					self.image_processing_class(**self.image_processor_dict )
									# create random numpy tensors
									lowerCAmelCase	:   Optional[Any]					     =					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
									lowerCAmelCase	:   List[str]					     =					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
									lowerCAmelCase	:   List[str]					     =					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[Any]:
									lowerCAmelCase	:   str					     =					self.image_processing_class(**self.image_processor_dict )
									# create random PyTorch tensors
									lowerCAmelCase	:   Tuple					     =					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
									lowerCAmelCase	:   Dict					     =					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
									lowerCAmelCase	:   List[str]					     =					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   a_					(_lowerCAmelCase  :   str       )->				int:
    snake_case:						List[str]         =   0
    for letter in data:
        snake_case:						int         =   (hash_ << 4) + ord(_lowerCAmelCase       )
        snake_case:						Optional[int]         =   hash_ & 0xf_0_0_0_0_0_0_0
        if x != 0:
            hash_ ^= x >> 24
        hash_ &= ~x
    return hash_


if __name__ == "__main__":
    import doctest

    doctest.testmod()


