




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




class 	UpperCAmelCase_  (						unittest.TestCase							):




    def __init__(    self						:       Optional[int]	, snake_case_						:       Union[str, Any]	, snake_case_						:       Optional[Any]=7	, snake_case_						:       List[str]=3	, snake_case_						:       Optional[int]=18	, snake_case_						:       Dict=30	, snake_case_						:       int=400	, snake_case_						:       str=True	, snake_case_						:       Dict=None	, snake_case_						:       Optional[int]=True	, snake_case_						:       Tuple=None	, snake_case_						:       str=True	, )      ->							Dict:




     '''simple docstring'''

     A__       =				size if size is not None else {"""shortest_edge""": 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_flip_channel_order




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




     '''simple docstring'''

     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_center_crop": self.do_center_crop,
         "crop_size": self.crop_size,
         "do_flip_channel_order": self.do_flip_channel_order,
     }






@require_torch
@require_vision
class 	UpperCAmelCase_  (						snake_case_,   unittest.TestCase							):
    lowercase__											=      MobileViTImageProcessor if is_vision_available() else None




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




     '''simple docstring'''

     A__       =				MobileViTImageProcessingTester(self      )




    @property
    def 							__magic_name__							(    self						:       Dict      )      ->							str:




     '''simple docstring'''

     return self.image_processor_tester.prepare_image_processor_dict()




    def 							__magic_name__							(    self						:       str      )      ->							Tuple:




     '''simple docstring'''

     A__       =				self.image_processing_class(**self.image_processor_dict      )
     self.assertTrue(hasattr(UpperCAmelCase__	, "do_resize"      )      )
     self.assertTrue(hasattr(UpperCAmelCase__	, "size"      )      )
     self.assertTrue(hasattr(UpperCAmelCase__	, "do_center_crop"      )      )
     self.assertTrue(hasattr(UpperCAmelCase__	, "center_crop"      )      )
     self.assertTrue(hasattr(UpperCAmelCase__	, "do_flip_channel_order"      )      )




    def 							__magic_name__							(    self						:       str      )      ->							str:




     '''simple docstring'''

     A__       =				self.image_processing_class.from_dict(self.image_processor_dict      )
     self.assertEqual(image_processor.size	, {"shortest_edge": 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	, {"shortest_edge": 42}      )
     self.assertEqual(image_processor.crop_size	, {"height": 84, "width": 84}      )




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




     '''simple docstring'''

     pass




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




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




    def 							__magic_name__							(    self						:       int      )      ->							Tuple:




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




    def 							__magic_name__							(    self						:       List[str]      )      ->							Dict:




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













"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


_snake_case          =   {
    'configuration_transfo_xl': ['TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TransfoXLConfig'],
    'tokenization_transfo_xl': ['TransfoXLCorpus', 'TransfoXLTokenizer'],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   [
     'TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'AdaptiveEmbedding',
     'TransfoXLForSequenceClassification',
     'TransfoXLLMHeadModel',
     'TransfoXLModel',
     'TransfoXLPreTrainedModel',
     'load_tf_weights_in_transfo_xl',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   [
     'TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFAdaptiveEmbedding',
     'TFTransfoXLForSequenceClassification',
     'TFTransfoXLLMHeadModel',
     'TFTransfoXLMainLayer',
     'TFTransfoXLModel',
     'TFTransfoXLPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
 from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_transfo_xl import (
      TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
      AdaptiveEmbedding,
      TransfoXLForSequenceClassification,
      TransfoXLLMHeadModel,
      TransfoXLModel,
      TransfoXLPreTrainedModel,
      load_tf_weights_in_transfo_xl,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_transfo_xl import (
      TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFAdaptiveEmbedding,
      TFTransfoXLForSequenceClassification,
      TFTransfoXLLMHeadModel,
      TFTransfoXLMainLayer,
      TFTransfoXLModel,
      TFTransfoXLPreTrainedModel,
  )

else:
 import sys

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

