




'''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 	lowerCamelCase_				(			unittest.TestCase				):




					'''simple docstring'''






					def __init__(       self,    __UpperCamelCase,    __UpperCamelCase=7,    __UpperCamelCase=3,    __UpperCamelCase=18,    __UpperCamelCase=30,    __UpperCamelCase=400,    __UpperCamelCase=True,    __UpperCamelCase=None,    __UpperCamelCase=True,    __UpperCamelCase=False,    __UpperCamelCase=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73],    __UpperCamelCase=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11],    __UpperCamelCase=True,    ):
							_snake_case      			=			size if size is not None else {'''height''': 20, '''width''': 20}
							_snake_case      			=			parent
							_snake_case      			=			batch_size
							_snake_case      			=			num_channels
							_snake_case      			=			image_size
							_snake_case      			=			min_resolution
							_snake_case      			=			max_resolution
							_snake_case      			=			do_resize
							_snake_case      			=			size
							_snake_case      			=			do_normalize
							_snake_case      			=			image_mean
							_snake_case      			=			image_std
							_snake_case      			=			do_pad
							_snake_case      			=			do_convert_rgb






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							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,    __UpperCamelCase=False,    __UpperCamelCase=False,    __UpperCamelCase=False					):
							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

							return image_inputs





@require_torch
@require_vision
class 	lowerCamelCase_				(			_lowercase,			unittest.TestCase				):




					'''simple docstring'''






					lowercase__       =					BlipImageProcessor if is_vision_available() else None






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							_snake_case      			=			BlipImageProcessingTester(self					)






					@property
					def 							__SCREAMING_SNAKE_CASE      (       self					):
							return self.image_processor_tester.prepare_image_processor_dict()






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							_snake_case      			=			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					):
							pass






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							# Initialize image_processor
							_snake_case      			=			self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							_snake_case      			=			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
							_snake_case      			=			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
							_snake_case      			=			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					):
							# Initialize image_processor
							_snake_case      			=			self.image_processing_class(**self.image_processor_dict					)
							# create random numpy tensors
							_snake_case      			=			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
							_snake_case      			=			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
							_snake_case      			=			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					):
							# Initialize image_processor
							_snake_case      			=			self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							_snake_case      			=			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
							_snake_case      			=			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
							_snake_case      			=			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 	lowerCamelCase_				(			_lowercase,			unittest.TestCase				):




					'''simple docstring'''






					lowercase__       =					BlipImageProcessor if is_vision_available() else None






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							_snake_case      			=			BlipImageProcessingTester(self,    num_channels=4					)
							_snake_case      			=			3






					@property
					def 							__SCREAMING_SNAKE_CASE      (       self					):
							return self.image_processor_tester.prepare_image_processor_dict()






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							_snake_case      			=			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					):
							pass






					def 							__SCREAMING_SNAKE_CASE      (       self					):
							# Initialize image_processor
							_snake_case      			=			self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							_snake_case      			=			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
							_snake_case      			=			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
							_snake_case      			=			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"],
							    ),    )









from typing import TYPE_CHECKING

from ...utils import _LazyModule


lowerCamelCase		=						{'''tokenization_phobert''': ['''PhobertTokenizer''']}


if TYPE_CHECKING:
		from .tokenization_phobert import PhobertTokenizer

else:
		import sys

		lowerCamelCase		=						_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




