




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  __lowerCAmelCase							:






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






       def        SCREAMING_SNAKE_CASE     ( self:       List[Any]					):
         lowercase     :Dict   						=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

         lowercase     :Tuple   						=    self.get_config()
         return config, pixel_values, labels






       def        SCREAMING_SNAKE_CASE     ( self:       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        SCREAMING_SNAKE_CASE     ( self:       Dict							,       _lowerCAmelCase:       Dict							,       _lowerCAmelCase:       Union[str, Any]							,       _lowerCAmelCase:       Union[str, Any]					):
         lowercase     :Dict   						=    EfficientNetModel(config=_lowerCAmelCase					)
         model.to(_lowerCAmelCase					)
         model.eval()
         lowercase     :int   						=    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        SCREAMING_SNAKE_CASE     ( self:       int							,       _lowerCAmelCase:       int							,       _lowerCAmelCase:       Optional[int]							,       _lowerCAmelCase:       Optional[Any]					):
         lowercase     :Union[str, Any]   						=    EfficientNetForImageClassification(_lowerCAmelCase					)
         model.to(_lowerCAmelCase					)
         model.eval()
         lowercase     :Optional[int]   						=    model(_lowerCAmelCase							,       labels=_lowerCAmelCase					)
         self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.num_labels)					)






       def        SCREAMING_SNAKE_CASE     ( self:       Optional[int]					):
         lowercase     :Optional[int]   						=    self.prepare_config_and_inputs()
         lowercase						,     lowercase						,     lowercase     :Dict   						=    config_and_inputs
         lowercase     :List[Any]   						=    {"pixel_values": pixel_values}
         return config, inputs_dict







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

       _a			       =    False
       _a			       =    False
       _a			       =    False
       _a			       =    False
       _a			       =    False






       def        SCREAMING_SNAKE_CASE     ( self:       Dict					):
         lowercase     :Optional[Any]   						=    EfficientNetModelTester(self					)
         lowercase     :Optional[int]   						=    ConfigTester(
             self							,       config_class=_lowerCAmelCase							,       has_text_modality=_lowerCAmelCase							,       hidden_size=37					)






       def        SCREAMING_SNAKE_CASE     ( self:       List[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        SCREAMING_SNAKE_CASE     ( self:       Any					):
         return






       @unittest.skip(reason="EfficientNet does not use inputs_embeds"					)
       def        SCREAMING_SNAKE_CASE     ( self:       Any					):
         pass






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






       @unittest.skip(reason="EfficientNet does not use feedforward chunking"					)
       def        SCREAMING_SNAKE_CASE     ( self:       Tuple					):
         pass






       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         lowercase						,     lowercase     :List[Any]   						=    self.model_tester.prepare_config_and_inputs_for_common()

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

           lowercase     :Union[str, Any]   						=    ["pixel_values"]
           self.assertListEqual(arg_names[:1]							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       str					):
         lowercase     :Dict   						=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       List[Any]					):
         def check_hidden_states_output(_lowerCAmelCase:       Tuple							,       _lowerCAmelCase:       List[Any]							,       _lowerCAmelCase:       Dict					):
           lowercase     :Tuple   						=    model_class(_lowerCAmelCase					)
           model.to(_lowerCAmelCase					)
           model.eval()

           with torch.no_grad():
             lowercase     :Tuple   						=    model(**self._prepare_for_class(_lowerCAmelCase							,       _lowerCAmelCase					)					)

           lowercase     :Dict   						=    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
           lowercase     :str   						=    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						,     lowercase     :Tuple   						=    self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowercase     :Union[str, Any]   						=    True
           check_hidden_states_output(_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase					)

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

           check_hidden_states_output(_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase					)






       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         lowercase     :Tuple   						=    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        SCREAMING_SNAKE_CASE     ( self:       Union[str, Any]					):
         pass






       @slow
       def        SCREAMING_SNAKE_CASE     ( self:       Optional[int]					):
         for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowercase     :Dict   						=    EfficientNetModel.from_pretrained(_lowerCAmelCase					)
           self.assertIsNotNone(_lowerCAmelCase					)






       @is_pipeline_test
       @require_vision
       @slow
       def        SCREAMING_SNAKE_CASE     ( self:       Tuple					):
         super().test_pipeline_image_classification()







def    UpperCAmelCase__	(  ):
  lowercase     :Tuple   						=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
  return image







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






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






       @slow
       def        SCREAMING_SNAKE_CASE     ( self:       Optional[Any]					):
         lowercase     :Any   						=    EfficientNetForImageClassification.from_pretrained("google/efficientnet-b7"					).to(_lowerCAmelCase					)

         lowercase     :str   						=    self.default_image_processor
         lowercase     :Any   						=    prepare_img()
         lowercase     :Any   						=    image_processor(images=_lowerCAmelCase							,       return_tensors="pt"					).to(_lowerCAmelCase					)

         # forward pass
         with torch.no_grad():
           lowercase     :str   						=    model(**_lowerCAmelCase					)

         # verify the logits
         lowercase     :Dict   						=    torch.Size((1, 10_00)					)
         self.assertEqual(outputs.logits.shape							,       _lowerCAmelCase					)

         lowercase     :List[Any]   						=    torch.tensor([0.00_01, 0.00_02, 0.00_02]					).to(_lowerCAmelCase					)
         self.assertTrue(torch.allclose(outputs.logits[0, :3]							,       _lowerCAmelCase							,       atol=1e-4					)					)










def  __UpperCamelCase   (     a = 998001)			->int:

					# fetches the next number
					for number in range(n - 1,  9999,  -1):
										lowerCamelCase__      =							str(a)

										# checks whether 'str_number' is a palindrome.
										if str_number == str_number[::-1]:
															lowerCamelCase__      =							999

															# if 'number' is a product of two 3-digit numbers
															# then number is the answer otherwise fetch next number.
															while divisor != 99:
																				if (number % divisor == 0) and (len(str(number // divisor)) == 3.0):
																									return number
																				divisor -= 1
					raise ValueError("That number is larger than our acceptable range.")


if __name__ == "__main__":
						print(f"""{solution() = }""")

