






"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


lowercase_				     =     {
    'configuration_mobilevit': ['MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MobileViTConfig', 'MobileViTOnnxConfig'],
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase_				     =     ['MobileViTFeatureExtractor']
       lowercase_				     =     ['MobileViTImageProcessor']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase_				     =     [
           'MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
           'MobileViTForImageClassification',
           'MobileViTForSemanticSegmentation',
           'MobileViTModel',
           'MobileViTPreTrainedModel',
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowercase_				     =     [
           'TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
           'TFMobileViTForImageClassification',
           'TFMobileViTForSemanticSegmentation',
           'TFMobileViTModel',
           'TFMobileViTPreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_mobilevit import MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, MobileViTConfig, MobileViTOnnxConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .feature_extraction_mobilevit import MobileViTFeatureExtractor
              from .image_processing_mobilevit import MobileViTImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mobilevit import (
                  MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  MobileViTForImageClassification,
                  MobileViTForSemanticSegmentation,
                  MobileViTModel,
                  MobileViTPreTrainedModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_mobilevit import (
                  TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFMobileViTForImageClassification,
                  TFMobileViTForSemanticSegmentation,
                  TFMobileViTModel,
                  TFMobileViTPreTrainedModel,
              )


else:
       import sys

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












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


class 					snake_case		(							unittest.TestCase						):


   '''simple docstring'''

   def __init__(	self :     List[str],       _lowerCamelCase :     Optional[Any],       _lowerCamelCase :     Union[str, Any]=13,       _lowerCamelCase :     Any=3,       _lowerCamelCase :     Optional[int]=2_24,       _lowerCamelCase :     str=30,       _lowerCamelCase :     Dict=4_00,       _lowerCamelCase :     Union[str, Any]=True,       _lowerCamelCase :     Any=None,       _lowerCamelCase :     Optional[Any]=True,       _lowerCamelCase :     Any=[0.5, 0.5, 0.5],       _lowerCamelCase :     List[str]=[0.5, 0.5, 0.5],       ):

     '''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 				_SCREAMING_SNAKE_CASE				(	self :     int  ):

     '''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 					snake_case		(							_lowerCAmelCase   ,	unittest.TestCase						):


   '''simple docstring'''

   A_						:	str						 = ViTImageProcessor if is_vision_available() else None


   def 				_SCREAMING_SNAKE_CASE				(	self :     Optional[int]  ):

     '''simple docstring'''
     __A									= EfficientFormerImageProcessorTester(self  )


   @property
   def 				_SCREAMING_SNAKE_CASE				(	self :     Dict  ):

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


   def 				_SCREAMING_SNAKE_CASE				(	self :     Optional[Any]  ):

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


   def 				_SCREAMING_SNAKE_CASE				(	self :     Union[str, Any]  ):

     '''simple docstring'''
     pass


   def 				_SCREAMING_SNAKE_CASE				(	self :     List[Any]  ):

     '''simple docstring'''
     # Initialize image_processor
     __A									= self.image_processing_class(**self.image_processor_dict  )
     # create random PIL images
     __A									= prepare_image_inputs(self.image_proc_tester,       equal_resolution=_lowerCamelCase  )
     for image in image_inputs:
       self.assertIsInstance(_lowerCamelCase,       Image.Image  )

     # Test not batched input
     __A									= image_processor(image_inputs[0],       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             1,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )

     # Test batched
     __A									= image_processor(_lowerCamelCase,       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             self.image_proc_tester.batch_size,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )


   def 				_SCREAMING_SNAKE_CASE				(	self :     Tuple  ):

     '''simple docstring'''
     # Initialize image_processor
     __A									= self.image_processing_class(**self.image_processor_dict  )
     # create random numpy tensors
     __A									= prepare_image_inputs(self.image_proc_tester,       equal_resolution=_lowerCamelCase,       numpify=_lowerCamelCase  )
     for image in image_inputs:
       self.assertIsInstance(_lowerCamelCase,       np.ndarray  )

     # Test not batched input
     __A									= image_processor(image_inputs[0],       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             1,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )

     # Test batched
     __A									= image_processor(_lowerCamelCase,       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             self.image_proc_tester.batch_size,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )






   def 				_SCREAMING_SNAKE_CASE				(	self :     str  ):

     '''simple docstring'''
     # Initialize image_processor
     __A									= self.image_processing_class(**self.image_processor_dict  )
     # create random PyTorch tensors
     __A									= prepare_image_inputs(self.image_proc_tester,       equal_resolution=_lowerCamelCase,       torchify=_lowerCamelCase  )
     for image in image_inputs:
       self.assertIsInstance(_lowerCamelCase,       torch.Tensor  )

     # Test not batched input
     __A									= image_processor(image_inputs[0],       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             1,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )

     # Test batched
     __A									= image_processor(_lowerCamelCase,       return_tensors='''pt'''  ).pixel_values
     self.assertEqual(
         encoded_images.shape,       (
             self.image_proc_tester.batch_size,
             self.image_proc_tester.num_channels,
             self.image_proc_tester.size['''height'''],
             self.image_proc_tester.size['''width'''],
         ),       )




