



"""simple docstring"""





import inspect
import unittest

from datasets import load_dataset
from packaging import version

from transformers import BeitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import (
      MODEL_MAPPING,
      BeitForImageClassification,
      BeitForMaskedImageModeling,
      BeitForSemanticSegmentation,
      BeitModel,
  )
  from transformers.models.beit.modeling_beit import BEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  import PIL
  from PIL import Image

  from transformers import BeitImageProcessor
class    lowercase__     :



       def __init__(							self    :						Optional[int]	,       _UpperCAmelCase    :						Optional[Any]	,       _UpperCAmelCase    :						Optional[int]=100	,       _UpperCAmelCase    :						Optional[Any]=13	,       _UpperCAmelCase    :						Union[str, Any]=30	,       _UpperCAmelCase    :						List[str]=2	,       _UpperCAmelCase    :						Optional[int]=3	,       _UpperCAmelCase    :						Union[str, Any]=True	,       _UpperCAmelCase    :						Dict=True	,       _UpperCAmelCase    :						Optional[int]=32	,       _UpperCAmelCase    :						List[str]=4	,       _UpperCAmelCase    :						Optional[int]=4	,       _UpperCAmelCase    :						str=37	,       _UpperCAmelCase    :						Optional[int]="gelu"	,       _UpperCAmelCase    :						int=0.1	,       _UpperCAmelCase    :						Dict=0.1	,       _UpperCAmelCase    :						Optional[Any]=10	,       _UpperCAmelCase    :						Union[str, Any]=0.02	,       _UpperCAmelCase    :						Union[str, Any]=3	,       _UpperCAmelCase    :						List[Any]=None	,       _UpperCAmelCase    :						Optional[Any]=[0, 1, 2, 3]	,       )				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							parent
             UpperCAmelCase_    				=							100
             UpperCAmelCase_    				=							batch_size
             UpperCAmelCase_    				=							image_size
             UpperCAmelCase_    				=							patch_size
             UpperCAmelCase_    				=							num_channels
             UpperCAmelCase_    				=							is_training
             UpperCAmelCase_    				=							use_labels
             UpperCAmelCase_    				=							hidden_size
             UpperCAmelCase_    				=							num_hidden_layers
             UpperCAmelCase_    				=							num_attention_heads
             UpperCAmelCase_    				=							intermediate_size
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							hidden_dropout_prob
             UpperCAmelCase_    				=							attention_probs_dropout_prob
             UpperCAmelCase_    				=							type_sequence_label_size
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							scope
             UpperCAmelCase_    				=							out_indices
             UpperCAmelCase_    				=							num_labels

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



       def   lowercase__       (							self    :						Optional[int]					)				->		int:


             '''simple docstring'''




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

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

             UpperCAmelCase_    				=							self.get_config()

             return config, pixel_values, labels, pixel_labels



       def   lowercase__       (							self    :						Optional[int]					)				->		List[Any]:


             '''simple docstring'''




             return BeitConfig(
                 vocab_size=self.vocab_size	,       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	,       out_indices=self.out_indices	,       )



       def   lowercase__       (							self    :						Optional[int]	,       _UpperCAmelCase    :						Any	,       _UpperCAmelCase    :						Any	,       _UpperCAmelCase    :						List[Any]	,       _UpperCAmelCase    :						Dict					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitModel(config=_UpperCAmelCase					)
             model.to(_UpperCAmelCase					)
             model.eval()
             UpperCAmelCase_    				=							model(_UpperCAmelCase					)
             self.parent.assertEqual(result.last_hidden_state.shape	,       (self.batch_size, self.seq_length, self.hidden_size)					)



       def   lowercase__       (							self    :						List[Any]	,       _UpperCAmelCase    :						Tuple	,       _UpperCAmelCase    :						int	,       _UpperCAmelCase    :						Optional[int]	,       _UpperCAmelCase    :						str					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForMaskedImageModeling(config=_UpperCAmelCase					)
             model.to(_UpperCAmelCase					)
             model.eval()
             UpperCAmelCase_    				=							model(_UpperCAmelCase					)
             self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.seq_length - 1, self.vocab_size)					)



       def   lowercase__       (							self    :						Tuple	,       _UpperCAmelCase    :						List[str]	,       _UpperCAmelCase    :						Union[str, Any]	,       _UpperCAmelCase    :						Union[str, Any]	,       _UpperCAmelCase    :						List[Any]					)				->		Any:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.type_sequence_label_size
             UpperCAmelCase_    				=							BeitForImageClassification(_UpperCAmelCase					)
             model.to(_UpperCAmelCase					)
             model.eval()
             UpperCAmelCase_    				=							model(_UpperCAmelCase	,       labels=_UpperCAmelCase					)
             self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.type_sequence_label_size)					)

             # test greyscale images
             UpperCAmelCase_    				=							1
             UpperCAmelCase_    				=							BeitForImageClassification(_UpperCAmelCase					)
             model.to(_UpperCAmelCase					)
             model.eval()

             UpperCAmelCase_    				=							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
             UpperCAmelCase_    				=							model(_UpperCAmelCase	,       labels=_UpperCAmelCase					)
             self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.type_sequence_label_size)					)



       def   lowercase__       (							self    :						Dict	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						Dict	,       _UpperCAmelCase    :						List[Any]	,       _UpperCAmelCase    :						List[str]					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.num_labels
             UpperCAmelCase_    				=							BeitForSemanticSegmentation(_UpperCAmelCase					)
             model.to(_UpperCAmelCase					)
             model.eval()
             UpperCAmelCase_    				=							model(_UpperCAmelCase					)
             self.parent.assertEqual(
                 result.logits.shape	,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)					)
             UpperCAmelCase_    				=							model(_UpperCAmelCase	,       labels=_UpperCAmelCase					)
             self.parent.assertEqual(
                 result.logits.shape	,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)					)







       def   lowercase__       (							self    :						Optional[Any]					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.prepare_config_and_inputs()
             UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_    				=							config_and_inputs
             UpperCAmelCase_    				=							{"pixel_values": pixel_values}
             return config, inputs_dict



@require_torch
class    lowercase__     (					SCREAMING_SNAKE_CASE       ,      SCREAMING_SNAKE_CASE       ,      unittest.TestCase   ):
       UpperCamelCase		=  (
           (BeitModel, BeitForImageClassification, BeitForMaskedImageModeling, BeitForSemanticSegmentation)
           if is_torch_available()
           else ()
       )
       UpperCamelCase		=  (
           {
               '''feature-extraction''': BeitModel,
               '''image-classification''': BeitForImageClassification,
               '''image-segmentation''': BeitForSemanticSegmentation,
           }
           if is_torch_available()
           else {}
       )

       UpperCamelCase		=  False
       UpperCamelCase		=  False
       UpperCamelCase		=  False



       def   lowercase__       (							self    :						Optional[int]					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitModelTester(self					)
             UpperCAmelCase_    				=							ConfigTester(self	,       config_class=_UpperCAmelCase	,       has_text_modality=_UpperCAmelCase	,       hidden_size=37					)



       def   lowercase__       (							self    :						Optional[int]					)				->		Optional[Any]:


             '''simple docstring'''




             self.config_tester.run_common_tests()



       @unittest.skip(reason="BEiT does not use inputs_embeds"					)
       def   lowercase__       (							self    :						Any					)				->		List[Any]:


             '''simple docstring'''




             pass



       @require_torch_multi_gpu
       @unittest.skip(reason="BEiT has some layers using `add_module` which doesn't work well with `nn.DataParallel`"					)
       def   lowercase__       (							self    :						Dict					)				->		str:


             '''simple docstring'''




             pass



       def   lowercase__       (							self    :						Dict					)				->		Dict:


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   UpperCAmelCase_    				=							model_class(_UpperCAmelCase					)
                   self.assertIsInstance(model.get_input_embeddings()	,       (nn.Module)					)
                   UpperCAmelCase_    				=							model.get_output_embeddings()
                   self.assertTrue(x is None or isinstance(_UpperCAmelCase	,       nn.Linear					)					)



       def   lowercase__       (							self    :						Dict					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()

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

                   UpperCAmelCase_    				=							["pixel_values"]
                   self.assertListEqual(arg_names[:1]	,       _UpperCAmelCase					)



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


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*_UpperCAmelCase					)



       def   lowercase__       (							self    :						Optional[int]					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase					)



       def   lowercase__       (							self    :						Optional[int]					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_semantic_segmentation(*_UpperCAmelCase					)



       def   lowercase__       (							self    :						Optional[Any]					)				->		Optional[Any]:


             '''simple docstring'''




             if not self.model_tester.is_training:
                   return

             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()
             UpperCAmelCase_    				=							True

             for model_class in self.all_model_classes:
                   # we don't test BeitForMaskedImageModeling
                   if model_class in [*get_values(_UpperCAmelCase					), BeitForMaskedImageModeling]:
                         continue

                   UpperCAmelCase_    				=							model_class(_UpperCAmelCase					)
                   model.to(_UpperCAmelCase					)
                   model.train()
                   UpperCAmelCase_    				=							self._prepare_for_class(_UpperCAmelCase	,       _UpperCAmelCase	,       return_labels=_UpperCAmelCase					)
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					).loss
                   loss.backward()



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


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()
             if not self.model_tester.is_training:
                   return

             UpperCAmelCase_    				=							False
             UpperCAmelCase_    				=							True

             for model_class in self.all_model_classes:
                   # we don't test BeitForMaskedImageModeling
                   if (
                       model_class in [*get_values(_UpperCAmelCase					), BeitForMaskedImageModeling]
                       or not model_class.supports_gradient_checkpointing
                   ):
                         continue

                   UpperCAmelCase_    				=							model_class(_UpperCAmelCase					)
                   model.gradient_checkpointing_enable()
                   model.to(_UpperCAmelCase					)
                   model.train()
                   UpperCAmelCase_    				=							self._prepare_for_class(_UpperCAmelCase	,       _UpperCAmelCase	,       return_labels=_UpperCAmelCase					)
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					).loss
                   loss.backward()



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


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()

             UpperCAmelCase_    				=							_config_zero_init(_UpperCAmelCase					)
             for model_class in self.all_model_classes:
                   UpperCAmelCase_    				=							model_class(config=_UpperCAmelCase					)
                   for name, param in model.named_parameters():
                         # we skip lambda parameters as these require special initial values
                         # determined by config.layer_scale_init_value
                         if "lambda" in name:
                               continue
                         if param.requires_grad:
                               self.assertIn(
                                   ((param.data.mean() * 1e9).round() / 1e9).item()	,       [0.0, 1.0]	,       msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""	,       )







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


             '''simple docstring'''




             for model_name in BEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_    				=							BeitModel.from_pretrained(_UpperCAmelCase					)
                   self.assertIsNotNone(_UpperCAmelCase					)



def      a__			(   ):
      UpperCAmelCase_    				=							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
      return image


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



       @cached_property
       def   lowercase__       (							self    :						Union[str, Any]					)				->		int:


             '''simple docstring'''




             return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"					) if is_vision_available() else None



       @slow
       def   lowercase__       (							self    :						str					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"					).to(_UpperCAmelCase					)

             UpperCAmelCase_    				=							self.default_image_processor
             UpperCAmelCase_    				=							prepare_img()
             UpperCAmelCase_    				=							image_processor(images=_UpperCAmelCase	,       return_tensors="pt"					).pixel_values.to(_UpperCAmelCase					)

             # prepare bool_masked_pos
             UpperCAmelCase_    				=							torch.ones((1, 196)	,       dtype=torch.bool					).to(_UpperCAmelCase					)

             # forward pass
             with torch.no_grad():
                   UpperCAmelCase_    				=							model(pixel_values=_UpperCAmelCase	,       bool_masked_pos=_UpperCAmelCase					)
             UpperCAmelCase_    				=							outputs.logits

             # verify the logits
             UpperCAmelCase_    				=							torch.Size((1, 196, 8192)					)
             self.assertEqual(logits.shape	,       _UpperCAmelCase					)

             UpperCAmelCase_    				=							torch.tensor(
                 [[-3.2437, 0.5072, -13.9174], [-3.2456, 0.4948, -13.9401], [-3.2033, 0.5121, -13.8550]]					).to(_UpperCAmelCase					)

             self.assertTrue(torch.allclose(logits[bool_masked_pos][:3, :3]	,       _UpperCAmelCase	,       atol=1e-2					)					)



       @slow
       def   lowercase__       (							self    :						Dict					)				->		Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"					).to(_UpperCAmelCase					)

             UpperCAmelCase_    				=							self.default_image_processor
             UpperCAmelCase_    				=							prepare_img()
             UpperCAmelCase_    				=							image_processor(images=_UpperCAmelCase	,       return_tensors="pt"					).to(_UpperCAmelCase					)

             # forward pass
             with torch.no_grad():
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					)
             UpperCAmelCase_    				=							outputs.logits

             # verify the logits
             UpperCAmelCase_    				=							torch.Size((1, 1000)					)
             self.assertEqual(logits.shape	,       _UpperCAmelCase					)

             UpperCAmelCase_    				=							torch.tensor([-1.2385, -1.0987, -1.0108]					).to(_UpperCAmelCase					)

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

             UpperCAmelCase_    				=							281
             self.assertEqual(logits.argmax(-1					).item()	,       _UpperCAmelCase					)



       @slow
       def   lowercase__       (							self    :						Any					)				->		Dict:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"					).to(
                 _UpperCAmelCase					)

             UpperCAmelCase_    				=							self.default_image_processor
             UpperCAmelCase_    				=							prepare_img()
             UpperCAmelCase_    				=							image_processor(images=_UpperCAmelCase	,       return_tensors="pt"					).to(_UpperCAmelCase					)

             # forward pass
             with torch.no_grad():
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					)
             UpperCAmelCase_    				=							outputs.logits

             # verify the logits
             UpperCAmelCase_    				=							torch.Size((1, 21841)					)
             self.assertEqual(logits.shape	,       _UpperCAmelCase					)

             UpperCAmelCase_    				=							torch.tensor([1.6881, -0.2787, 0.5901]					).to(_UpperCAmelCase					)

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

             UpperCAmelCase_    				=							2396
             self.assertEqual(logits.argmax(-1					).item()	,       _UpperCAmelCase					)



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


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"					)
             UpperCAmelCase_    				=							model.to(_UpperCAmelCase					)

             UpperCAmelCase_    				=							BeitImageProcessor(do_resize=_UpperCAmelCase	,       size=640	,       do_center_crop=_UpperCAmelCase					)

             UpperCAmelCase_    				=							load_dataset("hf-internal-testing/fixtures_ade20k"	,       split="test"					)
             UpperCAmelCase_    				=							Image.open(ds[0]["file"]					)
             UpperCAmelCase_    				=							image_processor(images=_UpperCAmelCase	,       return_tensors="pt"					).to(_UpperCAmelCase					)

             # forward pass
             with torch.no_grad():
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					)
             UpperCAmelCase_    				=							outputs.logits

             # verify the logits
             UpperCAmelCase_    				=							torch.Size((1, 150, 160, 160)					)
             self.assertEqual(logits.shape	,       _UpperCAmelCase					)

             UpperCAmelCase_    				=							version.parse(PIL.__version__					) < version.parse("9.0.0"					)

             if is_pillow_less_than_a:
                   UpperCAmelCase_    				=							torch.tensor(
                       [
                           [[-4.9225, -2.3954, -3.0522], [-2.8822, -1.0046, -1.7561], [-2.9549, -1.3228, -2.1347]],
                           [[-5.8168, -3.4129, -4.0778], [-3.8651, -2.2214, -3.0277], [-3.8356, -2.4643, -3.3535]],
                           [[-0.0078, 3.9952, 4.0754], [2.9856, 4.6944, 5.0035], [3.2413, 4.7813, 4.9969]],
                       ]	,       device=_UpperCAmelCase	,       )
             else:
                   UpperCAmelCase_    				=							torch.tensor(
                       [
                           [[-4.8960, -2.3688, -3.0355], [-2.8478, -0.9836, -1.7418], [-2.9449, -1.3332, -2.1456]],
                           [[-5.8081, -3.4124, -4.1006], [-3.8561, -2.2081, -3.0323], [-3.8365, -2.4601, -3.3669]],
                           [[-0.0309, 3.9868, 4.0540], [2.9640, 4.6877, 4.9976], [3.2081, 4.7690, 4.9942]],
                       ]	,       device=_UpperCAmelCase	,       )

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







       @slow
       def   lowercase__       (							self    :						int					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"					)
             UpperCAmelCase_    				=							model.to(_UpperCAmelCase					)

             UpperCAmelCase_    				=							BeitImageProcessor(do_resize=_UpperCAmelCase	,       size=640	,       do_center_crop=_UpperCAmelCase					)

             UpperCAmelCase_    				=							load_dataset("hf-internal-testing/fixtures_ade20k"	,       split="test"					)
             UpperCAmelCase_    				=							Image.open(ds[0]["file"]					)
             UpperCAmelCase_    				=							image_processor(images=_UpperCAmelCase	,       return_tensors="pt"					).to(_UpperCAmelCase					)

             # forward pass
             with torch.no_grad():
                   UpperCAmelCase_    				=							model(**_UpperCAmelCase					)

             UpperCAmelCase_    				=							outputs.logits.detach().cpu()

             UpperCAmelCase_    				=							image_processor.post_process_semantic_segmentation(outputs=_UpperCAmelCase	,       target_sizes=[(500, 300)]					)
             UpperCAmelCase_    				=							torch.Size((500, 300)					)
             self.assertEqual(segmentation[0].shape	,       _UpperCAmelCase					)

             UpperCAmelCase_    				=							image_processor.post_process_semantic_segmentation(outputs=_UpperCAmelCase					)
             UpperCAmelCase_    				=							torch.Size((160, 160)					)
             self.assertEqual(segmentation[0].shape	,       _UpperCAmelCase					)









"""simple docstring"""





from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase      =		logging.get_logger(__name__)

lowerCamelCase      =		{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}
class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''mobilenet_v1'''



       def __init__(							self    :						Tuple	,       _UpperCAmelCase    :						int=3	,       _UpperCAmelCase    :						Union[str, Any]=224	,       _UpperCAmelCase    :						Any=1.0	,       _UpperCAmelCase    :						Any=8	,       _UpperCAmelCase    :						List[Any]="relu6"	,       _UpperCAmelCase    :						List[str]=True	,       _UpperCAmelCase    :						Dict=0.999	,       _UpperCAmelCase    :						List[Any]=0.02	,       _UpperCAmelCase    :						List[Any]=0.001	,       **_UpperCAmelCase    :						str	,       )				->		Optional[int]:


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase					)

             if depth_multiplier <= 0:
                   raise ValueError("depth_multiplier must be greater than zero."					)

             UpperCAmelCase_    				=							num_channels
             UpperCAmelCase_    				=							image_size
             UpperCAmelCase_    				=							depth_multiplier
             UpperCAmelCase_    				=							min_depth
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							tf_padding
             UpperCAmelCase_    				=							classifier_dropout_prob
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							layer_norm_eps



class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  version.parse('''1.11'''   )



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             return OrderedDict([("pixel_values", {0: "batch"})]					)



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             if self.task == "image-classification":
                   return OrderedDict([("logits", {0: "batch"})]					)
             else:
                   return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]					)







       @property
       def   lowercase__       (							self    :						Tuple					)				->		float:


             '''simple docstring'''




             return 1e-4




