
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 LevitImageProcessor




class 					lowerCamelCase__				(							unittest.TestCase):




	'''simple docstring'''




	def __init__(   self						:Dict	,  a						:Union[str, Any]	,  a						:List[Any]=7	,  a						:Any=3	,  a						:int=1_8	,  a						:List[str]=3_0	,  a						:str=4_0_0	,  a						:Union[str, Any]=True	,  a						:List[str]=None	,  a						:Dict=True	,  a						:Any=None	,  a						:str=True	,  a						:List[str]=[0.5, 0.5, 0.5]	,  a						:List[Any]=[0.5, 0.5, 0.5]	,  )						->					Tuple:
								__UpperCamelCase      :  Any       =   size if size is not None else {"shortest_edge": 1_8}
								__UpperCamelCase      :  List[str]       =   crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
								__UpperCamelCase      :  str       =   parent
								__UpperCamelCase      :  Union[str, Any]       =   batch_size
								__UpperCamelCase      :  int       =   num_channels
								__UpperCamelCase      :  List[Any]       =   image_size
								__UpperCamelCase      :  List[Any]       =   min_resolution
								__UpperCamelCase      :  Optional[Any]       =   max_resolution
								__UpperCamelCase      :  Optional[Any]       =   do_resize
								__UpperCamelCase      :  Optional[int]       =   size
								__UpperCamelCase      :  Any       =   do_center_crop
								__UpperCamelCase      :  Dict       =   crop_size
								__UpperCamelCase      :  Optional[int]       =   do_normalize
								__UpperCamelCase      :  List[str]       =   image_mean
								__UpperCamelCase      :  List[Any]       =   image_std







	def   _lowerCamelCase							(   self						:str		)						->					Tuple:
								return {
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_normalize": self.do_normalize,
								    "do_resize": self.do_resize,
								    "do_center_crop": self.do_center_crop,
								    "size": self.size,
								    "crop_size": self.crop_size,
								}




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




	'''simple docstring'''




	_A								=	LevitImageProcessor if is_vision_available() else None







	def   _lowerCamelCase							(   self						:str		)						->					Any:
								__UpperCamelCase      :  Union[str, Any]       =   LevitImageProcessingTester(self		)







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







	def   _lowerCamelCase							(   self						:Optional[int]		)						->					List[Any]:
								__UpperCamelCase      :  List[Any]       =   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	,  "do_center_crop"		)		)
								self.assertTrue(hasattr(a	,  "size"		)		)







	def   _lowerCamelCase							(   self						:Optional[Any]		)						->					str:
								__UpperCamelCase      :  Union[str, Any]       =   self.image_processing_class.from_dict(self.image_processor_dict		)
								self.assertEqual(image_processor.size	,  {"shortest_edge": 1_8}		)
								self.assertEqual(image_processor.crop_size	,  {"height": 1_8, "width": 1_8}		)

								__UpperCamelCase      :  List[Any]       =   self.image_processing_class.from_dict(self.image_processor_dict	,  size=4_2	,  crop_size=8_4		)
								self.assertEqual(image_processor.size	,  {"shortest_edge": 4_2}		)
								self.assertEqual(image_processor.crop_size	,  {"height": 8_4, "width": 8_4}		)







	def   _lowerCamelCase							(   self						:List[str]		)						->					int:
								pass







	def   _lowerCamelCase							(   self						:int		)						->					List[Any]:
								# Initialize image_processing
								__UpperCamelCase      :  Optional[Any]       =   self.image_processing_class(**self.image_processor_dict		)
								# create random PIL images
								__UpperCamelCase      :  Any       =   prepare_image_inputs(self.image_processor_tester	,  equal_resolution=a		)
								for image in image_inputs:
															self.assertIsInstance(a	,  Image.Image		)

								# 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.crop_size["height"],
								        self.image_processor_tester.crop_size["width"],
								    )	,  )

								# Test batched
								__UpperCamelCase      :  Union[str, Any]       =   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   _lowerCamelCase							(   self						:int		)						->					Optional[int]:
								# Initialize image_processing
								__UpperCamelCase      :  Optional[Any]       =   self.image_processing_class(**self.image_processor_dict		)
								# create random numpy tensors
								__UpperCamelCase      :  Any       =   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
								__UpperCamelCase      :  Tuple       =   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
								__UpperCamelCase      :  List[Any]       =   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   _lowerCamelCase							(   self						:List[Any]		)						->					Any:
								# Initialize image_processing
								__UpperCamelCase      :  Optional[Any]       =   self.image_processing_class(**self.image_processor_dict		)
								# create random PyTorch tensors
								__UpperCamelCase      :  str       =   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
								__UpperCamelCase      :  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.crop_size["height"],
								        self.image_processor_tester.crop_size["width"],
								    )	,  )

								# Test batched
								__UpperCamelCase      :  Union[str, Any]       =   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 typing import List

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


lowercase    :   Union[str, 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 					lowerCamelCase__				(							__lowercase):




	'''simple docstring'''




	_A								=	'efficientformer'







	def __init__(   self						:Union[str, Any]	,  a						:List[int] = [3, 2, 6, 4]	,  a						:List[int] = [4_8, 9_6, 2_2_4, 4_4_8]	,  a						:List[bool] = [True, True, True, True]	,  a						:int = 4_4_8	,  a						:int = 3_2	,  a						:int = 4	,  a						:int = 7	,  a						:int = 5	,  a						:int = 8	,  a						:int = 4	,  a						:float = 0.0	,  a						:int = 1_6	,  a						:int = 3	,  a						:int = 3	,  a						:int = 3	,  a						:int = 2	,  a						:int = 1	,  a						:float = 0.0	,  a						:int = 1	,  a						:bool = True	,  a						:bool = True	,  a						:float = 1E-5	,  a						:str = "gelu"	,  a						:float = 0.02	,  a						:float = 1E-1_2	,  a						:int = 2_2_4	,  a						:float = 1E-0_5	,  **a						:str	,  )						->					None:
								super().__init__(**a		)

								__UpperCamelCase      :  Optional[Any]       =   hidden_act
								__UpperCamelCase      :  Any       =   hidden_dropout_prob
								__UpperCamelCase      :  str       =   hidden_sizes
								__UpperCamelCase      :  Dict       =   num_hidden_layers
								__UpperCamelCase      :  Optional[Any]       =   num_attention_heads
								__UpperCamelCase      :  str       =   initializer_range
								__UpperCamelCase      :  List[str]       =   layer_norm_eps
								__UpperCamelCase      :  str       =   patch_size
								__UpperCamelCase      :  str       =   num_channels
								__UpperCamelCase      :  Any       =   depths
								__UpperCamelCase      :  Tuple       =   mlp_expansion_ratio
								__UpperCamelCase      :  List[str]       =   downsamples
								__UpperCamelCase      :  Optional[int]       =   dim
								__UpperCamelCase      :  Dict       =   key_dim
								__UpperCamelCase      :  Optional[Any]       =   attention_ratio
								__UpperCamelCase      :  Dict       =   resolution
								__UpperCamelCase      :  Union[str, Any]       =   pool_size
								__UpperCamelCase      :  Tuple       =   downsample_patch_size
								__UpperCamelCase      :  Optional[int]       =   downsample_stride
								__UpperCamelCase      :  Optional[int]       =   downsample_pad
								__UpperCamelCase      :  Union[str, Any]       =   drop_path_rate
								__UpperCamelCase      :  Union[str, Any]       =   num_metaad_blocks
								__UpperCamelCase      :  List[str]       =   distillation
								__UpperCamelCase      :  str       =   use_layer_scale
								__UpperCamelCase      :  Tuple       =   layer_scale_init_value
								__UpperCamelCase      :  str       =   image_size
								__UpperCamelCase      :  int       =   batch_norm_eps