






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 MobileNetVaImageProcessor



class       __UpperCAmelCase		(unittest.TestCase    ):







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







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







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







									'''simple docstring'''




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



@require_torch
@require_vision
class       __UpperCAmelCase		(lowerCamelCase_       ,unittest.TestCase    ):
			__snake_case				:      Union[str, Any] 						=							MobileNetVaImageProcessor if is_vision_available() else None







			def 							UpperCamelCase      (	self:  str     ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE	      =  MobileNetVaImageProcessingTester(self     )







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







									'''simple docstring'''




									return self.image_processor_tester.prepare_image_processor_dict()







			def 							UpperCamelCase      (	self:  List[str]     ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE	      =  self.image_processing_class(**self.image_processor_dict     )
									self.assertTrue(hasattr(__snake_case      ,	"""do_resize"""     )     )
									self.assertTrue(hasattr(__snake_case      ,	"""size"""     )     )
									self.assertTrue(hasattr(__snake_case      ,	"""do_center_crop"""     )     )
									self.assertTrue(hasattr(__snake_case      ,	"""crop_size"""     )     )







			def 							UpperCamelCase      (	self:  int     ):







									'''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:  str     ):







									'''simple docstring'''




									pass







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







									'''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=__snake_case     )
									for image in image_inputs:
															self.assertIsInstance(__snake_case      ,	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(__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.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=__snake_case      ,	numpify=__snake_case     )
									for image in image_inputs:
															self.assertIsInstance(__snake_case      ,	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(__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.crop_size["""height"""],
									        self.image_processor_tester.crop_size["""width"""],
									    )      ,	)







			def 							UpperCamelCase      (	self:  Tuple     ):







									'''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=__snake_case      ,	torchify=__snake_case     )
									for image in image_inputs:
															self.assertIsInstance(__snake_case      ,	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(__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.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


snake_case							:       Union[str, Any]     			=      logging.get_logger(__name__)

snake_case							:       str     			=      {
    '''google/mobilenet_v2_1.4_224''': '''https://huggingface.co/google/mobilenet_v2_1.4_224/resolve/main/config.json''',
    '''google/mobilenet_v2_1.0_224''': '''https://huggingface.co/google/mobilenet_v2_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v2_0.75_160''': '''https://huggingface.co/google/mobilenet_v2_0.75_160/resolve/main/config.json''',
    '''google/mobilenet_v2_0.35_96''': '''https://huggingface.co/google/mobilenet_v2_0.35_96/resolve/main/config.json''',
    # See all MobileNetV2 models at https://huggingface.co/models?filter=mobilenet_v2
}







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    str          =			'''mobilenet_v2'''
					def __init__(      self   :Optional[Any]			,__snake_case   :List[Any]=3			,__snake_case   :Any=2_24			,__snake_case   :Dict=1.0			,__snake_case   :str=8			,__snake_case   :Union[str, Any]=8			,__snake_case   :Optional[Any]=6			,__snake_case   :str=32			,__snake_case   :Tuple=True			,__snake_case   :Union[str, Any]=True			,__snake_case   :Any="relu6"			,__snake_case   :List[str]=True			,__snake_case   :Dict=0.8			,__snake_case   :Optional[int]=0.02			,__snake_case   :Tuple=0.0_01			,__snake_case   :Dict=2_55			,**__snake_case   :Dict			,)					->    Any:
												super().__init__(**__snake_case      )

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

												a__             =     num_channels
												a__             =     image_size
												a__             =     depth_multiplier
												a__             =     depth_divisible_by
												a__             =     min_depth
												a__             =     expand_ratio
												a__             =     output_stride
												a__             =     first_layer_is_expansion
												a__             =     finegrained_output
												a__             =     hidden_act
												a__             =     tf_padding
												a__             =     classifier_dropout_prob
												a__             =     initializer_range
												a__             =     layer_norm_eps
												a__             =     semantic_loss_ignore_index







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    Tuple          =			version.parse('''1.11'''      )
					@property
					def  lowerCamelCase__(      self   :Any      )					->    Mapping[str, Mapping[int, str]]:
												return OrderedDict([('pixel_values', {0: 'batch'})]      )
					@property
					def  lowerCamelCase__(      self   :List[str]      )					->    Mapping[str, Mapping[int, str]]:
												if self.task == "image-classification":
																			return OrderedDict([('logits', {0: 'batch'})]      )
												else:
																			return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]      )



					@property
					def  lowerCamelCase__(      self   :Any      )					->    float:
												return 1E-4




