code: 
  
  
  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 					_UpperCamelCase (      unittest.TestCase	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def __init__(		self  :				Tuple		,				SCREAMING_SNAKE_CASE_  :				Dict		,				SCREAMING_SNAKE_CASE_  :				Tuple=7		,				SCREAMING_SNAKE_CASE_  :				Optional[int]=3		,				SCREAMING_SNAKE_CASE_  :				Tuple=1_8		,				SCREAMING_SNAKE_CASE_  :				Tuple=3_0		,				SCREAMING_SNAKE_CASE_  :				Tuple=4_0_0		,				SCREAMING_SNAKE_CASE_  :				Optional[int]=True		,				SCREAMING_SNAKE_CASE_  :				Optional[Any]=None		,				SCREAMING_SNAKE_CASE_  :				List[Any]=True		,				SCREAMING_SNAKE_CASE_  :				Optional[Any]=False		,				SCREAMING_SNAKE_CASE_  :				Tuple=[0.48145466, 0.4578275, 0.40821073]		,				SCREAMING_SNAKE_CASE_  :				Tuple=[0.26862954, 0.26130258, 0.27577711]		,				SCREAMING_SNAKE_CASE_  :				Optional[Any]=True		,				):
  													_a     =			size if size is not None else {'height': 2_0, 'width': 2_0}
  													_a     =			parent
  													_a     =			batch_size
  													_a     =			num_channels
  													_a     =			image_size
  													_a     =			min_resolution
  													_a     =			max_resolution
  													_a     =			do_resize
  													_a     =			size
  													_a     =			do_normalize
  													_a     =			image_mean
  													_a     =			image_std
  													_a     =			do_pad
  													_a     =			do_convert_rgb
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Union[str, 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 		_UpperCAmelCase	(		self  :				str		,				SCREAMING_SNAKE_CASE_  :				Any=False		,				SCREAMING_SNAKE_CASE_  :				Tuple=False		,				SCREAMING_SNAKE_CASE_  :				int=False		):
  													assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
  													if equal_resolution:
  																			_a     =			[]
  																			for i in range(self.batch_size		):
  																									image_inputs.append(
  																									    np.random.randint(
  																									        2_5_5		,				size=(self.num_channels, self.max_resolution, self.max_resolution)		,				dtype=np.uinta		)		)
  													else:
  																			_a     =			[]
  																			for i in range(self.batch_size		):
  																									_a ,	_a     =			np.random.choice(np.arange(self.min_resolution		,				self.max_resolution		)		,				2		)
  																									image_inputs.append(np.random.randint(2_5_5		,				size=(self.num_channels, width, height)		,				dtype=np.uinta		)		)
  
  													if not numpify and not torchify:
  																			# PIL expects the channel dimension as last dimension
  																			_a     =			[Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE_		,				0		,				-1		)		) for x in image_inputs]
  
  													if torchify:
  																			_a     =			[torch.from_numpy(SCREAMING_SNAKE_CASE_		) for x in image_inputs]
  
  													return image_inputs
  
  
  
  
  @require_torch
  @require_vision
  class 					_UpperCamelCase (      lowerCamelCase__			,							unittest.TestCase	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  							_A  				=  BlipImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[Any]		):
  													_a     =			BlipImageProcessingTester(self		)
  
  
  
  
  
  
  
  							@property
  							def 		_UpperCAmelCase	(		self  :				int		):
  													return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Tuple		):
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_resize'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'size'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_normalize'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'image_mean'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'image_std'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_convert_rgb'		)		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Tuple		):
  													pass
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Optional[Any]		):
  													# Initialize image_processor
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													# create random PIL images
  													_a     =			self.image_processor_tester.prepare_inputs(equal_resolution=SCREAMING_SNAKE_CASE_		)
  													for image in image_inputs:
  																			self.assertIsInstance(SCREAMING_SNAKE_CASE_		,				Image.Image		)
  
  													# Test not batched input
  													_a     =			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
  													_a     =			image_processor(SCREAMING_SNAKE_CASE_		,				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 		_UpperCAmelCase	(		self  :				List[Any]		):
  													# Initialize image_processor
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													# create random numpy tensors
  													_a     =			self.image_processor_tester.prepare_inputs(equal_resolution=SCREAMING_SNAKE_CASE_		,				numpify=SCREAMING_SNAKE_CASE_		)
  													for image in image_inputs:
  																			self.assertIsInstance(SCREAMING_SNAKE_CASE_		,				np.ndarray		)
  
  													# Test not batched input
  													_a     =			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
  													_a     =			image_processor(SCREAMING_SNAKE_CASE_		,				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 		_UpperCAmelCase	(		self  :				List[Any]		):
  													# Initialize image_processor
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													# create random PyTorch tensors
  													_a     =			self.image_processor_tester.prepare_inputs(equal_resolution=SCREAMING_SNAKE_CASE_		,				torchify=SCREAMING_SNAKE_CASE_		)
  													for image in image_inputs:
  																			self.assertIsInstance(SCREAMING_SNAKE_CASE_		,				torch.Tensor		)
  
  													# Test not batched input
  													_a     =			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
  													_a     =			image_processor(SCREAMING_SNAKE_CASE_		,				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 					_UpperCamelCase (      lowerCamelCase__			,							unittest.TestCase	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  							_A  				=  BlipImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				str		):
  													_a     =			BlipImageProcessingTester(self		,				num_channels=4		)
  													_a     =			3
  
  
  
  
  
  
  
  							@property
  							def 		_UpperCAmelCase	(		self  :				Optional[Any]		):
  													return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Optional[Any]		):
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_resize'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'size'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_normalize'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'image_mean'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'image_std'		)		)
  													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_		,				'do_convert_rgb'		)		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Optional[int]		):
  													pass
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				str		):
  													# Initialize image_processor
  													_a     =			self.image_processing_class(**self.image_processor_dict		)
  													# create random PIL images
  													_a     =			self.image_processor_tester.prepare_inputs(equal_resolution=SCREAMING_SNAKE_CASE_		)
  													for image in image_inputs:
  																			self.assertIsInstance(SCREAMING_SNAKE_CASE_		,				Image.Image		)
  
  													# Test not batched input
  													_a     =			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
  													_a     =			image_processor(SCREAMING_SNAKE_CASE_		,				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'],
  													    )		,				)
  
  
  
style_context: 
  
  
  lowercase_								=    [0.485, 0.456, 0.406]
  lowercase_								=    [0.229, 0.224, 0.225]
  lowercase_								=    [0.5, 0.5, 0.5]
  lowercase_								=    [0.5, 0.5, 0.5]
  lowercase_								=    [0.48145466, 0.4578275, 0.40821073]
  lowercase_								=    [0.26862954, 0.26130258, 0.27577711]
  
  
  