






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					):





				"""simple docstring"""







				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_145_466, 0.4_578_275, 0.40_821_073]				,    lowerCamelCase__=[0.26_862_954, 0.26_130_258, 0.27_577_711]				,    lowerCamelCase__=True				,    ):




									"""simple docstring"""

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


				def  __lowercase				(					self       ):




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




									"""simple docstring"""

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

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

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

									return image_inputs




@require_torch
@require_vision
class 							__A	(     a ,	unittest.TestCase					):





				"""simple docstring"""







				UpperCamelCase__					: Optional[Any]     					=BlipImageProcessor if is_vision_available() else None


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   int									=BlipImageProcessingTester(self       )


				@property
				def  __lowercase				(					self       ):




									"""simple docstring"""

									return self.image_processor_tester.prepare_image_processor_dict()


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   List[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       ):




									"""simple docstring"""

									pass


				def  __lowercase				(					self       ):




									"""simple docstring"""

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

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




									"""simple docstring"""

									__UpperCamelCase :   List[Any]									=self.image_processing_class(**self.image_processor_dict       )
									# create random numpy tensors
									__UpperCamelCase :   Optional[int]									=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
									__UpperCamelCase :   Tuple									=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
									__UpperCamelCase :   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       ):




									"""simple docstring"""

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




@require_torch
@require_vision
class 							__A	(     a ,	unittest.TestCase					):





				"""simple docstring"""







				UpperCamelCase__					: Dict     					=BlipImageProcessor if is_vision_available() else None


				def  __lowercase				(					self       ):




									"""simple docstring"""

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


				@property
				def  __lowercase				(					self       ):




									"""simple docstring"""

									return self.image_processor_tester.prepare_image_processor_dict()


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   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       ):




									"""simple docstring"""

									pass







				def  __lowercase				(					self       ):




									"""simple docstring"""

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

									# Test not batched input
									__UpperCamelCase :   Dict									=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
									__UpperCamelCase :   Tuple									=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'],
									    )				,    )









from typing import Callable






def 				A	(			a_   )	->		List[str]:

					def wrapper(a_   ):
										__UpperCamelCase :   Dict									=function_with_docstring.__doc__
										return target_function

					return wrapper

