






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

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

        __UpperCAmelCase							:			int     =						self.get_config()
        return config, pixel_values, labels
      def 			UpperCAmelCase   (   self      :    Union[str, Any]      )							->   List[str]:
        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      :    List[str]	,   __lowercase      :    Optional[int]	,   __lowercase      :    List[str]	,   __lowercase      :    List[Any]      )							->   Union[str, Any]:
        __UpperCAmelCase							:			Any     =						EfficientNetModel(config=__lowercase      )
        model.to(__lowercase      )
        model.eval()
        __UpperCAmelCase							:			List[str]     =						model(__lowercase      )
        # 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      :    str	,   __lowercase      :    Union[str, Any]	,   __lowercase      :    str	,   __lowercase      :    str      )							->   List[Any]:
        __UpperCAmelCase							:			int     =						EfficientNetForImageClassification(__lowercase      )
        model.to(__lowercase      )
        model.eval()
        __UpperCAmelCase							:			Any     =						model(__lowercase	,   labels=__lowercase      )
        self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_labels)      )




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


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



      """simple docstring"""


      a						:				Any							 =			(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
      a						:				List[Any]							 =			(
          {'feature-extraction': EfficientNetModel, 'image-classification': EfficientNetForImageClassification}
          if is_torch_available()
          else {}
      )

      a						:				List[Any]							 =			False
      a						:				Tuple							 =			False
      a						:				Optional[Any]							 =			False
      a						:				Optional[int]							 =			False
      a						:				int							 =			False
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   str:
        __UpperCAmelCase							:			str     =						EfficientNetModelTester(self      )
        __UpperCAmelCase							:			int     =						ConfigTester(
            self	,   config_class=__lowercase	,   has_text_modality=__lowercase	,   hidden_size=37      )
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   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      :    str      )							->   Optional[Any]:
        return
      @unittest.skip(reason="""EfficientNet does not use inputs_embeds"""      )
      def 			UpperCAmelCase   (   self      :    Any      )							->   int:
        pass
      @unittest.skip(reason="""EfficientNet does not support input and output embeddings"""      )
      def 			UpperCAmelCase   (   self      :    Any      )							->   List[str]:
        pass
      @unittest.skip(reason="""EfficientNet does not use feedforward chunking"""      )
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   Union[str, Any]:
        pass
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   int:
        __UpperCAmelCase   ,				__UpperCAmelCase							:			Optional[Any]     =						self.model_tester.prepare_config_and_inputs_for_common()

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

          __UpperCAmelCase							:			Optional[Any]     =						["""pixel_values"""]
          self.assertListEqual(arg_names[:1]	,   __lowercase      )
      def 			UpperCAmelCase   (   self      :    Dict      )							->   Dict:
        __UpperCAmelCase							:			str     =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__lowercase      )
      def 			UpperCAmelCase   (   self      :    Optional[int]      )							->   Optional[Any]:
        def check_hidden_states_output(__lowercase      :    Optional[int]	,   __lowercase      :    Optional[Any]	,   __lowercase      :    Tuple      ):
          __UpperCAmelCase							:			List[str]     =						model_class(__lowercase      )
          model.to(__lowercase      )
          model.eval()

          with torch.no_grad():
            __UpperCAmelCase							:			Any     =						model(**self._prepare_for_class(__lowercase	,   __lowercase      )      )

          __UpperCAmelCase							:			Any     =						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
          __UpperCAmelCase							:			str     =						sum(config.num_block_repeats      ) * 4
          self.assertEqual(len(__lowercase      )	,   __lowercase      )

          # 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							:			Any     =						self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
          __UpperCAmelCase							:			Tuple     =						True
          check_hidden_states_output(__lowercase	,   __lowercase	,   __lowercase      )

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

          check_hidden_states_output(__lowercase	,   __lowercase	,   __lowercase      )
      def 			UpperCAmelCase   (   self      :    Dict      )							->   int:
        __UpperCAmelCase							:			Dict     =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*__lowercase      )
      @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""      )
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   Tuple:
        pass
      @slow
      def 			UpperCAmelCase   (   self      :    Dict      )							->   Tuple:
        for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          __UpperCAmelCase							:			str     =						EfficientNetModel.from_pretrained(__lowercase      )
          self.assertIsNotNone(__lowercase      )




      @is_pipeline_test
      @require_vision
      @slow
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Optional[Any]:
        super().test_pipeline_image_classification()






def        lowerCamelCase__   (					):
  __UpperCAmelCase							:			List[str]     =						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""	)
  return image







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



      """simple docstring"""


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




      @slow
      def 			UpperCAmelCase   (   self      :    Dict      )							->   Any:
        __UpperCAmelCase							:			Any     =						EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7"""      ).to(__lowercase      )

        __UpperCAmelCase							:			int     =						self.default_image_processor
        __UpperCAmelCase							:			Tuple     =						prepare_img()
        __UpperCAmelCase							:			Any     =						image_processor(images=__lowercase	,   return_tensors="""pt"""      ).to(__lowercase      )

        # forward pass
        with torch.no_grad():
          __UpperCAmelCase							:			List[str]     =						model(**__lowercase      )

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

        __UpperCAmelCase							:			List[Any]     =						torch.tensor([0.0_001, 0.0_002, 0.0_002]      ).to(__lowercase      )
        self.assertTrue(torch.allclose(outputs.logits[0, :3]	,   __lowercase	,   atol=1e-4      )      )










import decimal






def        lowerCamelCase__   (					):
  __UpperCAmelCase							:			str     =						0
  __UpperCAmelCase							:			Tuple     =						decimal.Context(prec=105	)
  for i in range(2						,	100	):
    __UpperCAmelCase							:			Optional[int]     =						decimal.Decimal(__lowerCamelCase	)
    __UpperCAmelCase							:			Any     =						number.sqrt(__lowerCamelCase	)
    if len(str(__lowerCamelCase	)	) > 1:
      answer += int(str(__lowerCamelCase	)[0]	)
      __UpperCAmelCase							:			Optional[Any]     =						str(__lowerCamelCase	)[2:101]
      answer += sum(int(__lowerCamelCase	) for x in sqrt_number_str	)
  return answer


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       print(f"""{solution() = }""")


