'''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 				lowercase    :


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


   def __UpperCAmelCase							( self					:						Any)   ->       Optional[Any]:
         lowercase_     			=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

         lowercase_     			=   None
         if self.use_labels:
               lowercase_     			=   ids_tensor([self.batch_size] ,		self.num_labels)

         lowercase_     			=   self.get_config()
         return config, pixel_values, labels


   def __UpperCAmelCase							( self					:						Optional[Any])   ->       Any:
         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 __UpperCAmelCase							( self					:						Any ,		__lowerCAmelCase					:						Dict ,		__lowerCAmelCase					:						Any ,		__lowerCAmelCase					:						Tuple)   ->       int:
         lowercase_     			=   EfficientNetModel(config=lowerCAmelCase__)
         model.to(lowerCAmelCase__)
         model.eval()
         lowercase_     			=   model(lowerCAmelCase__)
         # 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 __UpperCAmelCase							( self					:						Dict ,		__lowerCAmelCase					:						Optional[Any] ,		__lowerCAmelCase					:						List[str] ,		__lowerCAmelCase					:						int)   ->       Any:
         lowercase_     			=   EfficientNetForImageClassification(lowerCAmelCase__)
         model.to(lowerCAmelCase__)
         model.eval()
         lowercase_     			=   model(lowerCAmelCase__ ,		labels=lowerCAmelCase__)
         self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_labels))


   def __UpperCAmelCase							( self					:						Optional[int])   ->       Optional[Any]:
         lowercase_     			=   self.prepare_config_and_inputs()
         lowercase_     			=   config_and_inputs
         lowercase_     			=   {"""pixel_values""": pixel_values}
         return config, inputs_dict





@require_torch
class 				lowercase    (    __snake_case			,					__snake_case			,					unittest.TestCase			):
   lowerCamelCase_            =(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
   lowerCamelCase_            =(
       {'feature-extraction': EfficientNetModel, 'image-classification': EfficientNetForImageClassification}
       if is_torch_available()
       else {}
   )

   lowerCamelCase_            =False
   lowerCamelCase_            =False
   lowerCamelCase_            =False
   lowerCamelCase_            =False
   lowerCamelCase_            =False


   def __UpperCAmelCase							( self					:						Union[str, Any])   ->       Union[str, Any]:
         lowercase_     			=   EfficientNetModelTester(self)
         lowercase_     			=   ConfigTester(
             self ,		config_class=lowerCAmelCase__ ,		has_text_modality=lowerCAmelCase__ ,		hidden_size=37)


   def __UpperCAmelCase							( self					:						Union[str, Any])   ->       Optional[Any]:
         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					:						List[str])   ->       Tuple:
         return


   @unittest.skip(reason="EfficientNet does not use inputs_embeds")
   def __UpperCAmelCase							( self					:						List[str])   ->       List[Any]:
         pass


   @unittest.skip(reason="EfficientNet does not support input and output embeddings")
   def __UpperCAmelCase							( self					:						Dict)   ->       str:
         pass


   @unittest.skip(reason="EfficientNet does not use feedforward chunking")
   def __UpperCAmelCase							( self					:						List[str])   ->       List[Any]:
         pass


   def __UpperCAmelCase							( self					:						str)   ->       Dict:
         lowercase_     			=   self.model_tester.prepare_config_and_inputs_for_common()

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

               lowercase_     			=   ["""pixel_values"""]
               self.assertListEqual(arg_names[:1] ,		lowerCAmelCase__)


   def __UpperCAmelCase							( self					:						Optional[Any])   ->       Optional[int]:
         lowercase_     			=   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*lowerCAmelCase__)


   def __UpperCAmelCase							( self					:						Any)   ->       Tuple:





         def check_hidden_states_output(__lowerCAmelCase					:						Union[str, Any] ,		__lowerCAmelCase					:						List[Any] ,		__lowerCAmelCase					:						List[Any]):
               lowercase_     			=   model_class(lowerCAmelCase__)
               model.to(lowerCAmelCase__)
               model.eval()

               with torch.no_grad():
                     lowercase_     			=   model(**self._prepare_for_class(lowerCAmelCase__ ,		lowerCAmelCase__))

               lowercase_     			=   outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
               lowercase_     			=   sum(config.num_block_repeats) * 4
               self.assertEqual(len(lowerCAmelCase__) ,		lowerCAmelCase__)

               # 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] ,		)

         lowercase_     			=   self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
               lowercase_     			=   True
               check_hidden_states_output(lowerCAmelCase__ ,		lowerCAmelCase__ ,		lowerCAmelCase__)

               # check that output_hidden_states also work using config
               del inputs_dict["output_hidden_states"]
               lowercase_     			=   True

               check_hidden_states_output(lowerCAmelCase__ ,		lowerCAmelCase__ ,		lowerCAmelCase__)


   def __UpperCAmelCase							( self					:						str)   ->       List[Any]:
         lowercase_     			=   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__)


   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests.")
   def __UpperCAmelCase							( self					:						Tuple)   ->       Tuple:
         pass


   @slow
   def __UpperCAmelCase							( self					:						str)   ->       List[Any]:





         for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase_     			=   EfficientNetModel.from_pretrained(lowerCAmelCase__)
               self.assertIsNotNone(lowerCAmelCase__)


   @is_pipeline_test
   @require_vision
   @slow
   def __UpperCAmelCase							( self					:						Dict)   ->       Optional[int]:
         super().test_pipeline_image_classification()




def __a			(						)						->				List[str]:
      '''simple docstring'''


      lowercase_     			=   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					)
      return image






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


   @cached_property
   def __UpperCAmelCase							( self					:						Dict)   ->       Optional[Any]:
         return AutoImageProcessor.from_pretrained("google/efficientnet-b7") if is_vision_available() else None


   @slow
   def __UpperCAmelCase							( self					:						Tuple)   ->       int:
         lowercase_     			=   EfficientNetForImageClassification.from_pretrained("google/efficientnet-b7").to(lowerCAmelCase__)

         lowercase_     			=   self.default_image_processor
         lowercase_     			=   prepare_img()
         lowercase_     			=   image_processor(images=lowerCAmelCase__ ,		return_tensors="pt").to(lowerCAmelCase__)

         # forward pass
         with torch.no_grad():
               lowercase_     			=   model(**lowerCAmelCase__)

         # verify the logits
         lowercase_     			=   torch.Size((1, 1000))
         self.assertEqual(outputs.logits.shape ,		lowerCAmelCase__)

         lowercase_     			=   torch.tensor([0.0001, 0.0002, 0.0002]).to(lowerCAmelCase__)
         self.assertTrue(torch.allclose(outputs.logits[0, :3] ,		lowerCAmelCase__ ,		atol=1e-4))







'''simple docstring'''

import numpy as np

_lowerCamelCase :				int														= [
    ["""a""", """b""", """c""", """d""", """e"""],
    ["""f""", """g""", """h""", """i""", """k"""],
    ["""l""", """m""", """n""", """o""", """p"""],
    ["""q""", """r""", """s""", """t""", """u"""],
    ["""v""", """w""", """x""", """y""", """z"""],
]




class    lowerCamelCase__  :



   def __init__(    self     )				->     None:
        """simple docstring"""





        _UpperCamelCase  :Any       =np.array(lowerCAmelCase__     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     np.ndarray:
        """simple docstring"""





        _UpperCamelCase       ,      _UpperCamelCase  :str       =np.where(letter == self.SQUARE     )
        _UpperCamelCase  :Union[str, Any]       =np.concatenate([indexa + 1, indexa + 1]     )
        return indexes



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        return self.SQUARE[indexa - 1, indexa - 1]



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :str       =message.lower()
        _UpperCamelCase  :List[Any]       =message.replace("""j"""					,      """i"""     )

        _UpperCamelCase  :List[str]       =""""""
        for letter_index in range(len(lowerCAmelCase__     )     ):
             if message[letter_index] != " ":
                  _UpperCamelCase  :Dict       =self.letter_to_numbers(message[letter_index]     )
                  _UpperCamelCase  :List[Any]       =encoded_message + str(numbers[0]     ) + str(numbers[1]     )
             elif message[letter_index] == " ":
                  _UpperCamelCase  :List[Any]       =encoded_message + """ """

        return encoded_message




   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =message.replace(""" """					,      """  """     )
        _UpperCamelCase  :Dict       =""""""
        for numbers_index in range(int(len(lowerCAmelCase__     ) / 2     )     ):
             if message[numbers_index * 2] != " ":
                  _UpperCamelCase  :Tuple       =message[numbers_index * 2]
                  _UpperCamelCase  :List[str]       =message[numbers_index * 2 + 1]

                  _UpperCamelCase  :Dict       =self.numbers_to_letter(int(lowerCAmelCase__     )					,      int(lowerCAmelCase__     )     )
                  _UpperCamelCase  :Union[str, Any]       =decoded_message + letter
             elif message[numbers_index * 2] == " ":
                  _UpperCamelCase  :Dict       =decoded_message + """ """

        return decoded_message