


'''simple docstring'''

from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import TFViTForImageClassification, TFViTModel


if is_vision_available():
 from PIL import Image

 from transformers import ViTImageProcessor
class   __lowerCAmelCase						:





      '''simple docstring'''






      def __init__(self    :    Optional[Any]   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Tuple=13   ,						UpperCamelCase    :    Dict=30   ,						UpperCamelCase    :    int=2   ,						UpperCamelCase    :    Any=3   ,						UpperCamelCase    :    List[Any]=True   ,						UpperCamelCase    :    Dict=True   ,						UpperCamelCase    :    Optional[int]=32   ,						UpperCamelCase    :    Optional[int]=2   ,						UpperCamelCase    :    str=4   ,						UpperCamelCase    :    Any=37   ,						UpperCamelCase    :    Any="gelu"   ,						UpperCamelCase    :    List[Any]=0.1   ,						UpperCamelCase    :    List[Any]=0.1   ,						UpperCamelCase    :    str=10   ,						UpperCamelCase    :    Any=0.02   ,						UpperCamelCase    :    str=3   ,						UpperCamelCase    :    Optional[int]=None   ,						):

             '''simple docstring'''







             lowercase__      			= parent
             lowercase__      			= batch_size
             lowercase__      			= image_size
             lowercase__      			= patch_size
             lowercase__      			= num_channels
             lowercase__      			= is_training
             lowercase__      			= use_labels
             lowercase__      			= hidden_size
             lowercase__      			= num_hidden_layers
             lowercase__      			= num_attention_heads
             lowercase__      			= intermediate_size
             lowercase__      			= hidden_act
             lowercase__      			= hidden_dropout_prob
             lowercase__      			= attention_probs_dropout_prob
             lowercase__      			= type_sequence_label_size
             lowercase__      			= initializer_range
             lowercase__      			= scope

             # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
             lowercase__      			= (image_size // patch_size) ** 2
             lowercase__      			= num_patches + 1



      def       UpperCamelCase__		(self    :    Any ):

             '''simple docstring'''







             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.type_sequence_label_size )

             lowercase__      			= self.get_config()

             return config, pixel_values, labels



      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             return ViTConfig(
                 image_size=self.image_size   ,						patch_size=self.patch_size   ,						num_channels=self.num_channels   ,						hidden_size=self.hidden_size   ,						num_hidden_layers=self.num_hidden_layers   ,						num_attention_heads=self.num_attention_heads   ,						intermediate_size=self.intermediate_size   ,						hidden_act=self.hidden_act   ,						hidden_dropout_prob=self.hidden_dropout_prob   ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,						is_decoder=UpperCamelCase   ,						initializer_range=self.initializer_range   ,						)



      def       UpperCamelCase__		(self    :    Optional[Any]   ,						UpperCamelCase    :    List[Any]   ,						UpperCamelCase    :    Optional[Any]   ,						UpperCamelCase    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= TFViTModel(config=UpperCamelCase )
             lowercase__      			= model(UpperCamelCase   ,						training=UpperCamelCase )
             self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, self.seq_length, self.hidden_size) )

             # Test with an image with different size than the one specified in config.
             lowercase__      			= self.image_size // 2
             lowercase__      			= pixel_values[:, :, :image_size, :image_size]
             lowercase__      			= model(UpperCamelCase   ,						interpolate_pos_encoding=UpperCamelCase   ,						training=UpperCamelCase )
             lowercase__      			= (image_size // self.patch_size) ** 2 + 1
             self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, seq_length, self.hidden_size) )



      def       UpperCamelCase__		(self    :    Dict   ,						UpperCamelCase    :    List[Any]   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    Union[str, Any] ):

             '''simple docstring'''







             lowercase__      			= self.type_sequence_label_size
             lowercase__      			= TFViTForImageClassification(UpperCamelCase )
             lowercase__      			= model(UpperCamelCase   ,						labels=UpperCamelCase   ,						training=UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.type_sequence_label_size) )

             # Test with an image with different size than the one specified in config.
             lowercase__      			= self.image_size // 2
             lowercase__      			= pixel_values[:, :, :image_size, :image_size]
             lowercase__      			= model(UpperCamelCase   ,						interpolate_pos_encoding=UpperCamelCase   ,						training=UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.type_sequence_label_size) )

             # test greyscale images
             lowercase__      			= 1
             lowercase__      			= TFViTForImageClassification(UpperCamelCase )
             lowercase__      			= floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
             lowercase__      			= model(UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.type_sequence_label_size) )






      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             lowercase__      			= self.prepare_config_and_inputs()
             lowercase__			,lowercase__			,lowercase__      			= config_and_inputs
             lowercase__      			= {'''pixel_values''': pixel_values}
             return config, inputs_dict






@require_tf
class   __lowerCAmelCase						(lowercase_  ,     lowercase_  ,     unittest.TestCase     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Optional[Any]  					=							(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
      lowerCAmelCase__					:     Tuple  					=							(
          {"""feature-extraction""": TFViTModel, """image-classification""": TFViTForImageClassification}
          if is_tf_available()
          else {}
      )

      lowerCAmelCase__					:     Optional[int]  					=							False
      lowerCAmelCase__					:     Any  					=							False
      lowerCAmelCase__					:     List[str]  					=							False



      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             lowercase__      			= TFViTModelTester(self )
             lowercase__      			= ConfigTester(self   ,						config_class=UpperCamelCase   ,						has_text_modality=UpperCamelCase   ,						hidden_size=37 )



      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             self.config_tester.run_common_tests()



      @unittest.skip(reason='''ViT does not use inputs_embeds''' )
      def       UpperCamelCase__		(self    :    str ):

             '''simple docstring'''







             pass



      @unittest.skip(reason='''ViT does not use inputs_embeds''' )
      def       UpperCamelCase__		(self    :    Optional[Any] ):

             '''simple docstring'''







             pass



      def       UpperCamelCase__		(self    :    List[Any] ):

             '''simple docstring'''







             lowercase__			,lowercase__      			= self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    lowercase__      			= model_class(UpperCamelCase )
                    self.assertIsInstance(model.get_input_embeddings()   ,						(tf.keras.layers.Layer) )
                    lowercase__      			= model.get_output_embeddings()
                    self.assertTrue(x is None or isinstance(UpperCamelCase   ,						tf.keras.layers.Layer ) )



      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__			,lowercase__      			= self.model_tester.prepare_config_and_inputs_for_common()

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

                    lowercase__      			= ['''pixel_values''']
                    self.assertListEqual(arg_names[:1]   ,						UpperCamelCase )



      def       UpperCamelCase__		(self    :    List[Any] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    Union[str, Any] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*UpperCamelCase )






      @slow
      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= TFViTModel.from_pretrained('''google/vit-base-patch16-224''' )
             self.assertIsNotNone(UpperCamelCase )






def _SCREAMING_SNAKE_CASE      ()       ->       List[Any]:






       """simple docstring"""







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

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





      '''simple docstring'''






      @cached_property
      def       UpperCamelCase__		(self    :    str ):

             '''simple docstring'''







             return ViTImageProcessor.from_pretrained('''google/vit-base-patch16-224''' ) if is_vision_available() else None






      @slow
      def       UpperCamelCase__		(self    :    Union[str, Any] ):

             '''simple docstring'''







             lowercase__      			= TFViTForImageClassification.from_pretrained('''google/vit-base-patch16-224''' )

             lowercase__      			= self.default_image_processor
             lowercase__      			= prepare_img()
             lowercase__      			= image_processor(images=UpperCamelCase   ,						return_tensors='''tf''' )

             # forward pass
             lowercase__      			= model(**UpperCamelCase )

             # verify the logits
             lowercase__      			= tf.TensorShape((1, 1000) )
             self.assertEqual(outputs.logits.shape   ,						UpperCamelCase )

             lowercase__      			= tf.constant([-0.27_44, 0.82_15, -0.08_36] )

             tf.debugging.assert_near(outputs.logits[0, :3]   ,						UpperCamelCase   ,						atol=1E-4 )





'''simple docstring'''





import os
from math import logaa





def 	lowerCAmelCase_				(					snake_case_       : str = "base_exp.txt"			)    ->      int:


     '''simple docstring'''




     UpperCAmelCase_           =   0
     UpperCAmelCase_           =   0
     for i, line in enumerate(open(os.path.join(os.path.dirname(snake_case_			)					,    snake_case_			)			)			):
          UpperCAmelCase_    , UpperCAmelCase_           =   list(map(snake_case_					,    line.split(","			)			)			)
          if x * logaa(snake_case_			) > largest:
               UpperCAmelCase_           =   x * logaa(snake_case_			)
               UpperCAmelCase_           =   i + 1
     return result


if __name__ == "__main__":
    print(solution())




