
"""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 DeiTImageProcessor





class 							snake_case       (     unittest.TestCase		):







   def __init__( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase=7       ,							__UpperCAmelCase=3       ,							__UpperCAmelCase=18       ,							__UpperCAmelCase=30       ,							__UpperCAmelCase=4_00       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=None       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=None       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=[0.5, 0.5, 0.5]       ,							__UpperCAmelCase=[0.5, 0.5, 0.5]       ,							)   ->List[str]:
      a_						   =     size if size is not None else {"height": 20, "width": 20}
      a_						   =     crop_size if crop_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_center_crop
      a_						   =     crop_size
      a_						   =     do_normalize
      a_						   =     image_mean
      a_						   =     image_std







   def    UpperCAmelCase__	( self)   ->Union[str, Any]:
      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
      }






@require_torch
@require_vision
class 							snake_case       (     A__							,       unittest.TestCase		):
   a_					:		List[str]     					=     DeiTImageProcessor if is_vision_available() else None
   a_					:		int     					=     True







   def    UpperCAmelCase__	( self)   ->Any:
      a_						   =     DeiTImageProcessingTester(self)







   @property
   def    UpperCAmelCase__	( self)   ->Tuple:
      return self.image_processor_tester.prepare_image_processor_dict()







   def    UpperCAmelCase__	( self)   ->Tuple:
      a_						   =     self.image_processing_class(**self.image_processor_dict)
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"do_resize"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"size"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"do_center_crop"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"center_crop"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"do_normalize"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"image_mean"))
      self.assertTrue(hasattr(_lowerCAmelCase       ,							"image_std"))







   def    UpperCAmelCase__	( self)   ->int:
      a_						   =     self.image_processing_class.from_dict(self.image_processor_dict)
      self.assertEqual(image_processor.size       ,							{"height": 20, "width": 20})
      self.assertEqual(image_processor.crop_size       ,							{"height": 18, "width": 18})

      a_						   =     self.image_processing_class.from_dict(self.image_processor_dict       ,							size=42       ,							crop_size=84)
      self.assertEqual(image_processor.size       ,							{"height": 42, "width": 42})
      self.assertEqual(image_processor.crop_size       ,							{"height": 84, "width": 84})







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







   def    UpperCAmelCase__	( self)   ->str:
      # 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)

      # 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)







   def    UpperCAmelCase__	( 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)

      # 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)







   def    UpperCAmelCase__	( self)   ->Optional[int]:
      # 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)

      # 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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )       ,							)






'''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__)

