


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







		def __init__(    self					:				List[str]			,      a__					:				List[str]			,      a__					:				Tuple=7			,      a__					:				Dict=3			,      a__					:				Union[str, Any]=18			,      a__					:				str=30			,      a__					:				Any=4_00			,      a__					:				Union[str, Any]=True			,      a__					:				Union[str, Any]=None			,      a__					:				Union[str, Any]=True			,      a__					:				Optional[Any]=False			,      a__					:				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]			,      a__					:				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]			,      a__					:				Any=True			,      )				->  List[Any]:





						'''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        a_       (    self					:				Optional[Any]						)				->  Optional[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        a_       (    self					:				Dict			,      a__					:				int=False			,      a__					:				int=False			,      a__					:				str=False						)				->  str:





						'''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(
														        2_55			,      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_55			,      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(a__			,      0			,      -1						)						) for x in image_inputs]

						if torchify:
										_A         =	[torch.from_numpy(a__						) for x in image_inputs]

						return image_inputs





@require_torch
@require_vision
class snake_case					(     _UpperCamelCase   , unittest.TestCase):
		__UpperCamelCase							=	BlipImageProcessor if is_vision_available() else None







		def        a_       (    self					:				str						)				->  Dict:





						'''simple docstring'''







						_A         =	BlipImageProcessingTester(self						)







		@property
		def        a_       (    self					:				Optional[int]						)				->  Tuple:





						'''simple docstring'''







						return self.image_processor_tester.prepare_image_processor_dict()







		def        a_       (    self					:				Union[str, Any]						)				->  List[str]:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(a__			,      "do_resize"						)						)
						self.assertTrue(hasattr(a__			,      "size"						)						)
						self.assertTrue(hasattr(a__			,      "do_normalize"						)						)
						self.assertTrue(hasattr(a__			,      "image_mean"						)						)
						self.assertTrue(hasattr(a__			,      "image_std"						)						)
						self.assertTrue(hasattr(a__			,      "do_convert_rgb"						)						)







		def        a_       (    self					:				List[Any]						)				->  int:





						'''simple docstring'''







						pass







		def        a_       (    self					:				Optional[int]						)				->  List[Any]:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						_A         =	self.image_processor_tester.prepare_inputs(equal_resolution=a__						)
						for image in image_inputs:
										self.assertIsInstance(a__			,      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(a__			,      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        a_       (    self					:				Optional[Any]						)				->  Union[str, Any]:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						# create random numpy tensors
						_A         =	self.image_processor_tester.prepare_inputs(equal_resolution=a__			,      numpify=a__						)
						for image in image_inputs:
										self.assertIsInstance(a__			,      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(a__			,      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        a_       (    self					:				Tuple						)				->  List[Any]:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						# create random PyTorch tensors
						_A         =	self.image_processor_tester.prepare_inputs(equal_resolution=a__			,      torchify=a__						)
						for image in image_inputs:
										self.assertIsInstance(a__			,      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(a__			,      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 snake_case					(     _UpperCamelCase   , unittest.TestCase):
		__UpperCamelCase							=	BlipImageProcessor if is_vision_available() else None







		def        a_       (    self					:				List[Any]						)				->  Optional[int]:





						'''simple docstring'''







						_A         =	BlipImageProcessingTester(self			,      num_channels=4						)
						_A         =	3







		@property
		def        a_       (    self					:				List[str]						)				->  Optional[Any]:





						'''simple docstring'''







						return self.image_processor_tester.prepare_image_processor_dict()







		def        a_       (    self					:				str						)				->  Any:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(a__			,      "do_resize"						)						)
						self.assertTrue(hasattr(a__			,      "size"						)						)
						self.assertTrue(hasattr(a__			,      "do_normalize"						)						)
						self.assertTrue(hasattr(a__			,      "image_mean"						)						)
						self.assertTrue(hasattr(a__			,      "image_std"						)						)
						self.assertTrue(hasattr(a__			,      "do_convert_rgb"						)						)







		def        a_       (    self					:				Union[str, Any]						)				->  List[str]:





						'''simple docstring'''







						pass







		def        a_       (    self					:				str						)				->  Optional[Any]:





						'''simple docstring'''







						_A         =	self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						_A         =	self.image_processor_tester.prepare_inputs(equal_resolution=a__						)
						for image in image_inputs:
										self.assertIsInstance(a__			,      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(a__			,      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"""


import warnings

from ...utils import logging
from .image_processing_mobilenet_va import MobileNetVaImageProcessor


a_											=			logging.get_logger(__name__)
class snake_case					(     _UpperCamelCase):







		def __init__(    self					:				str			,      *a__					:				Union[str, Any]			,      **a__					:				Optional[Any]						)				->  None:





						'''simple docstring'''







						warnings.warn(
						    "The class MobileNetV2FeatureExtractor is deprecated and will be removed in version 5 of Transformers."
						    " Please use MobileNetV2ImageProcessor instead."			,      a__			,      )
						super().__init__(*a__			,      **a__						)