






"""simple docstring"""
from typing import List

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


lowerCamelCase_							      = logging.get_logger(__name__)

lowerCamelCase_							      = {
    '''snap-research/efficientformer-l1-300''': (
        '''https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json'''
    ),
}







class      UpperCamelCase_			(__A	):
	__magic_name__       =							'''efficientformer'''





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

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











"""simple docstring"""
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 ViTImageProcessor







class      UpperCamelCase_			(unittest.TestCase	):





	def __init__( self   :					Optional[int]      ,      lowerCAmelCase_   :					Tuple      ,      lowerCAmelCase_   :					List[str]=13      ,      lowerCAmelCase_   :					Union[str, Any]=3      ,      lowerCAmelCase_   :					Union[str, Any]=224      ,      lowerCAmelCase_   :					List[Any]=30      ,      lowerCAmelCase_   :					Any=400      ,      lowerCAmelCase_   :					Any=True      ,      lowerCAmelCase_   :					Dict=None      ,      lowerCAmelCase_   :					int=True      ,      lowerCAmelCase_   :					Any=[0.5, 0.5, 0.5]      ,      lowerCAmelCase_   :					str=[0.5, 0.5, 0.5]      ,      )		->     Dict:
				UpperCAmelCase_	:					int     	=   size if size is not None else {"height": 18, "width": 18}
				UpperCAmelCase_	:					List[Any]     	=   parent
				UpperCAmelCase_	:					int     	=   batch_size
				UpperCAmelCase_	:					Optional[int]     	=   num_channels
				UpperCAmelCase_	:					Dict     	=   image_size
				UpperCAmelCase_	:					Union[str, Any]     	=   min_resolution
				UpperCAmelCase_	:					List[str]     	=   max_resolution
				UpperCAmelCase_	:					Dict     	=   do_resize
				UpperCAmelCase_	:					Optional[int]     	=   size
				UpperCAmelCase_	:					List[str]     	=   do_normalize
				UpperCAmelCase_	:					List[Any]     	=   image_mean
				UpperCAmelCase_	:					Dict     	=   image_std





	def 	_SCREAMING_SNAKE_CASE ( self   :					int		)		->     Union[str, Any]:
				return {
				    "image_mean": self.image_mean,
				    "image_std": self.image_std,
				    "do_normalize": self.do_normalize,
				    "do_resize": self.do_resize,
				    "size": self.size,
				}







@require_torch
@require_vision
class      UpperCamelCase_			(__A							,		unittest.TestCase	):
	__magic_name__       =							ViTImageProcessor if is_vision_available() else None





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     Optional[Any]:
				UpperCAmelCase_	:					Optional[Any]     	=   EfficientFormerImageProcessorTester(self		)





	@property
	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     List[Any]:
				return self.image_proc_tester.prepare_image_processor_dict()





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple		)		->     str:
				UpperCAmelCase_	:					Tuple     	=   self.image_processing_class(**self.image_processor_dict		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "image_mean"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "image_std"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "do_normalize"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "do_resize"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "size"		)		)





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





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     int:
				# Initialize image_processor
				UpperCAmelCase_	:					str     	=   self.image_processing_class(**self.image_processor_dict		)
				# create random PIL images
				UpperCAmelCase_	:					int     	=   prepare_image_inputs(self.image_proc_tester      ,      equal_resolution=lowerCAmelCase_		)
				for image in image_inputs:
							self.assertIsInstance(lowerCAmelCase_      ,      Image.Image		)

				# Test not batched input
				UpperCAmelCase_	:					Optional[Any]     	=   image_processor(image_inputs[0]      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        1,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )

				# Test batched
				UpperCAmelCase_	:					str     	=   image_processor(lowerCAmelCase_      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        self.image_proc_tester.batch_size,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )





	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     List[Any]:
				# Initialize image_processor
				UpperCAmelCase_	:					List[str]     	=   self.image_processing_class(**self.image_processor_dict		)
				# create random numpy tensors
				UpperCAmelCase_	:					List[str]     	=   prepare_image_inputs(self.image_proc_tester      ,      equal_resolution=lowerCAmelCase_      ,      numpify=lowerCAmelCase_		)
				for image in image_inputs:
							self.assertIsInstance(lowerCAmelCase_      ,      np.ndarray		)

				# Test not batched input
				UpperCAmelCase_	:					str     	=   image_processor(image_inputs[0]      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        1,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )

				# Test batched
				UpperCAmelCase_	:					Dict     	=   image_processor(lowerCAmelCase_      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        self.image_proc_tester.batch_size,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     List[Any]:
				# Initialize image_processor
				UpperCAmelCase_	:					Optional[Any]     	=   self.image_processing_class(**self.image_processor_dict		)
				# create random PyTorch tensors
				UpperCAmelCase_	:					Dict     	=   prepare_image_inputs(self.image_proc_tester      ,      equal_resolution=lowerCAmelCase_      ,      torchify=lowerCAmelCase_		)
				for image in image_inputs:
							self.assertIsInstance(lowerCAmelCase_      ,      torch.Tensor		)

				# Test not batched input
				UpperCAmelCase_	:					Optional[int]     	=   image_processor(image_inputs[0]      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        1,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )

				# Test batched
				UpperCAmelCase_	:					Optional[int]     	=   image_processor(lowerCAmelCase_      ,      return_tensors="pt"		).pixel_values
				self.assertEqual(
				    encoded_images.shape      ,      (
				        self.image_proc_tester.batch_size,
				        self.image_proc_tester.num_channels,
				        self.image_proc_tester.size["height"],
				        self.image_proc_tester.size["width"],
				    )      ,      )



