



import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import 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 MobileNetVaForImageClassification, MobileNetVaModel
    from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import MobileNetVaImageProcessor



class 		_snake_case   (      lowerCamelCase					):





 """simple docstring"""



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




   """simple docstring"""







   _A							     =     self.config_class(**self.inputs_dict       )
   self.parent.assertTrue(hasattr(A_						,     '''tf_padding'''       )       )
   self.parent.assertTrue(hasattr(A_						,     '''depth_multiplier'''       )       )







class 		_snake_case   :





 """simple docstring"""



 def __init__(    self						,     a						,     a=1_3						,     a=3						,     a=3_2						,     a=0.25						,     a=8						,     a=True						,     a=1_0_2_4						,     a=3_2						,     a="relu6"						,     a=0.1						,     a=0.02						,     a=True						,     a=True						,     a=1_0						,     a=None						,     )						->				Any:




   """simple docstring"""







   _A							     =     parent
   _A							     =     batch_size
   _A							     =     num_channels
   _A							     =     image_size
   _A							     =     depth_multiplier
   _A							     =     min_depth
   _A							     =     tf_padding
   _A							     =     int(last_hidden_size * depth_multiplier       )
   _A							     =     output_stride
   _A							     =     hidden_act
   _A							     =     classifier_dropout_prob
   _A							     =     use_labels
   _A							     =     is_training
   _A							     =     num_labels
   _A							     =     initializer_range
   _A							     =     scope
 def lowercase_		(    self       )						->				Optional[Any]:




   """simple docstring"""







   _A							     =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

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

   _A							     =     self.get_config()

   return config, pixel_values, labels, pixel_labels
 def lowercase_		(    self       )						->				str:




   """simple docstring"""







   return MobileNetVaConfig(
       num_channels=self.num_channels						,     image_size=self.image_size						,     depth_multiplier=self.depth_multiplier						,     min_depth=self.min_depth						,     tf_padding=self.tf_padding						,     hidden_act=self.hidden_act						,     classifier_dropout_prob=self.classifier_dropout_prob						,     initializer_range=self.initializer_range						,     )
 def lowercase_		(    self						,     a						,     a						,     a						,     a       )						->				Optional[Any]:




   """simple docstring"""







   _A							     =     MobileNetVaModel(config=A_       )
   model.to(A_       )
   model.eval()
   _A							     =     model(A_       )
   self.parent.assertEqual(
       result.last_hidden_state.shape						,     (
           self.batch_size,
           self.last_hidden_size,
           self.image_size // self.output_stride,
           self.image_size // self.output_stride,
       )						,     )
 def lowercase_		(    self						,     a						,     a						,     a						,     a       )						->				int:




   """simple docstring"""







   _A							     =     self.num_labels
   _A							     =     MobileNetVaForImageClassification(A_       )
   model.to(A_       )
   model.eval()
   _A							     =     model(A_						,     labels=A_       )
   self.parent.assertEqual(result.logits.shape						,     (self.batch_size, self.num_labels)       )



 def lowercase_		(    self       )						->				List[Any]:




   """simple docstring"""







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







@require_torch
class 		_snake_case   (      lowerCamelCase       ,lowerCamelCase       ,unittest.TestCase					):





 """simple docstring"""



 lowerCamelCase_        =      (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
 lowerCamelCase_        =      (
     {'''feature-extraction''': MobileNetVaModel, '''image-classification''': MobileNetVaForImageClassification}
     if is_torch_available()
     else {}
 )

 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 lowerCamelCase_        =      False
 def lowercase_		(    self       )						->				Any:




   """simple docstring"""







   _A							     =     MobileNetVaModelTester(self       )
   _A							     =     MobileNetVaConfigTester(self						,     config_class=A_						,     has_text_modality=A_       )
 def lowercase_		(    self       )						->				List[str]:




   """simple docstring"""







   self.config_tester.run_common_tests()
 @unittest.skip(reason='''MobileNetV1 does not use inputs_embeds'''       )
 def lowercase_		(    self       )						->				str:




   """simple docstring"""







   pass
 @unittest.skip(reason='''MobileNetV1 does not support input and output embeddings'''       )
 def lowercase_		(    self       )						->				Optional[int]:




   """simple docstring"""







   pass
 @unittest.skip(reason='''MobileNetV1 does not output attentions'''       )
 def lowercase_		(    self       )						->				Optional[int]:




   """simple docstring"""







   pass
 def lowercase_		(    self       )						->				int:




   """simple docstring"""







   _A     , _A							     =     self.model_tester.prepare_config_and_inputs_for_common()

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

     _A							     =     ['''pixel_values''']
     self.assertListEqual(arg_names[:1]						,     A_       )
 def lowercase_		(    self       )						->				List[Any]:




   """simple docstring"""







   _A							     =     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*A_       )
 def lowercase_		(    self       )						->				str:




   """simple docstring"""







   def check_hidden_states_output(a						,     a						,     a       ):
     _A							     =     model_class(A_       )
     model.to(A_       )
     model.eval()

     with torch.no_grad():
       _A							     =     model(**self._prepare_for_class(A_						,     A_       )       )

     _A							     =     outputs.hidden_states

     _A							     =     2_6
     self.assertEqual(len(A_       )						,     A_       )

   _A     , _A							     =     self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     _A							     =     True
     check_hidden_states_output(A_						,     A_						,     A_       )

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

     check_hidden_states_output(A_						,     A_						,     A_       )
 def lowercase_		(    self       )						->				Any:




   """simple docstring"""







   _A							     =     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_image_classification(*A_       )



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




   """simple docstring"""







   for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     _A							     =     MobileNetVaModel.from_pretrained(A_       )
     self.assertIsNotNone(A_       )







def      UpperCAmelCase__			(				) ->			Optional[Any]:
  _A							     =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
  return image



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





 """simple docstring"""



 @cached_property
 def lowercase_		(    self       )						->				Dict:




   """simple docstring"""







   return (
       MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v1_1.0_224'''       ) if is_vision_available() else None
   )



 @slow
 def lowercase_		(    self       )						->				Any:




   """simple docstring"""







   _A							     =     MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v1_1.0_224'''       ).to(A_       )

   _A							     =     self.default_image_processor
   _A							     =     prepare_img()
   _A							     =     image_processor(images=A_						,     return_tensors='''pt'''       ).to(A_       )

   # forward pass
   with torch.no_grad():
     _A							     =     model(**A_       )

   # verify the logits
   _A							     =     torch.Size((1, 1_0_0_1)       )
   self.assertEqual(outputs.logits.shape						,     A_       )

   _A							     =     torch.tensor([-4.1_739, -1.1_233, 3.1_205]       ).to(A_       )

   self.assertTrue(torch.allclose(outputs.logits[0, :3]						,     A_						,     atol=1e-4       )       )






from math import factorial






def 				_UpperCAmelCase			(    A = 20     ):




   '''simple docstring'''

   UpperCAmelCase__						=2 * n  # middle entry of odd rows starting at row 3 is the solution for n = 1,
   # 2, 3,...
   UpperCAmelCase__						=n // 2

   return int(factorial(A     ) / (factorial(A     ) * factorial(n - k     ))     )


if __name__ == "__main__":
    import sys

    if len(sys.argv) == 1:
        print(solution(20))
    else:
        try:
            UpperCamelCase_												=	int(sys.argv[1])
            print(solution(n))
        except ValueError:
            print('Invalid entry - please enter a number.')



