


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

				"""simple docstring"""







				def __init__(    self					, a__					, a__=7					, a__=3					, a__=18					, a__=30					, a__=400					, a__=True					, a__=None					, a__=True					, a__=False					, a__=True					, a__=True					, a__=[0.5, 0.5, 0.5]					, a__=[0.5, 0.5, 0.5]					, )						->					Tuple:
					A             =					parent
					A             =					batch_size
					A             =					num_channels
					A             =					image_size
					A             =					min_resolution
					A             =					max_resolution
					A             =					do_resize
					A             =					size if size is not None else {"""height""": 18, """width""": 20}
					A             =					do_thumbnail
					A             =					do_align_axis
					A             =					do_pad
					A             =					do_normalize
					A             =					image_mean
					A             =					image_std

				def   _UpperCAmelCase       (    self )						->					Dict:
					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    _UpperCamelCase     (       __snake_case     ,		unittest.TestCase					):

				"""simple docstring"""







				lowerCAmelCase					=			DonutImageProcessor if is_vision_available() else None

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					DonutImageProcessingTester(self )

				@property
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					return self.image_processor_tester.prepare_image_processor_dict()

				def   _UpperCAmelCase       (    self )						->					str:
					A             =					self.image_processing_class(**self.image_processor_dict )
					self.assertTrue(hasattr(a__					, """do_resize""" ) )
					self.assertTrue(hasattr(a__					, """size""" ) )
					self.assertTrue(hasattr(a__					, """do_thumbnail""" ) )
					self.assertTrue(hasattr(a__					, """do_align_long_axis""" ) )
					self.assertTrue(hasattr(a__					, """do_pad""" ) )
					self.assertTrue(hasattr(a__					, """do_normalize""" ) )
					self.assertTrue(hasattr(a__					, """image_mean""" ) )
					self.assertTrue(hasattr(a__					, """image_std""" ) )

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					self.image_processing_class.from_dict(self.image_processor_dict )
					self.assertEqual(image_processor.size					, {"""height""": 18, """width""": 20} )

					A             =					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
					A             =					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 )						->					str:
					pass

				@is_flaky()
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					# Initialize image_processing
					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"""],
					    )					, )

				@is_flaky()
				def   _UpperCAmelCase       (    self )						->					List[str]:
					# Initialize image_processing
					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"""],
					    )					, )

				@is_flaky()
				def   _UpperCAmelCase       (    self )						->					Union[str, Any]:
					# Initialize image_processing
					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"""],
					    )					, )







from typing import List

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase							:   Any						=						logging.get_logger(__name__)

_lowercase							:   Union[str, Any]						=						{
    "snap-research/efficientformer-l1-300": (
        "https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json"
    ),
}






class    _UpperCamelCase     (       __snake_case					):

				"""simple docstring"""







				lowerCAmelCase					=			'efficientformer'

				def __init__(    self					, a__ = [3, 2, 6, 4]					, a__ = [48, 96, 224, 448]					, a__ = [True, True, True, True]					, a__ = 448					, a__ = 32					, a__ = 4					, a__ = 7					, a__ = 5					, a__ = 8					, a__ = 4					, a__ = 0.0					, a__ = 16					, a__ = 3					, a__ = 3					, a__ = 3					, a__ = 2					, a__ = 1					, a__ = 0.0					, a__ = 1					, a__ = True					, a__ = True					, a__ = 1e-5					, a__ = "gelu"					, a__ = 0.02					, a__ = 1e-12					, a__ = 224					, a__ = 1e-05					, **a__					, )						->					None:
					super().__init__(**a__ )

					A             =					hidden_act
					A             =					hidden_dropout_prob
					A             =					hidden_sizes
					A             =					num_hidden_layers
					A             =					num_attention_heads
					A             =					initializer_range
					A             =					layer_norm_eps
					A             =					patch_size
					A             =					num_channels
					A             =					depths
					A             =					mlp_expansion_ratio
					A             =					downsamples
					A             =					dim
					A             =					key_dim
					A             =					attention_ratio
					A             =					resolution
					A             =					pool_size
					A             =					downsample_patch_size
					A             =					downsample_stride
					A             =					downsample_pad
					A             =					drop_path_rate
					A             =					num_metaad_blocks
					A             =					distillation
					A             =					use_layer_scale
					A             =					layer_scale_init_value
					A             =					image_size
					A             =					batch_norm_eps



