



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						:						Any ,			__lowercase						:						Optional[int] ,			__lowercase						:						str=7 ,			__lowercase						:						str=3 ,			__lowercase						:						Union[str, Any]=18 ,			__lowercase						:						Optional[Any]=30 ,			__lowercase						:						Dict=400 ,			__lowercase						:						List[str]=True ,			__lowercase						:						Optional[Any]=None ,			__lowercase						:						Tuple=True ,			__lowercase						:						Optional[Any]=False ,			__lowercase						:						List[Any]=[0.48145466, 0.4578275, 0.40821073] ,			__lowercase						:						Dict=[0.26862954, 0.26130258, 0.27577711] ,			__lowercase						:						Union[str, Any]=True ,			):

											'''simple docstring'''
											__a					       =						size if size is not None else {"""height""": 20, """width""": 20}
											__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						:						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   UpperCamelCase_   (				self						:						Optional[int] ,			__lowercase						:						Union[str, Any]=False ,			__lowercase						:						Union[str, Any]=False ,			__lowercase						:						Optional[Any]=False		):

											'''simple docstring'''
											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(
																			        255 ,			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(255 ,			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(__lowercase ,			0 ,			-1		)		) for x in image_inputs]

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

											return image_inputs






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





							def   UpperCamelCase_   (				self						:						int		):

											'''simple docstring'''
											__a					       =						BlipImageProcessingTester(self		)





							@property
							def   UpperCamelCase_   (				self						:						str		):

											'''simple docstring'''
											return self.image_processor_tester.prepare_image_processor_dict()





							def   UpperCamelCase_   (				self						:						int		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											self.assertTrue(hasattr(__lowercase ,			"""do_resize"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""size"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""do_normalize"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""image_mean"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""image_std"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""do_convert_rgb"""		)		)





							def   UpperCamelCase_   (				self						:						Tuple		):

											'''simple docstring'''
											pass





							def   UpperCamelCase_   (				self						:						Optional[int]		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											# create random PIL images
											__a					       =						self.image_processor_tester.prepare_inputs(equal_resolution=__lowercase		)
											for image in image_inputs:
															self.assertIsInstance(__lowercase ,			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(__lowercase ,			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						:						Optional[int]		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											# create random numpy tensors
											__a					       =						self.image_processor_tester.prepare_inputs(equal_resolution=__lowercase ,			numpify=__lowercase		)
											for image in image_inputs:
															self.assertIsInstance(__lowercase ,			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(__lowercase ,			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						:						Optional[int]		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											# create random PyTorch tensors
											__a					       =						self.image_processor_tester.prepare_inputs(equal_resolution=__lowercase ,			torchify=__lowercase		)
											for image in image_inputs:
															self.assertIsInstance(__lowercase ,			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(__lowercase ,			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     (							lowerCamelCase__     , unittest.TestCase   ):
							__lowerCamelCase		:		Optional[Any]      =BlipImageProcessor if is_vision_available() else None





							def   UpperCamelCase_   (				self						:						Optional[int]		):

											'''simple docstring'''
											__a					       =						BlipImageProcessingTester(self ,			num_channels=4		)
											__a					       =						3





							@property
							def   UpperCamelCase_   (				self						:						List[Any]		):

											'''simple docstring'''
											return self.image_processor_tester.prepare_image_processor_dict()





							def   UpperCamelCase_   (				self						:						Dict		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											self.assertTrue(hasattr(__lowercase ,			"""do_resize"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""size"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""do_normalize"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""image_mean"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""image_std"""		)		)
											self.assertTrue(hasattr(__lowercase ,			"""do_convert_rgb"""		)		)





							def   UpperCamelCase_   (				self						:						List[str]		):

											'''simple docstring'''
											pass







							def   UpperCamelCase_   (				self						:						str		):

											'''simple docstring'''
											__a					       =						self.image_processing_class(**self.image_processor_dict		)
											# create random PIL images
											__a					       =						self.image_processor_tester.prepare_inputs(equal_resolution=__lowercase		)
											for image in image_inputs:
															self.assertIsInstance(__lowercase ,			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(__lowercase ,			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 TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowerCamelCase__     =	{
    """configuration_oneformer""": ["""ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """OneFormerConfig"""],
    """processing_oneformer""": ["""OneFormerProcessor"""],
}

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__     =	["""OneFormerImageProcessor"""]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__     =	[
						    """ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """OneFormerForUniversalSegmentation""",
						    """OneFormerModel""",
						    """OneFormerPreTrainedModel""",
						]

if TYPE_CHECKING:
						from .configuration_oneformer import ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, OneFormerConfig
						from .processing_oneformer import OneFormerProcessor

						try:
												if not is_vision_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .image_processing_oneformer import OneFormerImageProcessor
						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_oneformer import (
												    ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    OneFormerForUniversalSegmentation,
												    OneFormerModel,
												    OneFormerPreTrainedModel,
												)


else:
						import sys

						lowerCamelCase__     =	_LazyModule(__name__, globals()["""__file__"""], _import_structure)
