

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, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import ViTImageProcessor






class 			__magic_name__					(    unittest.TestCase   ):





			def __init__(	self      ,						__snake_case      ,						__snake_case=7      ,						__snake_case=3      ,						__snake_case=18      ,						__snake_case=30      ,						__snake_case=400      ,						__snake_case=True      ,						__snake_case=None      ,						__snake_case=True      ,						__snake_case=[0.5, 0.5, 0.5]      ,						__snake_case=[0.5, 0.5, 0.5]      ,						)     ->				Union[str, Any]:




						'''simple docstring'''
						__a						   =size if size is not None else {'''height''': 18, '''width''': 18}
						__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





			def 	__magic_name__					(	self      )     ->				Dict:




						'''simple docstring'''
						return {
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						    "do_normalize": self.do_normalize,
						    "do_resize": self.do_resize,
						    "size": self.size,
						}






@require_torch
@require_vision
class 			__magic_name__					(    __SCREAMING_SNAKE_CASE						,					unittest.TestCase   ):
			SCREAMING_SNAKE_CASE							     =		ViTImageProcessor if is_vision_available() else None





			def 	__magic_name__					(	self      )     ->				List[Any]:




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





			@property
			def 	__magic_name__					(	self      )     ->				Union[str, Any]:




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





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




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





			def 	__magic_name__					(	self      )     ->				Any:




						'''simple docstring'''
						__a						   =self.image_processing_class.from_dict(self.image_processor_dict      )
						self.assertEqual(image_processor.size      ,						{'height': 18, 'width': 18}      )

						__a						   =self.image_processing_class.from_dict(self.image_processor_dict      ,						size=42      )
						self.assertEqual(image_processor.size      ,						{'height': 42, 'width': 42}      )





			def 	__magic_name__					(	self      )     ->				Optional[Any]:




						'''simple docstring'''
						pass





			def 	__magic_name__					(	self      )     ->				str:




						'''simple docstring'''
						__a						   =self.image_processing_class(**self.image_processor_dict      )
						# create random PIL images
						__a						   =prepare_image_inputs(self.image_processor_tester      ,						equal_resolution=UpperCamelCase__      )
						for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__      ,						Image.Image      )

						# Test not batched input
						__a						   =image_processing(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_processing(UpperCamelCase__      ,						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 	__magic_name__					(	self      )     ->				Dict:




						'''simple docstring'''
						__a						   =self.image_processing_class(**self.image_processor_dict      )
						# create random numpy tensors
						__a						   =prepare_image_inputs(self.image_processor_tester      ,						equal_resolution=UpperCamelCase__      ,						numpify=UpperCamelCase__      )
						for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__      ,						np.ndarray      )

						# Test not batched input
						__a						   =image_processing(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_processing(UpperCamelCase__      ,						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 	__magic_name__					(	self      )     ->				List[str]:




						'''simple docstring'''
						__a						   =self.image_processing_class(**self.image_processor_dict      )
						# create random PyTorch tensors
						__a						   =prepare_image_inputs(self.image_processor_tester      ,						equal_resolution=UpperCamelCase__      ,						torchify=UpperCamelCase__      )
						for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__      ,						torch.Tensor      )

						# Test not batched input
						__a						   =image_processing(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_processing(UpperCamelCase__      ,						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'],
						    )      ,						)









from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_torch_available


_lowerCAmelCase      :    Union[str, Any]						       =    {
    "configuration_ernie_m": ["ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP", "ErnieMConfig"],
}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowerCAmelCase      :    str						       =    ["ErnieMTokenizer"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowerCAmelCase      :    Optional[Any]						       =    [
						    "ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "ErnieMForMultipleChoice",
						    "ErnieMForQuestionAnswering",
						    "ErnieMForSequenceClassification",
						    "ErnieMForTokenClassification",
						    "ErnieMModel",
						    "ErnieMPreTrainedModel",
						    "ErnieMForInformationExtraction",
						]


if TYPE_CHECKING:
						from .configuration_ernie_m import ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieMConfig

						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_ernie_m import ErnieMTokenizer

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_ernie_m import (
												    ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST,
												    ErnieMForInformationExtraction,
												    ErnieMForMultipleChoice,
												    ErnieMForQuestionAnswering,
												    ErnieMForSequenceClassification,
												    ErnieMForTokenClassification,
												    ErnieMModel,
												    ErnieMPreTrainedModel,
												)


else:
						import sys

						_lowerCAmelCase      :    Tuple						       =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






