






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[Any]				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  Union[str, Any]=7				,     UpperCAmelCase_:  List[Any]=3				,     UpperCAmelCase_:  Optional[int]=18				,     UpperCAmelCase_:  Union[str, Any]=30				,     UpperCAmelCase_:  Any=400				,     UpperCAmelCase_:  Union[str, Any]=True				,     UpperCAmelCase_:  Any=None				,     UpperCAmelCase_:  Union[str, Any]=True				,     UpperCAmelCase_:  str=None				,     UpperCAmelCase_:  List[Any]=True				,     ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  size if size is not None else {"""shortest_edge""": 20}
									_SCREAMING_SNAKE_CASE     				=  crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
									_SCREAMING_SNAKE_CASE     				=  parent
									_SCREAMING_SNAKE_CASE     				=  batch_size
									_SCREAMING_SNAKE_CASE     				=  num_channels
									_SCREAMING_SNAKE_CASE     				=  image_size
									_SCREAMING_SNAKE_CASE     				=  min_resolution
									_SCREAMING_SNAKE_CASE     				=  max_resolution
									_SCREAMING_SNAKE_CASE     				=  do_resize
									_SCREAMING_SNAKE_CASE     				=  size
									_SCREAMING_SNAKE_CASE     				=  do_center_crop
									_SCREAMING_SNAKE_CASE     				=  crop_size
									_SCREAMING_SNAKE_CASE     				=  do_flip_channel_order







			def 							UpperCamelCase				(     self:  Dict					):







									'''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		(SCREAMING_SNAKE_CASE__	,unittest.TestCase   ):
			__snake_case    :				str									=							MobileViTImageProcessor if is_vision_available() else None







			def 							UpperCamelCase				(     self:  Optional[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  MobileViTImageProcessingTester(self					)







			@property
			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									return self.image_processor_tester.prepare_image_processor_dict()







			def 							UpperCamelCase				(     self:  Optional[int]					):







									'''simple docstring'''




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







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  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}					)

									_SCREAMING_SNAKE_CASE     				=  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 							UpperCamelCase				(     self:  Tuple					):







									'''simple docstring'''




									pass







			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.image_processing_class(**self.image_processor_dict					)
									# create random PIL images
									_SCREAMING_SNAKE_CASE     				=  prepare_image_inputs(self.image_processor_tester				,     equal_resolution=a_					)
									for image in image_inputs:
															self.assertIsInstance(a_				,     Image.Image					)

									# Test not batched input
									_SCREAMING_SNAKE_CASE     				=  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
									_SCREAMING_SNAKE_CASE     				=  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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )				,     )







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.image_processing_class(**self.image_processor_dict					)
									# create random numpy tensors
									_SCREAMING_SNAKE_CASE     				=  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
									_SCREAMING_SNAKE_CASE     				=  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
									_SCREAMING_SNAKE_CASE     				=  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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )				,     )







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.image_processing_class(**self.image_processor_dict					)
									# create random PyTorch tensors
									_SCREAMING_SNAKE_CASE     				=  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
									_SCREAMING_SNAKE_CASE     				=  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
									_SCREAMING_SNAKE_CASE     				=  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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )				,     )









from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCamelCase			    =     logging.get_logger(__name__)

UpperCamelCase			    =     {
    '''google/mobilenet_v1_1.0_224''': '''https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v1_0.75_192''': '''https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json''',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Any									=							"mobilenet_v1"







			def __init__(     self:  List[str]				,     UpperCAmelCase_:  List[Any]=3				,     UpperCAmelCase_:  List[str]=224				,     UpperCAmelCase_:  Optional[Any]=1.0				,     UpperCAmelCase_:  Dict=8				,     UpperCAmelCase_:  List[str]="relu6"				,     UpperCAmelCase_:  List[Any]=True				,     UpperCAmelCase_:  Dict=0.9_99				,     UpperCAmelCase_:  Union[str, Any]=0.02				,     UpperCAmelCase_:  Tuple=0.0_01				,     **UpperCAmelCase_:  List[str]				,     ):







									'''simple docstring'''




									super().__init__(**UpperCAmelCase_					)

									if depth_multiplier <= 0:
															raise ValueError("""depth_multiplier must be greater than zero."""					)

									_SCREAMING_SNAKE_CASE     				=  num_channels
									_SCREAMING_SNAKE_CASE     				=  image_size
									_SCREAMING_SNAKE_CASE     				=  depth_multiplier
									_SCREAMING_SNAKE_CASE     				=  min_depth
									_SCREAMING_SNAKE_CASE     				=  hidden_act
									_SCREAMING_SNAKE_CASE     				=  tf_padding
									_SCREAMING_SNAKE_CASE     				=  classifier_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  initializer_range
									_SCREAMING_SNAKE_CASE     				=  layer_norm_eps



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				List[Any]									=							version.parse("1.11"   )







			@property
			def 							UpperCamelCase				(     self:  Tuple					):







									'''simple docstring'''




									return OrderedDict([("""pixel_values""", {0: """batch"""})]					)







			@property
			def 							UpperCamelCase				(     self:  Dict					):







									'''simple docstring'''




									if self.task == "image-classification":
															return OrderedDict([("""logits""", {0: """batch"""})]					)
									else:
															return OrderedDict([("""last_hidden_state""", {0: """batch"""}), ("""pooler_output""", {0: """batch"""})]					)







			@property
			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									return 1E-4

