




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				,     lowerCamelCase				,     lowerCamelCase=7				,     lowerCamelCase=3				,     lowerCamelCase=18				,     lowerCamelCase=30				,     lowerCamelCase=400				,     lowerCamelCase=True				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=False				,     lowerCamelCase=[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]				,     lowerCamelCase=[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]				,     lowerCamelCase=True				,     )      ->   Union[str, Any]:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							size if size is not None else {'''height''': 20, '''width''': 20}
						__magic_name__					:							Any		   =							parent
						__magic_name__					:							List[Any]		   =							batch_size
						__magic_name__					:							int		   =							num_channels
						__magic_name__					:							str		   =							image_size
						__magic_name__					:							Union[str, Any]		   =							min_resolution
						__magic_name__					:							Dict		   =							max_resolution
						__magic_name__					:							Optional[Any]		   =							do_resize
						__magic_name__					:							Optional[Any]		   =							size
						__magic_name__					:							Optional[Any]		   =							do_normalize
						__magic_name__					:							List[Any]		   =							image_mean
						__magic_name__					:							Optional[Any]		   =							image_std
						__magic_name__					:							Optional[Any]		   =							do_pad
						__magic_name__					:							Any		   =							do_convert_rgb






	def  lowercase      (	self						)      ->   Optional[int]:




						"""simple docstring"""






						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  lowercase      (	self				,     lowerCamelCase=False				,     lowerCamelCase=False				,     lowerCamelCase=False						)      ->   Tuple:




						"""simple docstring"""






						assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

						if equal_resolution:
											__magic_name__					:							Optional[int]		   =							[]
											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:
											__magic_name__					:							List[Any]		   =							[]
											for i in range(self.batch_size						):
																__magic_name__   , __magic_name__					:							List[Any]		   =							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
											__magic_name__					:							Optional[int]		   =							[Image.fromarray(np.moveaxis(lowerCamelCase__				,     0				,     -1						)						) for x in image_inputs]

						if torchify:
											__magic_name__					:							Tuple		   =							[torch.from_numpy(lowerCamelCase__						) for x in image_inputs]

						return image_inputs





@require_torch
@require_vision
class 		A__				(   __A		,     unittest.TestCase ):
	lowerCamelCase__		: Optional[int]				    =BlipImageProcessor if is_vision_available() else None






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




						"""simple docstring"""






						__magic_name__					:							Optional[Any]		   =							BlipImageProcessingTester(self						)






	@property
	def  lowercase      (	self						)      ->   Optional[int]:




						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()






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




						"""simple docstring"""






						__magic_name__					:							str		   =							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  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						pass






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




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						__magic_name__					:							Dict		   =							self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase__						)
						for image in image_inputs:
											self.assertIsInstance(lowerCamelCase__				,     Image.Image						)

						# Test not batched input
						__magic_name__					:							Optional[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
						__magic_name__					:							Union[str, Any]		   =							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  lowercase      (	self						)      ->   int:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random numpy tensors
						__magic_name__					:							Dict		   =							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
						__magic_name__					:							List[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
						__magic_name__					:							List[Any]		   =							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  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						__magic_name__					:							List[str]		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random PyTorch tensors
						__magic_name__					:							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
						__magic_name__					:							Dict		   =							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
						__magic_name__					:							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'''],
						    )				,     )





@require_torch
@require_vision
class 		A__				(   __A		,     unittest.TestCase ):
	lowerCamelCase__		: Union[str, Any]				    =BlipImageProcessor if is_vision_available() else None






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




						"""simple docstring"""






						__magic_name__					:							Optional[Any]		   =							BlipImageProcessingTester(self				,     num_channels=4						)
						__magic_name__					:							Any		   =							3






	@property
	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()






	def  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						__magic_name__					:							Optional[int]		   =							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  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						pass






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




						"""simple docstring"""






						__magic_name__					:							Union[str, Any]		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						__magic_name__					:							List[str]		   =							self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase__						)
						for image in image_inputs:
											self.assertIsInstance(lowerCamelCase__				,     Image.Image						)

						# Test not batched input
						__magic_name__					:							Tuple		   =							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
						__magic_name__					:							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'''
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        SCREAMING_SNAKE_CASE(				unittest.TestCase     ):

       def __init__(    self					,		lowerCamelCase__					,		lowerCamelCase__=7					,		lowerCamelCase__=3					,		lowerCamelCase__=18					,		lowerCamelCase__=30					,		lowerCamelCase__=400					,		lowerCamelCase__=True					,		lowerCamelCase__=None					,		lowerCamelCase__=True					,		lowerCamelCase__=False					,		lowerCamelCase__=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]					,		lowerCamelCase__=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]					,		lowerCamelCase__=True					,		)    ->					Union[str, Any]:

           """simple docstring"""



           __lowercase							=						size if size is not None else {"""height""": 20, """width""": 20}
           __lowercase							=						parent
           __lowercase							=						batch_size
           __lowercase							=						num_channels
           __lowercase							=						image_size
           __lowercase							=						min_resolution
           __lowercase							=						max_resolution
           __lowercase							=						do_resize
           __lowercase							=						size
           __lowercase							=						do_normalize
           __lowercase							=						image_mean
           __lowercase							=						image_std
           __lowercase							=						do_pad
           __lowercase							=						do_convert_rgb

       def     snake_case__			(    self     )    ->					Optional[int]:

           """simple docstring"""



           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					,		lowerCamelCase__=False					,		lowerCamelCase__=False					,		lowerCamelCase__=False     )    ->					Tuple:

           """simple docstring"""



           assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

           if equal_resolution:
               __lowercase							=						[]
               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:
               __lowercase							=						[]
               for i in range(self.batch_size     ):
                   __lowercase				,__lowercase							=						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
               __lowercase							=						[Image.fromarray(np.moveaxis(lowerCamelCase__					,		0					,		-1     )     ) for x in image_inputs]

           if torchify:
               __lowercase							=						[torch.from_numpy(lowerCamelCase__     ) for x in image_inputs]

           return image_inputs






@require_torch
@require_vision
class        SCREAMING_SNAKE_CASE(				__A   ,      unittest.TestCase     ):
       snake_case_ :     Optional[int]    =					BlipImageProcessor if is_vision_available() else None

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

           """simple docstring"""



           __lowercase							=						BlipImageProcessingTester(self     )

       @property
       def     snake_case__			(    self     )    ->					Optional[int]:

           """simple docstring"""



           return self.image_processor_tester.prepare_image_processor_dict()

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

           """simple docstring"""



           __lowercase							=						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     )    ->					Any:

           """simple docstring"""



           pass

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

           """simple docstring"""



           __lowercase							=						self.image_processing_class(**self.image_processor_dict     )
           # create random PIL images
           __lowercase							=						self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase__     )
           for image in image_inputs:
               self.assertIsInstance(lowerCamelCase__					,		Image.Image     )

           # Test not batched input
           __lowercase							=						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
           __lowercase							=						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     )    ->					int:

           """simple docstring"""



           __lowercase							=						self.image_processing_class(**self.image_processor_dict     )
           # create random numpy tensors
           __lowercase							=						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
           __lowercase							=						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
           __lowercase							=						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     )    ->					Any:

           """simple docstring"""



           __lowercase							=						self.image_processing_class(**self.image_processor_dict     )
           # create random PyTorch tensors
           __lowercase							=						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
           __lowercase							=						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
           __lowercase							=						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        SCREAMING_SNAKE_CASE(				__A   ,      unittest.TestCase     ):
       snake_case_ :     Union[str, Any]    =					BlipImageProcessor if is_vision_available() else None

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

           """simple docstring"""



           __lowercase							=						BlipImageProcessingTester(self					,		num_channels=4     )
           __lowercase							=						3

       @property
       def     snake_case__			(    self     )    ->					str:

           """simple docstring"""



           return self.image_processor_tester.prepare_image_processor_dict()

       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           __lowercase							=						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     )    ->					Any:

           """simple docstring"""



           pass




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

           """simple docstring"""



           __lowercase							=						self.image_processing_class(**self.image_processor_dict     )
           # create random PIL images
           __lowercase							=						self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase__     )
           for image in image_inputs:
               self.assertIsInstance(lowerCamelCase__					,		Image.Image     )

           # Test not batched input
           __lowercase							=						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
           __lowercase							=						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"""],
               )					,		)




