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






	def __init__(			self  :Dict	,				_A  :int	,				_A  :Optional[Any]=7	,				_A  :int=3	,				_A  :Optional[Any]=18	,				_A  :Optional[int]=30	,				_A  :Any=400	,				_A  :Optional[Any]=True	,				_A  :Optional[int]=None	,				_A  :Any=True	,				_A  :Optional[Any]=[0.5, 0.5, 0.5]	,				_A  :int=[0.5, 0.5, 0.5]	,				)				->			Dict:







							'''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 	lowercase_						(			self  :Tuple			)				->			Tuple:







							'''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  UpperCamelCase__  (    SCREAMING_SNAKE_CASE      ,     unittest.TestCase):
	UpperCAmelCase__    :    str										=					ViTImageProcessor if is_vision_available() else None






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







							'''simple docstring'''



							__A       	=			ViTImageProcessingTester(self			)






	@property
	def 	lowercase_						(			self  :List[str]			)				->			str:







							'''simple docstring'''



							return self.image_processor_tester.prepare_image_processor_dict()






	def 	lowercase_						(			self  :Tuple			)				->			Optional[int]:







							'''simple docstring'''



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






	def 	lowercase_						(			self  :Any			)				->			Dict:







							'''simple docstring'''



							__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 	lowercase_						(			self  :Tuple			)				->			int:







							'''simple docstring'''



							pass






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







							'''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=_A			)
							for image in image_inputs:
													self.assertIsInstance(_A	,				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(_A	,				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 	lowercase_						(			self  :str			)				->			str:







							'''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=_A	,				numpify=_A			)
							for image in image_inputs:
													self.assertIsInstance(_A	,				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(_A	,				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 	lowercase_						(			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=_A	,				torchify=_A			)
							for image in image_inputs:
													self.assertIsInstance(_A	,				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(_A	,				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'],
							    )	,				)








'''simple docstring'''





from typing import TYPE_CHECKING

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


a__		:   Optional[Any]            =       {
    "configuration_mobilevitv2": [
        "MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "MobileViTV2Config",
        "MobileViTV2OnnxConfig",
    ],
}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   Optional[int]            =       [
     "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

 a__		:   List[str]            =       _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






