
"""simple docstring"""
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 			UpperCamelCase      (							__SCREAMING_SNAKE_CASE  ):
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Any							    = self.config_class(**self.inputs_dict				)
       self.parent.assertTrue(hasattr(snake_case__  ,     "tf_padding"				)				)
       self.parent.assertTrue(hasattr(snake_case__  ,     "depth_multiplier"				)				)
class 			UpperCamelCase      :
     def __init__(     self  ,     snake_case__  ,     snake_case__=13  ,     snake_case__=3  ,     snake_case__=32  ,     snake_case__=0.25  ,     snake_case__=8  ,     snake_case__=True  ,     snake_case__=1024  ,     snake_case__=32  ,     snake_case__="relu6"  ,     snake_case__=0.1  ,     snake_case__=0.02  ,     snake_case__=True  ,     snake_case__=True  ,     snake_case__=10  ,     snake_case__=None  ,     ):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Any							    = parent
       _SCREAMING_SNAKE_CASE   :				str							    = batch_size
       _SCREAMING_SNAKE_CASE   :				Dict							    = num_channels
       _SCREAMING_SNAKE_CASE   :				str							    = image_size
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = depth_multiplier
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = min_depth
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = tf_padding
       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = int(last_hidden_size * depth_multiplier				)
       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = output_stride
       _SCREAMING_SNAKE_CASE   :				str							    = hidden_act
       _SCREAMING_SNAKE_CASE   :				str							    = classifier_dropout_prob
       _SCREAMING_SNAKE_CASE   :				str							    = use_labels
       _SCREAMING_SNAKE_CASE   :				Tuple							    = is_training
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = num_labels
       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = initializer_range
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = scope
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				int							    = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

       _SCREAMING_SNAKE_CASE   :				List[str]							    = None
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = None
       if self.use_labels:
         _SCREAMING_SNAKE_CASE   :				Any							    = ids_tensor([self.batch_size]  ,     self.num_labels				)
         _SCREAMING_SNAKE_CASE   :				List[str]							    = ids_tensor([self.batch_size, self.image_size, self.image_size]  ,     self.num_labels				)

       _SCREAMING_SNAKE_CASE   :				int							    = self.get_config()

       return config, pixel_values, labels, pixel_labels
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """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 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Any							    = MobileNetVaModel(config=snake_case__				)
       model.to(snake_case__				)
       model.eval()
       _SCREAMING_SNAKE_CASE   :				Dict							    = model(snake_case__				)
       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 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				str							    = self.num_labels
       _SCREAMING_SNAKE_CASE   :				int							    = MobileNetVaForImageClassification(snake_case__				)
       model.to(snake_case__				)
       model.eval()
       _SCREAMING_SNAKE_CASE   :				int							    = model(snake_case__  ,     labels=snake_case__				)
       self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.num_labels)				)




     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Tuple							    = self.prepare_config_and_inputs()
       _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Optional[Any]							    = config_and_inputs
       _SCREAMING_SNAKE_CASE   :				Tuple							    = {"pixel_values": pixel_values}
       return config, inputs_dict
@require_torch
class 			UpperCamelCase      (							__SCREAMING_SNAKE_CASE      ,       __SCREAMING_SNAKE_CASE      ,       unittest.TestCase  ):
     A__      =			(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
     A__      =			(
         {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
         if is_torch_available()
         else {}
     )

     A__      =			False
     A__      =			False
     A__      =			False
     A__      =			False
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = MobileNetVaModelTester(self				)
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = MobileNetVaConfigTester(self  ,     config_class=snake_case__  ,     has_text_modality=snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       self.config_tester.run_common_tests()
     @unittest.skip(reason="MobileNetV1 does not use inputs_embeds"				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


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




       """simple docstring"""


       pass
     @unittest.skip(reason="MobileNetV1 does not output attentions"				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       pass
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Any							    = self.model_tester.prepare_config_and_inputs_for_common()

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

         _SCREAMING_SNAKE_CASE   :				List[Any]							    = ["pixel_values"]
         self.assertListEqual(arg_names[:1]  ,     snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				List[str]							    = self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       def check_hidden_states_output(snake_case__  ,     snake_case__  ,     snake_case__				):
         _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = model_class(snake_case__				)
         model.to(snake_case__				)
         model.eval()

         with torch.no_grad():
           _SCREAMING_SNAKE_CASE   :				List[str]							    = model(**self._prepare_for_class(snake_case__  ,     snake_case__				)				)

         _SCREAMING_SNAKE_CASE   :				Tuple							    = outputs.hidden_states

         _SCREAMING_SNAKE_CASE   :				Optional[int]							    = 26
         self.assertEqual(len(snake_case__				)  ,     snake_case__				)

       _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Any							    = self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         _SCREAMING_SNAKE_CASE   :				int							    = True
         check_hidden_states_output(snake_case__  ,     snake_case__  ,     snake_case__				)

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         _SCREAMING_SNAKE_CASE   :				Optional[int]							    = True

         check_hidden_states_output(snake_case__  ,     snake_case__  ,     snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Any							    = self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*snake_case__				)




     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _SCREAMING_SNAKE_CASE   :				Any							    = MobileNetVaModel.from_pretrained(snake_case__				)
         self.assertIsNotNone(snake_case__				)





def    _lowerCAmelCase    (     )  ->    Union[str, Any]:
  _SCREAMING_SNAKE_CASE   :				Optional[int]							    = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
  return image





@require_torch
@require_vision
class 			UpperCamelCase      (							unittest.TestCase  ):
     @cached_property
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


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




     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				List[Any]							    = MobileNetVaForImageClassification.from_pretrained("google/mobilenet_v1_1.0_224"				).to(snake_case__				)

       _SCREAMING_SNAKE_CASE   :				int							    = self.default_image_processor
       _SCREAMING_SNAKE_CASE   :				Dict							    = prepare_img()
       _SCREAMING_SNAKE_CASE   :				str							    = image_processor(images=snake_case__  ,     return_tensors="pt"				).to(snake_case__				)

       # forward pass
       with torch.no_grad():
         _SCREAMING_SNAKE_CASE   :				Optional[int]							    = model(**snake_case__				)

       # verify the logits
       _SCREAMING_SNAKE_CASE   :				Dict							    = torch.Size((1, 1001)				)
       self.assertEqual(outputs.logits.shape  ,     snake_case__				)

       _SCREAMING_SNAKE_CASE   :				List[Any]							    = torch.tensor([-4.1_739, -1.1_233, 3.1_205]				).to(snake_case__				)

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





"""simple docstring"""
import operator as op





def    _lowerCAmelCase    (     lowerCamelCase__							:							Tuple				)  ->    List[str]:
  _SCREAMING_SNAKE_CASE   :				Optional[int]							    = []
  _SCREAMING_SNAKE_CASE   :				str							    = lambda lowerCamelCase__,						lowerCamelCase__				: int(x / y				)  # noqa: E731 integer division operation
  _SCREAMING_SNAKE_CASE   :				Any							    = {
      "^": op.pow,
      "*": op.mul,
      "/": div,
      "+": op.add,
      "-": op.sub,
  }  # operators & their respective operation

  # print table header
  print("Symbol".center(8				),						"Action".center(1_2				),						"Stack",						sep=" | "				)
  print("-" * (3_0 + len(lowerCamelCase__				))				)

  for x in post_fix:
    if x.isdigit():  # if x in digit
      stack.append(lowerCamelCase__				)  # append x to stack
      # output in tabular format
      print(x.rjust(8				),						("push(" + x + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)
    else:
      _SCREAMING_SNAKE_CASE   :				Dict							    = stack.pop()  # pop stack
      # output in tabular format
      print("".rjust(8				),						("pop(" + b + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)

      _SCREAMING_SNAKE_CASE   :				Any							    = stack.pop()  # pop stack
      # output in tabular format
      print("".rjust(8				),						("pop(" + a + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)

      stack.append(
          str(opr[x](int(lowerCamelCase__				),						int(lowerCamelCase__				)				)				)				)  # evaluate the 2 values popped from stack & push result to stack
      # output in tabular format
      print(
          x.rjust(8				),						("push(" + a + x + b + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | ",						)

  return int(stack[0]				)


if __name__ == "__main__":
      lowercase_       :						int     					=	input('''\n\nEnter a Postfix Equation (space separated) = ''').split(''' ''')
      print('''\n\tResult = ''', solve(Postfix))



