


'''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 LevitImageProcessor
class 						UpperCamelCase__       (			unittest.TestCase						):



     """simple docstring"""






     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__=None   ,						snake_case__=True   ,						snake_case__=[0.5, 0.5, 0.5]   ,						snake_case__=[0.5, 0.5, 0.5]   ,						):

            '''simple docstring'''

            _lowerCAmelCase     :				Any       =							size if size is not None else {'shortest_edge': 18}
            _lowerCAmelCase     :				Union[str, Any]       =							crop_size if crop_size is not None else {'height': 18, 'width': 18}
            _lowerCAmelCase     :				Dict       =							parent
            _lowerCAmelCase     :				List[Any]       =							batch_size
            _lowerCAmelCase     :				Optional[Any]       =							num_channels
            _lowerCAmelCase     :				int       =							image_size
            _lowerCAmelCase     :				Tuple       =							min_resolution
            _lowerCAmelCase     :				List[Any]       =							max_resolution
            _lowerCAmelCase     :				List[Any]       =							do_resize
            _lowerCAmelCase     :				str       =							size
            _lowerCAmelCase     :				List[Any]       =							do_center_crop
            _lowerCAmelCase     :				int       =							crop_size
            _lowerCAmelCase     :				Optional[Any]       =							do_normalize
            _lowerCAmelCase     :				Dict       =							image_mean
            _lowerCAmelCase     :				Any       =							image_std







     def a						(			self ):

            '''simple docstring'''

            return {
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_normalize": self.do_normalize,
                "do_resize": self.do_resize,
                "do_center_crop": self.do_center_crop,
                "size": self.size,
                "crop_size": self.crop_size,
            }
@require_torch
@require_vision
class 						UpperCamelCase__       (			SCREAMING_SNAKE_CASE_     ,       unittest.TestCase						):



     """simple docstring"""






     __magic_name__           =     LevitImageProcessor if is_vision_available() else None







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				List[str]       =							LevitImageProcessingTester(self )







     @property
     def a						(			self ):

            '''simple docstring'''

            return self.image_processor_tester.prepare_image_processor_dict()







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				List[Any]       =							self.image_processing_class(**self.image_processor_dict )
            self.assertTrue(hasattr(snake_case__   ,						'image_mean' ) )
            self.assertTrue(hasattr(snake_case__   ,						'image_std' ) )
            self.assertTrue(hasattr(snake_case__   ,						'do_normalize' ) )
            self.assertTrue(hasattr(snake_case__   ,						'do_resize' ) )
            self.assertTrue(hasattr(snake_case__   ,						'do_center_crop' ) )
            self.assertTrue(hasattr(snake_case__   ,						'size' ) )







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				int       =							self.image_processing_class.from_dict(self.image_processor_dict )
            self.assertEqual(image_processor.size   ,						{'shortest_edge': 18} )
            self.assertEqual(image_processor.crop_size   ,						{'height': 18, 'width': 18} )

            _lowerCAmelCase     :				List[str]       =							self.image_processing_class.from_dict(self.image_processor_dict   ,						size=42   ,						crop_size=84 )
            self.assertEqual(image_processor.size   ,						{'shortest_edge': 42} )
            self.assertEqual(image_processor.crop_size   ,						{'height': 84, 'width': 84} )







     def a						(			self ):

            '''simple docstring'''

            pass







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Optional[int]       =							self.image_processing_class(**self.image_processor_dict )
            # create random PIL images
            _lowerCAmelCase     :				Optional[Any]       =							prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=snake_case__ )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__   ,						Image.Image )

            # Test not batched input
            _lowerCAmelCase     :				Optional[Any]       =							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
            _lowerCAmelCase     :				int       =							image_processing(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.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Optional[int]       =							self.image_processing_class(**self.image_processor_dict )
            # create random numpy tensors
            _lowerCAmelCase     :				List[Any]       =							prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=snake_case__   ,						numpify=snake_case__ )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__   ,						np.ndarray )

            # Test not batched input
            _lowerCAmelCase     :				str       =							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
            _lowerCAmelCase     :				str       =							image_processing(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.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Union[str, Any]       =							self.image_processing_class(**self.image_processor_dict )
            # create random PyTorch tensors
            _lowerCAmelCase     :				Optional[Any]       =							prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=snake_case__   ,						torchify=snake_case__ )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__   ,						torch.Tensor )

            # Test not batched input
            _lowerCAmelCase     :				int       =							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
            _lowerCAmelCase     :				Union[str, Any]       =							image_processing(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.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)





'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase     :  List[str]											=    {
    """configuration_electra""": ["""ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ElectraConfig""", """ElectraOnnxConfig"""],
    """tokenization_electra""": ["""ElectraTokenizer"""],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Optional[Any]											=    ["""ElectraTokenizerFast"""]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  str											=    [
           """ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """ElectraForCausalLM""",
           """ElectraForMaskedLM""",
           """ElectraForMultipleChoice""",
           """ElectraForPreTraining""",
           """ElectraForQuestionAnswering""",
           """ElectraForSequenceClassification""",
           """ElectraForTokenClassification""",
           """ElectraModel""",
           """ElectraPreTrainedModel""",
           """load_tf_weights_in_electra""",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Tuple											=    [
           """TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFElectraForMaskedLM""",
           """TFElectraForMultipleChoice""",
           """TFElectraForPreTraining""",
           """TFElectraForQuestionAnswering""",
           """TFElectraForSequenceClassification""",
           """TFElectraForTokenClassification""",
           """TFElectraModel""",
           """TFElectraPreTrainedModel""",
       ]

try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Union[str, Any]											=    [
           """FlaxElectraForCausalLM""",
           """FlaxElectraForMaskedLM""",
           """FlaxElectraForMultipleChoice""",
           """FlaxElectraForPreTraining""",
           """FlaxElectraForQuestionAnswering""",
           """FlaxElectraForSequenceClassification""",
           """FlaxElectraForTokenClassification""",
           """FlaxElectraModel""",
           """FlaxElectraPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
       from .tokenization_electra import ElectraTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_electra_fast import ElectraTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_electra import (
                  ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  ElectraForCausalLM,
                  ElectraForMaskedLM,
                  ElectraForMultipleChoice,
                  ElectraForPreTraining,
                  ElectraForQuestionAnswering,
                  ElectraForSequenceClassification,
                  ElectraForTokenClassification,
                  ElectraModel,
                  ElectraPreTrainedModel,
                  load_tf_weights_in_electra,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_electra import (
                  TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFElectraForMaskedLM,
                  TFElectraForMultipleChoice,
                  TFElectraForPreTraining,
                  TFElectraForQuestionAnswering,
                  TFElectraForSequenceClassification,
                  TFElectraForTokenClassification,
                  TFElectraModel,
                  TFElectraPreTrainedModel,
              )

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_flax_electra import (
                  FlaxElectraForCausalLM,
                  FlaxElectraForMaskedLM,
                  FlaxElectraForMultipleChoice,
                  FlaxElectraForPreTraining,
                  FlaxElectraForQuestionAnswering,
                  FlaxElectraForSequenceClassification,
                  FlaxElectraForTokenClassification,
                  FlaxElectraModel,
                  FlaxElectraPreTrainedModel,
              )

else:
       import sys

       lowerCAmelCase     :  int											=    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

