

"""simple docstring"""
import collections
import inspect
import unittest

from transformers import DinatConfig
from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import DinatBackbone, DinatForImageClassification, DinatModel
 from transformers.models.dinat.modeling_dinat import DINAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor

class        _UpperCamelCase	:


  """simple docstring"""





  def __init__( self					: Union[str, Any]       ,       snake_case					: int       ,       snake_case					: str=13       ,       snake_case					: Dict=64       ,       snake_case					: int=4       ,       snake_case					: Dict=3       ,       snake_case					: Optional[Any]=16       ,       snake_case					: List[str]=[1, 2, 1]       ,       snake_case					: Optional[Any]=[2, 4, 8]       ,       snake_case					: int=3       ,       snake_case					: Any=[[3], [1, 2], [1]]       ,       snake_case					: Optional[int]=2.0       ,       snake_case					: Union[str, Any]=True       ,       snake_case					: Dict=0.0       ,       snake_case					: Optional[Any]=0.0       ,       snake_case					: Dict=0.1       ,       snake_case					: int="gelu"       ,       snake_case					: Tuple=True       ,       snake_case					: Optional[Any]=0.02       ,       snake_case					: List[Any]=1e-5       ,       snake_case					: str=True       ,       snake_case					: Optional[Any]=None       ,       snake_case					: int=True       ,       snake_case					: Union[str, Any]=10       ,       snake_case					: List[str]=["stage1", "stage2"]       ,       snake_case					: Tuple=[1, 2]       ,       )	->			Dict:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     parent
         __magic_name__			:		Tuple        =     batch_size
         __magic_name__			:		Optional[Any]        =     image_size
         __magic_name__			:		Optional[int]        =     patch_size
         __magic_name__			:		Dict        =     num_channels
         __magic_name__			:		Tuple        =     embed_dim
         __magic_name__			:		Optional[Any]        =     depths
         __magic_name__			:		Any        =     num_heads
         __magic_name__			:		Union[str, Any]        =     kernel_size
         __magic_name__			:		Optional[Any]        =     dilations
         __magic_name__			:		Tuple        =     mlp_ratio
         __magic_name__			:		Union[str, Any]        =     qkv_bias
         __magic_name__			:		str        =     hidden_dropout_prob
         __magic_name__			:		Dict        =     attention_probs_dropout_prob
         __magic_name__			:		Union[str, Any]        =     drop_path_rate
         __magic_name__			:		Any        =     hidden_act
         __magic_name__			:		Dict        =     patch_norm
         __magic_name__			:		Optional[Any]        =     layer_norm_eps
         __magic_name__			:		Optional[Any]        =     initializer_range
         __magic_name__			:		str        =     is_training
         __magic_name__			:		List[str]        =     scope
         __magic_name__			:		Optional[int]        =     use_labels
         __magic_name__			:		int        =     num_labels
         __magic_name__			:		str        =     out_features
         __magic_name__			:		Any        =     out_indices



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Dict:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

         __magic_name__			:		List[str]        =     None
         if self.use_labels:
                __magic_name__			:		Dict        =     ids_tensor([self.batch_size]       ,       self.num_labels      )

         __magic_name__			:		List[Any]        =     self.get_config()

         return config, pixel_values, labels



  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			List[Any]:


         '''simple docstring'''





         return DinatConfig(
             num_labels=self.num_labels       ,       image_size=self.image_size       ,       patch_size=self.patch_size       ,       num_channels=self.num_channels       ,       embed_dim=self.embed_dim       ,       depths=self.depths       ,       num_heads=self.num_heads       ,       kernel_size=self.kernel_size       ,       dilations=self.dilations       ,       mlp_ratio=self.mlp_ratio       ,       qkv_bias=self.qkv_bias       ,       hidden_dropout_prob=self.hidden_dropout_prob       ,       attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,       drop_path_rate=self.drop_path_rate       ,       hidden_act=self.hidden_act       ,       patch_norm=self.patch_norm       ,       layer_norm_eps=self.layer_norm_eps       ,       initializer_range=self.initializer_range       ,       out_features=self.out_features       ,       out_indices=self.out_indices       ,       )



  def 							_UpperCAmelCase      ( self					: Union[str, Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Union[str, Any]       ,       snake_case					: Union[str, Any]      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     DinatModel(config=snake_case      )
         model.to(snake_case      )
         model.eval()
         __magic_name__			:		Dict        =     model(snake_case      )

         __magic_name__			:		Any        =     (config.image_size // config.patch_size) // (2 ** (len(config.depths      ) - 1))
         __magic_name__			:		Optional[Any]        =     int(config.embed_dim * 2 ** (len(config.depths      ) - 1)      )

         self.parent.assertEqual(
             result.last_hidden_state.shape       ,       (self.batch_size, expected_height, expected_width, expected_dim)      )



  def 							_UpperCAmelCase      ( self					: str       ,       snake_case					: List[Any]       ,       snake_case					: str       ,       snake_case					: Any      )	->			Optional[int]:


         '''simple docstring'''





         __magic_name__			:		Tuple        =     DinatForImageClassification(snake_case      )
         model.to(snake_case      )
         model.eval()
         __magic_name__			:		Union[str, Any]        =     model(snake_case       ,       labels=snake_case      )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_labels)      )

         # test greyscale images
         __magic_name__			:		Optional[int]        =     1
         __magic_name__			:		Optional[Any]        =     DinatForImageClassification(snake_case      )
         model.to(snake_case      )
         model.eval()

         __magic_name__			:		Tuple        =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
         __magic_name__			:		Tuple        =     model(snake_case      )
         self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_labels)      )



  def 							_UpperCAmelCase      ( self					: List[str]       ,       snake_case					: Optional[int]       ,       snake_case					: Optional[Any]       ,       snake_case					: Any      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Tuple        =     DinatBackbone(config=snake_case      )
         model.to(snake_case      )
         model.eval()
         __magic_name__			:		Tuple        =     model(snake_case      )

         # verify hidden states
         self.parent.assertEqual(len(result.feature_maps      )       ,       len(config.out_features      )      )
         self.parent.assertListEqual(list(result.feature_maps[0].shape      )       ,       [self.batch_size, model.channels[0], 16, 16]      )

         # verify channels
         self.parent.assertEqual(len(model.channels      )       ,       len(config.out_features      )      )

         # verify backbone works with out_features=None
         __magic_name__			:		Dict        =     None
         __magic_name__			:		Optional[int]        =     DinatBackbone(config=snake_case      )
         model.to(snake_case      )
         model.eval()
         __magic_name__			:		str        =     model(snake_case      )

         # verify feature maps
         self.parent.assertEqual(len(result.feature_maps      )       ,       1      )
         self.parent.assertListEqual(list(result.feature_maps[0].shape      )       ,       [self.batch_size, model.channels[-1], 4, 4]      )

         # verify channels
         self.parent.assertEqual(len(model.channels      )       ,       1      )




  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			int:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     self.prepare_config_and_inputs()
         __magic_name__			:		Optional[int]        =     config_and_inputs
         __magic_name__			:		List[Any]        =     {'''pixel_values''': pixel_values}
         return config, inputs_dict

@require_natten
@require_torch
class        _UpperCamelCase	(						_a   ,				_a   ,				unittest.TestCase	):


  """simple docstring"""





  snake_case_        =    (
      (
          DinatModel,
          DinatForImageClassification,
          DinatBackbone,
      )
      if is_torch_available()
      else ()
  )
  snake_case_        =    (
      {"feature-extraction": DinatModel, "image-classification": DinatForImageClassification}
      if is_torch_available()
      else {}
  )
  snake_case_        =    False

  snake_case_        =    False
  snake_case_        =    False
  snake_case_        =    False
  snake_case_        =    False



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     DinatModelTester(self      )
         __magic_name__			:		Optional[int]        =     ConfigTester(self       ,       config_class=snake_case       ,       embed_dim=37      )



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


         '''simple docstring'''





         self.create_and_test_config_common_properties()
         self.config_tester.create_and_test_config_to_json_string()
         self.config_tester.create_and_test_config_to_json_file()
         self.config_tester.create_and_test_config_from_and_save_pretrained()
         self.config_tester.create_and_test_config_with_num_labels()
         self.config_tester.check_config_can_be_init_without_params()
         self.config_tester.check_config_arguments_init()



  def 							_UpperCAmelCase      ( self					: str      )	->			Tuple:


         '''simple docstring'''





         return



  def 							_UpperCAmelCase      ( self					: Dict      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case      )



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Dict:


         '''simple docstring'''





         __magic_name__			:		List[str]        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*snake_case      )



  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			str:


         '''simple docstring'''





         __magic_name__			:		Optional[Any]        =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_backbone(*snake_case      )



  @unittest.skip(reason='''Dinat does not use inputs_embeds'''      )
  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			List[Any]:


         '''simple docstring'''





         pass



  @unittest.skip(reason='''Dinat does not use feedforward chunking'''      )
  def 							_UpperCAmelCase      ( self					: List[Any]      )	->			List[Any]:


         '''simple docstring'''





         pass



  def 							_UpperCAmelCase      ( self					: int      )	->			Dict:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
                __magic_name__			:		int        =     model_class(snake_case      )
                self.assertIsInstance(model.get_input_embeddings()       ,       (nn.Module)      )
                __magic_name__			:		Optional[Any]        =     model.get_output_embeddings()
                self.assertTrue(x is None or isinstance(snake_case       ,       nn.Linear      )      )



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


         '''simple docstring'''





         __magic_name__			:		int        =     self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
                __magic_name__			:		Optional[Any]        =     model_class(snake_case      )
                __magic_name__			:		Dict        =     inspect.signature(model.forward      )
                # signature.parameters is an OrderedDict => so arg_names order is deterministic
                __magic_name__			:		List[Any]        =     [*signature.parameters.keys()]

                __magic_name__			:		Any        =     ['''pixel_values''']
                self.assertListEqual(arg_names[:1]       ,       snake_case      )



  def 							_UpperCAmelCase      ( self					: Dict      )	->			int:


         '''simple docstring'''





         self.skipTest('''Dinat\'s attention operation is handled entirely by NATTEN.'''      )



  def 							_UpperCAmelCase      ( self					: Dict       ,       snake_case					: int       ,       snake_case					: str       ,       snake_case					: Any       ,       snake_case					: str      )	->			int:


         '''simple docstring'''





         __magic_name__			:		Any        =     model_class(snake_case      )
         model.to(snake_case      )
         model.eval()

         with torch.no_grad():
                __magic_name__			:		List[str]        =     model(**self._prepare_for_class(snake_case       ,       snake_case      )      )

         __magic_name__			:		str        =     outputs.hidden_states

         __magic_name__			:		Union[str, Any]        =     getattr(
             self.model_tester       ,       '''expected_num_hidden_layers'''       ,       len(self.model_tester.depths      ) + 1      )
         self.assertEqual(len(snake_case      )       ,       snake_case      )

         # Dinat has a different seq_length
         __magic_name__			:		Optional[int]        =     (
             config.patch_size
             if isinstance(config.patch_size       ,       collections.abc.Iterable      )
             else (config.patch_size, config.patch_size)
         )

         __magic_name__			:		List[Any]        =     image_size[0] // patch_size[0]
         __magic_name__			:		Optional[int]        =     image_size[1] // patch_size[1]

         self.assertListEqual(
             list(hidden_states[0].shape[-3:]      )       ,       [height, width, self.model_tester.embed_dim]       ,       )

         if model_class.__name__ != "DinatBackbone":
                __magic_name__			:		int        =     outputs.reshaped_hidden_states
                self.assertEqual(len(snake_case      )       ,       snake_case      )

                __magic_name__			:		List[Any]        =     reshaped_hidden_states[0].shape
                __magic_name__			:		Union[str, Any]        =     (
                    reshaped_hidden_states[0].view(snake_case       ,       snake_case       ,       snake_case       ,       snake_case      ).permute(0       ,       2       ,       3       ,       1      )
                )
                self.assertListEqual(
                    list(reshaped_hidden_states.shape[-3:]      )       ,       [height, width, self.model_tester.embed_dim]       ,       )



  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		List[str]        =     self.model_tester.prepare_config_and_inputs_for_common()

         __magic_name__			:		List[Any]        =     (
             self.model_tester.image_size
             if isinstance(self.model_tester.image_size       ,       collections.abc.Iterable      )
             else (self.model_tester.image_size, self.model_tester.image_size)
         )

         for model_class in self.all_model_classes:
                __magic_name__			:		Any        =     True
                self.check_hidden_states_output(snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )

                # check that output_hidden_states also work using config
                del inputs_dict["output_hidden_states"]
                __magic_name__			:		List[str]        =     True

                self.check_hidden_states_output(snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )



  @slow
  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Optional[Any]:


         '''simple docstring'''





         for model_name in DINAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                __magic_name__			:		int        =     DinatModel.from_pretrained(snake_case      )
                self.assertIsNotNone(snake_case      )




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


         '''simple docstring'''





         __magic_name__			:		Tuple        =     self.model_tester.prepare_config_and_inputs_for_common()

         __magic_name__			:		List[Any]        =     _config_zero_init(snake_case      )
         for model_class in self.all_model_classes:
                __magic_name__			:		str        =     model_class(config=snake_case      )
                for name, param in model.named_parameters():
                       if "embeddings" not in name and param.requires_grad:
                              self.assertIn(
                                  ((param.data.mean() * 1e9).round() / 1e9).item()       ,       [0.0, 1.0]       ,       msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""       ,       )

@require_natten
@require_vision
@require_torch
class        _UpperCamelCase	(						unittest.TestCase	):


  """simple docstring"""





  @cached_property
  def 							_UpperCAmelCase      ( self					: int      )	->			Tuple:


         '''simple docstring'''





         return AutoImageProcessor.from_pretrained('''shi-labs/dinat-mini-in1k-224'''      ) if is_vision_available() else None




  @slow
  def 							_UpperCAmelCase      ( self					: int      )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		Dict        =     DinatForImageClassification.from_pretrained('''shi-labs/dinat-mini-in1k-224'''      ).to(snake_case      )
         __magic_name__			:		Optional[Any]        =     self.default_image_processor

         __magic_name__			:		Optional[Any]        =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
         __magic_name__			:		List[str]        =     image_processor(images=snake_case       ,       return_tensors='''pt'''      ).to(snake_case      )

         # forward pass
         with torch.no_grad():
                __magic_name__			:		Optional[Any]        =     model(**snake_case      )

         # verify the logits
         __magic_name__			:		int        =     torch.Size((1, 1000)      )
         self.assertEqual(outputs.logits.shape       ,       snake_case      )
         __magic_name__			:		Dict        =     torch.tensor([-0.1545, -0.7667, 0.4642]      ).to(snake_case      )
         self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,       snake_case       ,       atol=1e-4      )      )

@require_torch
@require_natten
class        _UpperCamelCase	(						unittest.TestCase   ,				_a	):


  """simple docstring"""





  snake_case_        =    (DinatBackbone,) if is_torch_available() else ()
  snake_case_        =    DinatConfig



  def 							_UpperCAmelCase      ( self					: int      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		int        =     DinatModelTester(self      )




'''simple docstring'''



import inspect
import unittest

from transformers import EfficientNetConfig
from transformers.testing_utils import is_pipeline_test, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import EfficientNetForImageClassification, EfficientNetModel
      from transformers.models.efficientnet.modeling_efficientnet import EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor



class       a							:


     """simple docstring"""






     def __init__(							self	:						int				,					snake_case	:						str				,					snake_case	:						str=13				,					snake_case	:						List[str]=32				,					snake_case	:						Tuple=3				,					snake_case	:						Dict=[3, 3, 5]				,					snake_case	:						Tuple=[32, 16, 24]				,					snake_case	:						Any=[16, 24, 40]				,					snake_case	:						Dict=[1, 1, 2]				,					snake_case	:						Optional[int]=[1, 1, 2]				,					snake_case	:						Optional[int]=[1, 6, 6]				,					snake_case	:						List[str]=True				,					snake_case	:						int=True				,					snake_case	:						Tuple=37				,					snake_case	:						List[str]="gelu"				,					snake_case	:						Optional[int]=10				,					)		->				Optional[int]:
          __UpperCAmelCase      :					Union[str, Any]    				=     parent
          __UpperCAmelCase      :					Optional[int]    				=     batch_size
          __UpperCAmelCase      :					Union[str, Any]    				=     image_size
          __UpperCAmelCase      :					List[Any]    				=     num_channels
          __UpperCAmelCase      :					str    				=     kernel_sizes
          __UpperCAmelCase      :					Union[str, Any]    				=     in_channels
          __UpperCAmelCase      :					str    				=     out_channels
          __UpperCAmelCase      :					List[str]    				=     strides
          __UpperCAmelCase      :					List[str]    				=     num_block_repeats
          __UpperCAmelCase      :					List[str]    				=     expand_ratios
          __UpperCAmelCase      :					Union[str, Any]    				=     is_training
          __UpperCAmelCase      :					Optional[int]    				=     hidden_act
          __UpperCAmelCase      :					List[Any]    				=     num_labels
          __UpperCAmelCase      :					Dict    				=     use_labels

     def 					lowerCamelCase__					(							self	:						Dict     )		->				Tuple:
          __UpperCAmelCase      :					Tuple    				=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

          __UpperCAmelCase      :					int    				=     None
          if self.use_labels:
               __UpperCAmelCase      :					Optional[Any]    				=     ids_tensor([self.batch_size]				,					self.num_labels     )

          __UpperCAmelCase      :					int    				=     self.get_config()
          return config, pixel_values, labels

     def 					lowerCamelCase__					(							self	:						str     )		->				Dict:
          return EfficientNetConfig(
              num_channels=self.num_channels				,					kernel_sizes=self.kernel_sizes				,					in_channels=self.in_channels				,					out_channels=self.out_channels				,					strides=self.strides				,					num_block_repeats=self.num_block_repeats				,					expand_ratios=self.expand_ratios				,					hidden_act=self.hidden_act				,					num_labels=self.num_labels				,					)

     def 					lowerCamelCase__					(							self	:						Any				,					snake_case	:						Tuple				,					snake_case	:						Tuple				,					snake_case	:						Optional[int]     )		->				Union[str, Any]:
          __UpperCAmelCase      :					Union[str, Any]    				=     EfficientNetModel(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case     )
          # expected last hidden states: B, C, H // 4, W // 4
          self.parent.assertEqual(
              result.last_hidden_state.shape				,					(self.batch_size, config.hidden_dim, self.image_size // 4, self.image_size // 4)				,					)

     def 					lowerCamelCase__					(							self	:						List[str]				,					snake_case	:						Optional[int]				,					snake_case	:						List[str]				,					snake_case	:						List[str]     )		->				Optional[int]:
          __UpperCAmelCase      :					List[str]    				=     EfficientNetForImageClassification(snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Any    				=     model(snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)     )






     def 					lowerCamelCase__					(							self	:						str     )		->				Tuple:
          __UpperCAmelCase      :					List[Any]    				=     self.prepare_config_and_inputs()
          __UpperCAmelCase				,  __UpperCAmelCase				,  __UpperCAmelCase      :					Union[str, Any]    				=     config_and_inputs
          __UpperCAmelCase      :					Union[str, Any]    				=     {'''pixel_values''': pixel_values}
          return config, inputs_dict



@require_torch
class       a							(						_a      ,    _a      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					str				  =  (EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
     SCREAMING_SNAKE_CASE			:					List[str]				  =  (
         {"feature-extraction": EfficientNetModel, "image-classification": EfficientNetForImageClassification}
         if is_torch_available()
         else {}
     )

     SCREAMING_SNAKE_CASE			:					Union[str, Any]				  =  False
     SCREAMING_SNAKE_CASE			:					Optional[int]				  =  False
     SCREAMING_SNAKE_CASE			:					Optional[int]				  =  False
     SCREAMING_SNAKE_CASE			:					List[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					List[str]				  =  False

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				List[str]:
          __UpperCAmelCase      :					Dict    				=     EfficientNetModelTester(self     )
          __UpperCAmelCase      :					Optional[Any]    				=     ConfigTester(
              self				,					config_class=snake_case				,					has_text_modality=snake_case				,					hidden_size=37     )

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				str:
          self.create_and_test_config_common_properties()
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()

     def 					lowerCamelCase__					(							self	:						Dict     )		->				str:
          return

     @unittest.skip(reason='''EfficientNet does not use inputs_embeds'''     )
     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				Optional[int]:
          pass

     @unittest.skip(reason='''EfficientNet does not support input and output embeddings'''     )
     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Dict:
          pass

     @unittest.skip(reason='''EfficientNet does not use feedforward chunking'''     )
     def 					lowerCamelCase__					(							self	:						Union[str, Any]     )		->				Optional[int]:
          pass

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Optional[Any]:
          __UpperCAmelCase				,  __UpperCAmelCase      :					List[str]    				=     self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __UpperCAmelCase      :					Tuple    				=     model_class(snake_case     )
               __UpperCAmelCase      :					Tuple    				=     inspect.signature(model.forward     )
               # signature.parameters is an OrderedDict => so arg_names order is deterministic
               __UpperCAmelCase      :					Optional[int]    				=     [*signature.parameters.keys()]

               __UpperCAmelCase      :					Union[str, Any]    				=     ['''pixel_values''']
               self.assertListEqual(arg_names[:1]				,					snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				List[str]:
          __UpperCAmelCase      :					Union[str, Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				str:
          def check_hidden_states_output(snake_case	:						Union[str, Any]				,					snake_case	:						str				,					snake_case	:						Tuple     ):
               __UpperCAmelCase      :					List[str]    				=     model_class(snake_case     )
               model.to(snake_case     )
               model.eval()

               with torch.no_grad():
                    __UpperCAmelCase      :					int    				=     model(**self._prepare_for_class(snake_case				,					snake_case     )     )

               __UpperCAmelCase      :					Optional[int]    				=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
               __UpperCAmelCase      :					List[str]    				=     sum(config.num_block_repeats     ) * 4
               self.assertEqual(len(snake_case     )				,					snake_case     )

               # EfficientNet's feature maps are of shape (batch_size, num_channels, height, width)
               self.assertListEqual(
                   list(hidden_states[0].shape[-2:]     )				,					[self.model_tester.image_size // 2, self.model_tester.image_size // 2]				,					)

          __UpperCAmelCase				,  __UpperCAmelCase      :					Union[str, Any]    				=     self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __UpperCAmelCase      :					int    				=     True
               check_hidden_states_output(snake_case				,					snake_case				,					snake_case     )

               # check that output_hidden_states also work using config
               del inputs_dict["output_hidden_states"]
               __UpperCAmelCase      :					Union[str, Any]    				=     True

               check_hidden_states_output(snake_case				,					snake_case				,					snake_case     )

     def 					lowerCamelCase__					(							self	:						str     )		->				Any:
          __UpperCAmelCase      :					Any    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*snake_case     )

     @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''     )
     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				Tuple:
          pass

     @slow
     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				List[str]:
          for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase      :					str    				=     EfficientNetModel.from_pretrained(snake_case     )
               self.assertIsNotNone(snake_case     )






     @is_pipeline_test
     @require_vision
     @slow
     def 					lowerCamelCase__					(							self	:						Union[str, Any]     )		->				List[str]:
          super().test_pipeline_image_classification()




def       _a      (		):





     '''simple docstring'''






     __UpperCAmelCase      :					Any    				=     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''    )
     return image



@require_torch
@require_vision
class       a							(						unittest.TestCase			):


     """simple docstring"""






     @cached_property
     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Dict:
          return AutoImageProcessor.from_pretrained('''google/efficientnet-b7'''     ) if is_vision_available() else None






     @slow
     def 					lowerCamelCase__					(							self	:						str     )		->				Any:
          __UpperCAmelCase      :					Tuple    				=     EfficientNetForImageClassification.from_pretrained('''google/efficientnet-b7'''     ).to(snake_case     )

          __UpperCAmelCase      :					List[str]    				=     self.default_image_processor
          __UpperCAmelCase      :					List[Any]    				=     prepare_img()
          __UpperCAmelCase      :					Union[str, Any]    				=     image_processor(images=snake_case				,					return_tensors='''pt'''     ).to(snake_case     )

          # forward pass
          with torch.no_grad():
               __UpperCAmelCase      :					Optional[Any]    				=     model(**snake_case     )

          # verify the logits
          __UpperCAmelCase      :					Any    				=     torch.Size((1, 1000)     )
          self.assertEqual(outputs.logits.shape				,					snake_case     )

          __UpperCAmelCase      :					Dict    				=     torch.tensor([0.0_001, 0.0_002, 0.0_002]     ).to(snake_case     )
          self.assertTrue(torch.allclose(outputs.logits[0, :3]				,					snake_case				,					atol=1E-4     )     )