


"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor






class      A(  unittest.TestCase		):

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=7					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=18					,				SCREAMING_SNAKE_CASE__=30					,				SCREAMING_SNAKE_CASE__=4_00					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=[0.5, 0.5, 0.5]					,				SCREAMING_SNAKE_CASE__=[0.5, 0.5, 0.5]					,				)      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	parent
					_UpperCamelCase					:Any					     =	batch_size
					_UpperCamelCase					:List[Any]					     =	num_channels
					_UpperCamelCase					:Any					     =	image_size
					_UpperCamelCase					:Optional[int]					     =	min_resolution
					_UpperCamelCase					:Tuple					     =	max_resolution
					_UpperCamelCase					:Any					     =	do_resize
					_UpperCamelCase					:Dict					     =	size if size is not None else {'''height''': 18, '''width''': 20}
					_UpperCamelCase					:Dict					     =	do_thumbnail
					_UpperCamelCase					:Any					     =	do_align_axis
					_UpperCamelCase					:Optional[Any]					     =	do_pad
					_UpperCamelCase					:int					     =	do_normalize
					_UpperCamelCase					:Dict					     =	image_mean
					_UpperCamelCase					:Optional[Any]					     =	image_std





		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_thumbnail": self.do_thumbnail,
					    "do_align_long_axis": self.do_align_axis,
					    "do_pad": self.do_pad,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					}






@require_torch
@require_vision
class      A(  lowerCamelCase__				,							unittest.TestCase		):

		"""simple docstring"""





		A    =							DonutImageProcessor if is_vision_available() else None
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Union[str, Any]					     =	DonutImageProcessingTester(self   )
		@property
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					return self.image_processor_tester.prepare_image_processor_dict()
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	self.image_processing_class(**self.image_processor_dict   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''do_resize'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''size'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''do_thumbnail'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''do_align_long_axis'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''do_pad'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''do_normalize'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''image_mean'''   )   )
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__					,				'''image_std'''   )   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.image_processing_class.from_dict(self.image_processor_dict   )
					self.assertEqual(image_processor.size					,				{'''height''': 18, '''width''': 20}   )

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

					# Previous config had dimensions in (width, height) order
					_UpperCamelCase					:str					     =	self.image_processing_class.from_dict(self.image_processor_dict					,				size=(42, 84)   )
					self.assertEqual(image_processor.size					,				{'''height''': 84, '''width''': 42}   )
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					pass
		@is_flaky()
		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



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

					# Test not batched input
					_UpperCamelCase					:Optional[int]					     =	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
					_UpperCamelCase					:Optional[Any]					     =	image_processing(SCREAMING_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'''],
					    )					,				)
		@is_flaky()
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	self.image_processing_class(**self.image_processor_dict   )
					# create random numpy tensors
					_UpperCamelCase					:str					     =	prepare_image_inputs(self.image_processor_tester					,				equal_resolution=SCREAMING_SNAKE_CASE__					,				numpify=SCREAMING_SNAKE_CASE__   )
					for image in image_inputs:
								self.assertIsInstance(SCREAMING_SNAKE_CASE__					,				np.ndarray   )

					# Test not batched input
					_UpperCamelCase					:Optional[int]					     =	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
					_UpperCamelCase					:List[Any]					     =	image_processing(SCREAMING_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'''],
					    )					,				)





		@is_flaky()
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	self.image_processing_class(**self.image_processor_dict   )
					# create random PyTorch tensors
					_UpperCamelCase					:Dict					     =	prepare_image_inputs(self.image_processor_tester					,				equal_resolution=SCREAMING_SNAKE_CASE__					,				torchify=SCREAMING_SNAKE_CASE__   )
					for image in image_inputs:
								self.assertIsInstance(SCREAMING_SNAKE_CASE__					,				torch.Tensor   )

					# Test not batched input
					_UpperCamelCase					:List[str]					     =	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
					_UpperCamelCase					:Tuple					     =	image_processing(SCREAMING_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'''],
					    )					,				)





"""simple docstring"""






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__				:Union[str, Any]			   =	logging.get_logger(__name__)

UpperCamelCase__				:Union[str, Any]			   =	{
    """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      A(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							"mobilenet_v2"
		def __init__( self					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=2_24					,				SCREAMING_SNAKE_CASE__=1.0					,				SCREAMING_SNAKE_CASE__=8					,				SCREAMING_SNAKE_CASE__=8					,				SCREAMING_SNAKE_CASE__=6					,				SCREAMING_SNAKE_CASE__=32					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__="relu6"					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=0.8					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=0.0_0_1					,				SCREAMING_SNAKE_CASE__=2_55					,				**SCREAMING_SNAKE_CASE__					,				)      ->	int:

					"""simple docstring"""



					super().__init__(**SCREAMING_SNAKE_CASE__   )

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

					_UpperCamelCase					:Optional[int]					     =	num_channels
					_UpperCamelCase					:Tuple					     =	image_size
					_UpperCamelCase					:Union[str, Any]					     =	depth_multiplier
					_UpperCamelCase					:Any					     =	depth_divisible_by
					_UpperCamelCase					:Optional[int]					     =	min_depth
					_UpperCamelCase					:Union[str, Any]					     =	expand_ratio
					_UpperCamelCase					:str					     =	output_stride
					_UpperCamelCase					:Tuple					     =	first_layer_is_expansion
					_UpperCamelCase					:Any					     =	finegrained_output
					_UpperCamelCase					:Union[str, Any]					     =	hidden_act
					_UpperCamelCase					:Any					     =	tf_padding
					_UpperCamelCase					:str					     =	classifier_dropout_prob
					_UpperCamelCase					:Optional[Any]					     =	initializer_range
					_UpperCamelCase					:int					     =	layer_norm_eps
					_UpperCamelCase					:Union[str, Any]					     =	semantic_loss_ignore_index






class      A(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							version.parse("1.11"		)
		@property
		def   _UpperCamelCase( self   )      ->	Mapping[str, Mapping[int, str]]:

					"""simple docstring"""



					return OrderedDict([('''pixel_values''', {0: '''batch'''})]   )
		@property
		def   _UpperCamelCase( self   )      ->	Mapping[str, Mapping[int, str]]:

					"""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   )      ->	float:

					"""simple docstring"""



					return 1E-4

