


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		:						List[Any]						,   _SCREAMING_SNAKE_CASE		:						List[Any]						,   _SCREAMING_SNAKE_CASE		:						Optional[Any]=7						,   _SCREAMING_SNAKE_CASE		:						Any=3						,   _SCREAMING_SNAKE_CASE		:						Dict=18						,   _SCREAMING_SNAKE_CASE		:						List[str]=30						,   _SCREAMING_SNAKE_CASE		:						Tuple=400						,   _SCREAMING_SNAKE_CASE		:						str=True						,   _SCREAMING_SNAKE_CASE		:						Optional[int]=None						,   _SCREAMING_SNAKE_CASE		:						Optional[int]=True						,   _SCREAMING_SNAKE_CASE		:						Tuple=False						,   _SCREAMING_SNAKE_CASE		:						int=[0.4814_5466, 0.457_8275, 0.4082_1073]						,   _SCREAMING_SNAKE_CASE		:						Dict=[0.2686_2954, 0.2613_0258, 0.2757_7711]						,   _SCREAMING_SNAKE_CASE		:						Any=True						,   )->			Dict:
			lowerCAmelCase__  :     List[Any]       	=   size if size is not None else {'''height''': 20, '''width''': 20}
			lowerCAmelCase__  :     Optional[int]       	=   parent
			lowerCAmelCase__  :     List[str]       	=   batch_size
			lowerCAmelCase__  :     List[Any]       	=   num_channels
			lowerCAmelCase__  :     Dict       	=   image_size
			lowerCAmelCase__  :     Dict       	=   min_resolution
			lowerCAmelCase__  :     Tuple       	=   max_resolution
			lowerCAmelCase__  :     List[str]       	=   do_resize
			lowerCAmelCase__  :     Union[str, Any]       	=   size
			lowerCAmelCase__  :     Optional[int]       	=   do_normalize
			lowerCAmelCase__  :     Any       	=   image_mean
			lowerCAmelCase__  :     Any       	=   image_std
			lowerCAmelCase__  :     List[str]       	=   do_pad
			lowerCAmelCase__  :     Tuple       	=   do_convert_rgb




	def 				UpperCAmelCase__(   self		:						Any						)->			List[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		:						Union[str, Any]						,   _SCREAMING_SNAKE_CASE		:						int=False						,   _SCREAMING_SNAKE_CASE		:						Dict=False						,   _SCREAMING_SNAKE_CASE		:						Any=False						)->			str:
			assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

			if torchify:
					lowerCAmelCase__  :     Any       	=   [torch.from_numpy(_SCREAMING_SNAKE_CASE						) for x in image_inputs]

			return image_inputs





@require_torch
@require_vision
class    _a				(							_lowercase	,		unittest.TestCase):
	_a    :    int        =				BlipImageProcessor if is_vision_available() else None




	def 				UpperCAmelCase__(   self		:						List[str]						)->			Dict:
			lowerCAmelCase__  :     Dict       	=   BlipImageProcessingTester(self						)




	@property
	def 				UpperCAmelCase__(   self		:						List[str]						)->			Any:
			return self.image_processor_tester.prepare_image_processor_dict()




	def 				UpperCAmelCase__(   self		:						int						)->			Union[str, Any]:
			lowerCAmelCase__  :     List[str]       	=   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		:						Any						)->			Any:
			pass




	def 				UpperCAmelCase__(   self		:						int						)->			List[str]:
			# Initialize image_processor
			lowerCAmelCase__  :     Dict       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PIL images
			lowerCAmelCase__  :     str       	=   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
			lowerCAmelCase__  :     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(_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		:						Tuple						)->			List[str]:
			# Initialize image_processor
			lowerCAmelCase__  :     Union[str, Any]       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random numpy tensors
			lowerCAmelCase__  :     Union[str, Any]       	=   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
			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__  :     Optional[int]       	=   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		:						Dict						)->			Tuple:
			# Initialize image_processor
			lowerCAmelCase__  :     Optional[int]       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PyTorch tensors
			lowerCAmelCase__  :     List[str]       	=   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
			lowerCAmelCase__  :     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(_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    _a				(							_lowercase	,		unittest.TestCase):
	_a    :    Dict        =				BlipImageProcessor if is_vision_available() else None




	def 				UpperCAmelCase__(   self		:						int						)->			Union[str, Any]:
			lowerCAmelCase__  :     Optional[Any]       	=   BlipImageProcessingTester(self						,   num_channels=4						)
			lowerCAmelCase__  :     Optional[int]       	=   3




	@property
	def 				UpperCAmelCase__(   self		:						Optional[int]						)->			List[str]:
			return self.image_processor_tester.prepare_image_processor_dict()




	def 				UpperCAmelCase__(   self		:						Optional[Any]						)->			List[Any]:
			lowerCAmelCase__  :     Tuple       	=   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		:						str						)->			List[str]:
			pass




	def 				UpperCAmelCase__(   self		:						List[str]						)->			Any:
			# Initialize image_processor
			lowerCAmelCase__  :     Any       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PIL images
			lowerCAmelCase__  :     Dict       	=   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
			lowerCAmelCase__  :     Optional[int]       	=   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__  :     Union[str, Any]       	=   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'''],
			    )						,   )








import warnings

from ...utils import logging
from .image_processing_maskformer import MaskFormerImageProcessor


lowerCamelCase		=						logging.get_logger(__name__)





class    _a				(							_lowercase):




	def __init__(   self		:						Any						,   *_SCREAMING_SNAKE_CASE		:						int						,   **_SCREAMING_SNAKE_CASE		:						Dict						)->			None:
			warnings.warn(
			    '''The class MaskFormerFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
			    ''' Please use MaskFormerImageProcessor instead.'''						,   _SCREAMING_SNAKE_CASE						,   )
			super().__init__(*_SCREAMING_SNAKE_CASE						,   **_SCREAMING_SNAKE_CASE						)




