





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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import ConvNextImageProcessor



class 				__UpperCAmelCase	(							unittest.TestCase    ):







		'''simple docstring'''







		def __init__(self    :   Optional[Any]   ,   _lowerCAmelCase    :   List[Any]   ,   _lowerCAmelCase    :   Optional[int]=7   ,   _lowerCAmelCase    :   Union[str, Any]=3   ,   _lowerCAmelCase    :   Optional[Any]=18   ,   _lowerCAmelCase    :   Optional[int]=30   ,   _lowerCAmelCase    :   Tuple=400   ,   _lowerCAmelCase    :   Optional[int]=True   ,   _lowerCAmelCase    :   Tuple=None   ,   _lowerCAmelCase    :   str=0.875   ,   _lowerCAmelCase    :   Optional[Any]=True   ,   _lowerCAmelCase    :   int=[0.5, 0.5, 0.5]   ,   _lowerCAmelCase    :   Dict=[0.5, 0.5, 0.5]   ,   ):
			A					=   size if size is not None else {"""shortest_edge""": 20}
			A					=   parent
			A					=   batch_size
			A					=   num_channels
			A					=   image_size
			A					=   min_resolution
			A					=   max_resolution
			A					=   do_resize
			A					=   size
			A					=   crop_pct
			A					=   do_normalize
			A					=   image_mean
			A					=   image_std







		def 							A  (self    :   List[str]   ):
			return {
			    "image_mean": self.image_mean,
			    "image_std": self.image_std,
			    "do_normalize": self.do_normalize,
			    "do_resize": self.do_resize,
			    "size": self.size,
			    "crop_pct": self.crop_pct,
			}






@require_torch
@require_vision
class 				__UpperCAmelCase	(							A__		,       unittest.TestCase    ):







		'''simple docstring'''







		__lowerCAmelCase								=     ConvNextImageProcessor if is_vision_available() else None







		def 							A  (self    :   Union[str, Any]   ):
			A					=   ConvNextImageProcessingTester(self   )







		@property
		def 							A  (self    :   Tuple   ):
			return self.image_processor_tester.prepare_image_processor_dict()







		def 							A  (self    :   Optional[int]   ):
			A					=   self.image_processing_class(**self.image_processor_dict   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """do_resize"""   )   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """size"""   )   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """crop_pct"""   )   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """do_normalize"""   )   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """image_mean"""   )   )
			self.assertTrue(hasattr(_lowerCAmelCase   ,   """image_std"""   )   )







		def 							A  (self    :   Optional[Any]   ):
			A					=   self.image_processing_class.from_dict(self.image_processor_dict   )
			self.assertEqual(image_processor.size   ,   {"""shortest_edge""": 20}   )

			A					=   self.image_processing_class.from_dict(self.image_processor_dict   ,   size=42   )
			self.assertEqual(image_processor.size   ,   {"""shortest_edge""": 42}   )







		def 							A  (self    :   List[str]   ):
			pass







		def 							A  (self    :   Tuple   ):
			# Initialize image_processing
			A					=   self.image_processing_class(**self.image_processor_dict   )
			# create random PIL images
			A					=   prepare_image_inputs(self.image_processor_tester   ,   equal_resolution=_lowerCAmelCase   )
			for image in image_inputs:
				self.assertIsInstance(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )

			# Test batched
			A					=   image_processing(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )







		def 							A  (self    :   Optional[int]   ):
			# Initialize image_processing
			A					=   self.image_processing_class(**self.image_processor_dict   )
			# create random numpy tensors
			A					=   prepare_image_inputs(self.image_processor_tester   ,   equal_resolution=_lowerCAmelCase   ,   numpify=_lowerCAmelCase   )
			for image in image_inputs:
				self.assertIsInstance(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )

			# Test batched
			A					=   image_processing(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )







		def 							A  (self    :   Tuple   ):
			# Initialize image_processing
			A					=   self.image_processing_class(**self.image_processor_dict   )
			# create random PyTorch tensors
			A					=   prepare_image_inputs(self.image_processor_tester   ,   equal_resolution=_lowerCAmelCase   ,   torchify=_lowerCAmelCase   )
			for image in image_inputs:
				self.assertIsInstance(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )

			# Test batched
			A					=   image_processing(_lowerCAmelCase   ,   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["""shortest_edge"""],
			        self.image_processor_tester.size["""shortest_edge"""],
			    )   ,   )








'''simple docstring'''


from typing import TYPE_CHECKING

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


_lowerCamelCase					:						str					     =							{
    'configuration_ernie_m': ['ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ErnieMConfig'],
}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_lowerCamelCase					:						List[str]					     =							['ErnieMTokenizer']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_lowerCamelCase					:						Union[str, 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					:						int					     =							_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

