'''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 EfficientNetImageProcessor




class       __UpperCAmelCase							(							unittest.TestCase	):





       '''simple docstring'''



       def __init__( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE=13       ,	_SCREAMING_SNAKE_CASE=3       ,	_SCREAMING_SNAKE_CASE=18       ,	_SCREAMING_SNAKE_CASE=30       ,	_SCREAMING_SNAKE_CASE=400       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]       ,	_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]       ,	)						->	Any:
           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    __A			( self					)						->	int:
           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       __UpperCAmelCase							(							lowerCamelCase__		, unittest.TestCase	):





       '''simple docstring'''



       __lowercase   :   Any  					=							EfficientNetImageProcessor if is_vision_available() else None

       def    __A			( self					)						->	Tuple:
           A_      =  EfficientNetImageProcessorTester(self					)

       @property
       def    __A			( self					)						->	int:
           return self.image_processor_tester.prepare_image_processor_dict()

       def    __A			( self					)						->	List[str]:
           A_      =  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__       ,	'''size'''					)					)

       def    __A			( self					)						->	Tuple:
           A_      =  self.image_processing_class.from_dict(self.image_processor_dict					)
           self.assertEqual(image_processor.size       ,	{'''height''': 18, '''width''': 18}					)

           A_      =  self.image_processing_class.from_dict(self.image_processor_dict       ,	size=42					)
           self.assertEqual(image_processor.size       ,	{'''height''': 42, '''width''': 42}					)

       def    __A			( self					)						->	Dict:
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random PIL images
           A_      =  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
           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['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)

           # Test batched
           A_      =  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.size['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)

       def    __A			( self					)						->	Dict:
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random numpy tensors
           A_      =  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
           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['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)

           # Test batched
           A_      =  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.size['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)

       def    __A			( self					)						->	str:
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random PyTorch tensors
           A_      =  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
           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['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)

           # Test batched
           A_      =  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.size['''height'''],
                   self.image_processor_tester.size['''width'''],
               )       ,	)







from typing import TYPE_CHECKING

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


__snake_case         =     {
    '''configuration_mobilevitv2''': [
        '''MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''MobileViTV2Config''',
        '''MobileViTV2OnnxConfig''',
    ],
}


try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __snake_case         =     [
         '''MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''MobileViTV2ForImageClassification''',
         '''MobileViTV2ForSemanticSegmentation''',
         '''MobileViTV2Model''',
         '''MobileViTV2PreTrainedModel''',
     ]

if TYPE_CHECKING:
     from .configuration_mobilevitva import (
         MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
         MobileViTVaConfig,
         MobileViTVaOnnxConfig,
     )

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mobilevitva import (
              MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
              MobileViTVaForImageClassification,
              MobileViTVaForSemanticSegmentation,
              MobileViTVaModel,
              MobileViTVaPreTrainedModel,
          )

else:
     import sys

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