



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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import BlipImageProcessor






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_=False    ,  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    ,  )	->					Optional[Any]:
									lowerCAmelCase	:   List[str]					     =					size if size is not None else {"""height""": 20, """width""": 20}
									lowerCAmelCase	:   Any					     =					parent
									lowerCAmelCase	:   str					     =					batch_size
									lowerCAmelCase	:   List[Any]					     =					num_channels
									lowerCAmelCase	:   Dict					     =					image_size
									lowerCAmelCase	:   List[Any]					     =					min_resolution
									lowerCAmelCase	:   List[Any]					     =					max_resolution
									lowerCAmelCase	:   int					     =					do_resize
									lowerCAmelCase	:   List[str]					     =					size
									lowerCAmelCase	:   List[Any]					     =					do_normalize
									lowerCAmelCase	:   List[str]					     =					image_mean
									lowerCAmelCase	:   str					     =					image_std
									lowerCAmelCase	:   List[str]					     =					do_pad
									lowerCAmelCase	:   Tuple					     =					do_convert_rgb






			def 							_snake_case   (    self )	->					Any:
									return {
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "do_normalize": self.do_normalize,
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_convert_rgb": self.do_convert_rgb,
									    "do_pad": self.do_pad,
									}






			def 							_snake_case   (    self    ,  lowercase_=False    ,  lowercase_=False    ,  lowercase_=False )	->					List[str]:
									assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

									if equal_resolution:
															lowerCAmelCase	:   Optional[Any]					     =					[]
															for i in range(self.batch_size ):
																					image_inputs.append(
																					    np.random.randint(
																					        255    ,  size=(self.num_channels, self.max_resolution, self.max_resolution)    ,  dtype=np.uinta ) )
									else:
															lowerCAmelCase	:   Dict					     =					[]
															for i in range(self.batch_size ):
																					lowerCAmelCase     ,	lowerCAmelCase	:   Tuple					     =					np.random.choice(np.arange(self.min_resolution    ,  self.max_resolution )    ,  2 )
																					image_inputs.append(np.random.randint(255    ,  size=(self.num_channels, width, height)    ,  dtype=np.uinta ) )

									if not numpify and not torchify:
															# PIL expects the channel dimension as last dimension
															lowerCAmelCase	:   Optional[int]					     =					[Image.fromarray(np.moveaxis(__lowerCamelCase    ,  0    ,  -1 ) ) for x in image_inputs]

									if torchify:
															lowerCAmelCase	:   str					     =					[torch.from_numpy(__lowerCamelCase ) for x in image_inputs]

									return image_inputs






@require_torch
@require_vision
class 	_a			(      _lowerCamelCase     , unittest.TestCase  ):
			_UpperCamelCase:   Union[str, Any]	     =		BlipImageProcessor if is_vision_available() else None






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






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






			def 							_snake_case   (    self )	->					str:
									lowerCAmelCase	:   Any					     =					self.image_processing_class(**self.image_processor_dict )
									self.assertTrue(hasattr(__lowerCamelCase    ,  """do_resize""" ) )
									self.assertTrue(hasattr(__lowerCamelCase    ,  """size""" ) )
									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 )	->					str:
									pass






			def 							_snake_case   (    self )	->					Any:
									lowerCAmelCase	:   Any					     =					self.image_processing_class(**self.image_processor_dict )
									# create random PIL images
									lowerCAmelCase	:   Dict					     =					self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase )
									for image in image_inputs:
															self.assertIsInstance(__lowerCamelCase    ,  Image.Image )

									# Test not batched input
									lowerCAmelCase	:   Union[str, Any]					     =					image_processor(image_inputs[0]    ,  return_tensors="""pt""" ).pixel_values
									self.assertEqual(
									    encoded_images.shape    ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )

									# Test batched
									lowerCAmelCase	:   Optional[int]					     =					image_processor(__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.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )






			def 							_snake_case   (    self )	->					Optional[int]:
									lowerCAmelCase	:   Optional[Any]					     =					self.image_processing_class(**self.image_processor_dict )
									# create random numpy tensors
									lowerCAmelCase	:   Optional[Any]					     =					self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase    ,  numpify=__lowerCamelCase )
									for image in image_inputs:
															self.assertIsInstance(__lowerCamelCase    ,  np.ndarray )

									# Test not batched input
									lowerCAmelCase	:   int					     =					image_processor(image_inputs[0]    ,  return_tensors="""pt""" ).pixel_values
									self.assertEqual(
									    encoded_images.shape    ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )

									# Test batched
									lowerCAmelCase	:   Tuple					     =					image_processor(__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.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )






			def 							_snake_case   (    self )	->					List[Any]:
									lowerCAmelCase	:   Any					     =					self.image_processing_class(**self.image_processor_dict )
									# create random PyTorch tensors
									lowerCAmelCase	:   List[str]					     =					self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase    ,  torchify=__lowerCamelCase )
									for image in image_inputs:
															self.assertIsInstance(__lowerCamelCase    ,  torch.Tensor )

									# Test not batched input
									lowerCAmelCase	:   Union[str, Any]					     =					image_processor(image_inputs[0]    ,  return_tensors="""pt""" ).pixel_values
									self.assertEqual(
									    encoded_images.shape    ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )

									# Test batched
									lowerCAmelCase	:   List[str]					     =					image_processor(__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.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )






@require_torch
@require_vision
class 	_a			(      _lowerCamelCase     , unittest.TestCase  ):
			_UpperCamelCase:   Dict	     =		BlipImageProcessor if is_vision_available() else None






			def 							_snake_case   (    self )	->					Dict:
									lowerCAmelCase	:   List[str]					     =					BlipImageProcessingTester(self    ,  num_channels=4 )
									lowerCAmelCase	:   Tuple					     =					3






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






			def 							_snake_case   (    self )	->					List[Any]:
									lowerCAmelCase	:   Union[str, Any]					     =					self.image_processing_class(**self.image_processor_dict )
									self.assertTrue(hasattr(__lowerCamelCase    ,  """do_resize""" ) )
									self.assertTrue(hasattr(__lowerCamelCase    ,  """size""" ) )
									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 )	->					str:
									pass






			def 							_snake_case   (    self )	->					Tuple:
									lowerCAmelCase	:   Dict					     =					self.image_processing_class(**self.image_processor_dict )
									# create random PIL images
									lowerCAmelCase	:   List[Any]					     =					self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase )
									for image in image_inputs:
															self.assertIsInstance(__lowerCamelCase    ,  Image.Image )

									# Test not batched input
									lowerCAmelCase	:   Optional[Any]					     =					image_processor(image_inputs[0]    ,  return_tensors="""pt""" ).pixel_values
									self.assertEqual(
									    encoded_images.shape    ,  (
									        1,
									        self.expected_encoded_image_num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )

									# Test batched
									lowerCAmelCase	:   Dict					     =					image_processor(__lowerCamelCase    ,  return_tensors="""pt""" ).pixel_values
									self.assertEqual(
									    encoded_images.shape    ,  (
									        self.image_processor_tester.batch_size,
									        self.expected_encoded_image_num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )    ,  )









'''simple docstring'''





from ..utils import DummyObject, requires_backends
class 					lowercase							(				metaclass=_lowerCamelCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				["torch", "transformers", "invisible_watermark"]

    def __init__(       self  :  Optional[Any]					,  *__lowerCamelCase  :  List[Any]					,  **__lowerCamelCase  :  Union[str, Any]  )				->				Dict:

     '''simple docstring'''




     requires_backends(self					,  ["torch", "transformers", "invisible_watermark"]  )

    @classmethod
    def  a__					(       cls  :  Any					,  *__lowerCamelCase  :  List[Any]					,  **__lowerCamelCase  :  Tuple  )				->				List[str]:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )




    @classmethod
    def  a__					(       cls  :  Union[str, Any]					,  *__lowerCamelCase  :  Tuple					,  **__lowerCamelCase  :  Tuple  )				->				List[Any]:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )
class 					lowercase							(				metaclass=_lowerCamelCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				["torch", "transformers", "invisible_watermark"]

    def __init__(       self  :  Optional[Any]					,  *__lowerCamelCase  :  str					,  **__lowerCamelCase  :  Optional[Any]  )				->				str:

     '''simple docstring'''




     requires_backends(self					,  ["torch", "transformers", "invisible_watermark"]  )

    @classmethod
    def  a__					(       cls  :  Union[str, Any]					,  *__lowerCamelCase  :  List[str]					,  **__lowerCamelCase  :  Dict  )				->				Any:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )




    @classmethod
    def  a__					(       cls  :  List[Any]					,  *__lowerCamelCase  :  Union[str, Any]					,  **__lowerCamelCase  :  Any  )				->				Any:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )

