

"""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      __UpperCamelCase					(  unittest.TestCase		):


		def __init__(self					:						Union[str, Any]	,	__SCREAMING_SNAKE_CASE					:						int	,	__SCREAMING_SNAKE_CASE					:						List[str]=7	,	__SCREAMING_SNAKE_CASE					:						Any=3	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=1_8	,	__SCREAMING_SNAKE_CASE					:						int=3_0	,	__SCREAMING_SNAKE_CASE					:						str=4_0_0	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=True	,	__SCREAMING_SNAKE_CASE					:						List[str]=None	,	__SCREAMING_SNAKE_CASE					:						str=True	,	__SCREAMING_SNAKE_CASE					:						Dict=False	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]=[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]	,	__SCREAMING_SNAKE_CASE					:						List[str]=[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]	,	__SCREAMING_SNAKE_CASE					:						Dict=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    SCREAMING_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    SCREAMING_SNAKE_CASE__  (self					:						Any	,	__SCREAMING_SNAKE_CASE					:						int=False	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]=False	,	__SCREAMING_SNAKE_CASE					:						Any=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					(  _A	,						unittest.TestCase		):
		SCREAMING_SNAKE_CASE														=       BlipImageProcessor if is_vision_available() else None


		def    SCREAMING_SNAKE_CASE__  (self					:						Dict):
							A     =   BlipImageProcessingTester(self)


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Union[str, Any]):
							return self.image_processor_tester.prepare_image_processor_dict()


		def    SCREAMING_SNAKE_CASE__  (self					:						List[str]):
							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    SCREAMING_SNAKE_CASE__  (self					:						Dict):
							pass


		def    SCREAMING_SNAKE_CASE__  (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    SCREAMING_SNAKE_CASE__  (self					:						Optional[int]):
							# 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    SCREAMING_SNAKE_CASE__  (self					:						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					(  _A	,						unittest.TestCase		):
		SCREAMING_SNAKE_CASE														=       BlipImageProcessor if is_vision_available() else None


		def    SCREAMING_SNAKE_CASE__  (self					:						List[Any]):
							A     =   BlipImageProcessingTester(self	,	num_channels=4)
							A     =   3


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[Any]):
							return self.image_processor_tester.prepare_image_processor_dict()


		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[int]):
							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    SCREAMING_SNAKE_CASE__  (self					:						Optional[int]):
							pass


		def    SCREAMING_SNAKE_CASE__  (self					:						List[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"],
							    )	,	)






'''simple docstring'''

from ..utils import DummyObject, requires_backends
class 	SCREAMING_SNAKE_CASE      (    metaclass=__lowercase):







		"""simple docstring"""
		lowercase :   List[Any]							=				['tensorflow_text']






		def __init__( self		,    *__A		,    **__A					)			->  List[Any]:
								requires_backends(self		,    ['tensorflow_text']					)





