






import collections
import inspect
import unittest
from typing import Dict, List, Tuple

from transformers import MaskFormerSwinConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, torch_device
from transformers.utils import is_torch_available

from ...test_backbone_common import BackboneTesterMixin
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 torch import nn

	from transformers import MaskFormerSwinBackbone
	from transformers.models.maskformer import MaskFormerSwinModel

class 		lowerCAmelCase     :

					'''simple docstring'''

					def __init__(  self				:	int		,     __a				:	Dict		,     __a				:	Union[str, Any]=13		,     __a				:	str=32		,     __a				:	int=2		,     __a				:	List[str]=3		,     __a				:	Optional[int]=16		,     __a				:	List[Any]=[1, 2, 1]		,     __a				:	Optional[Any]=[2, 2, 4]		,     __a				:	Any=2		,     __a				:	Dict=2.0		,     __a				:	Any=True		,     __a				:	Optional[int]=0.0		,     __a				:	Union[str, Any]=0.0		,     __a				:	Union[str, Any]=0.1		,     __a				:	Optional[Any]="gelu"		,     __a				:	int=False		,     __a				:	str=True		,     __a				:	Union[str, Any]=0.02		,     __a				:	Tuple=1E-5		,     __a				:	str=True		,     __a				:	Optional[Any]=None		,     __a				:	Optional[Any]=True		,     __a				:	Optional[int]=10		,     __a				:	Optional[int]=8		,     __a				:	List[Any]=["stage1", "stage2", "stage3"]		,     __a				:	List[str]=[1, 2, 3]		,     )			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							Optional[int]				=     parent
												__lowercase      :							List[str]				=     batch_size
												__lowercase      :							Tuple				=     image_size
												__lowercase      :							Any				=     patch_size
												__lowercase      :							Dict				=     num_channels
												__lowercase      :							int				=     embed_dim
												__lowercase      :							Dict				=     depths
												__lowercase      :							Optional[Any]				=     num_heads
												__lowercase      :							Union[str, Any]				=     window_size
												__lowercase      :							Dict				=     mlp_ratio
												__lowercase      :							List[Any]				=     qkv_bias
												__lowercase      :							str				=     hidden_dropout_prob
												__lowercase      :							Tuple				=     attention_probs_dropout_prob
												__lowercase      :							Tuple				=     drop_path_rate
												__lowercase      :							Dict				=     hidden_act
												__lowercase      :							Union[str, Any]				=     use_absolute_embeddings
												__lowercase      :							Any				=     patch_norm
												__lowercase      :							Optional[int]				=     layer_norm_eps
												__lowercase      :							Dict				=     initializer_range
												__lowercase      :							Any				=     is_training
												__lowercase      :							List[str]				=     scope
												__lowercase      :							int				=     use_labels
												__lowercase      :							List[Any]				=     type_sequence_label_size
												__lowercase      :							List[Any]				=     encoder_stride
												__lowercase      :							Any				=     out_features
												__lowercase      :							List[str]				=     out_indices



					def       lowerCAmelCase				(  self				:	str							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							List[str]				=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

												__lowercase      :							Any				=     None
												if self.use_labels:
																			__lowercase      :							int				=     ids_tensor([self.batch_size]		,     self.type_sequence_label_size							)

												__lowercase      :							Dict				=     self.get_config()

												return config, pixel_values, labels



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


												"""simple docstring"""

												return MaskFormerSwinConfig(
												    image_size=self.image_size		,     patch_size=self.patch_size		,     num_channels=self.num_channels		,     embed_dim=self.embed_dim		,     depths=self.depths		,     num_heads=self.num_heads		,     window_size=self.window_size		,     mlp_ratio=self.mlp_ratio		,     qkv_bias=self.qkv_bias		,     hidden_dropout_prob=self.hidden_dropout_prob		,     attention_probs_dropout_prob=self.attention_probs_dropout_prob		,     drop_path_rate=self.drop_path_rate		,     hidden_act=self.hidden_act		,     use_absolute_embeddings=self.use_absolute_embeddings		,     path_norm=self.patch_norm		,     layer_norm_eps=self.layer_norm_eps		,     initializer_range=self.initializer_range		,     encoder_stride=self.encoder_stride		,     out_features=self.out_features		,     out_indices=self.out_indices		,     )



					def       lowerCAmelCase				(  self				:	int		,     __a				:	str		,     __a				:	Tuple		,     __a				:	str							)			->  Dict:


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     MaskFormerSwinModel(config=__a							)
												model.to(__a							)
												model.eval()
												__lowercase      :							Tuple				=     model(__a							)

												__lowercase      :							List[Any]				=     ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths							) - 1))
												__lowercase      :							Optional[int]				=     int(config.embed_dim * 2 ** (len(config.depths							) - 1)							)

												self.parent.assertEqual(result.last_hidden_state.shape		,     (self.batch_size, expected_seq_len, expected_dim)							)



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


												"""simple docstring"""

												__lowercase      :							Tuple				=     MaskFormerSwinBackbone(config=__a							)
												model.to(__a							)
												model.eval()
												__lowercase      :							List[Any]				=     model(__a							)

												# verify feature maps
												self.parent.assertEqual(len(result.feature_maps							)		,     len(config.out_features							)							)
												self.parent.assertListEqual(list(result.feature_maps[0].shape							)		,     [13, 16, 16, 16]							)

												# verify channels
												self.parent.assertEqual(len(model.channels							)		,     len(config.out_features							)							)
												self.parent.assertListEqual(model.channels		,     [16, 32, 64]							)

												# verify ValueError
												with self.parent.assertRaises(__a							):
																			__lowercase      :							Optional[int]				=     ["""stem"""]
																			__lowercase      :							int				=     MaskFormerSwinBackbone(config=__a							)



					def       lowerCAmelCase				(  self				:	str							)			->  int:


												"""simple docstring"""

												__lowercase      :							Tuple				=     self.prepare_config_and_inputs()
												__lowercase      :							int				=     config_and_inputs
												__lowercase      :							List[Any]				=     {"""pixel_values""": pixel_values}
												return config, inputs_dict







@require_torch
class 		lowerCAmelCase     ( __a      ,       __a      ,       unittest.TestCase			):

					'''simple docstring'''

					_A						:			Tuple									=      (
					    (
					        MaskFormerSwinModel,
					        MaskFormerSwinBackbone,
					    )
					    if is_torch_available()
					    else ()
					)
					_A						:			int									=      {'''feature-extraction''': MaskFormerSwinModel} if is_torch_available() else {}
					_A						:			int									=      False
					_A						:			int									=      False
					_A						:			int									=      False
					_A						:			Tuple									=      False
					_A						:			Optional[int]									=      False



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


												"""simple docstring"""

												__lowercase      :							List[str]				=     MaskFormerSwinModelTester(self							)
												__lowercase      :							Union[str, Any]				=     ConfigTester(self		,     config_class=__a		,     embed_dim=37							)



					@require_torch_multi_gpu
					@unittest.skip(
					    reason=(
					        """`MaskFormerSwinModel` outputs `hidden_states_spatial_dimensions` which doesn't work well with"""
					        """ `nn.DataParallel`"""
					    )							)
					def       lowerCAmelCase				(  self				:	str							)			->  Optional[int]:


												"""simple docstring"""

												pass



					def       lowerCAmelCase				(  self				:	Optional[int]							)			->  Dict:


												"""simple docstring"""

												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       lowerCAmelCase				(  self				:	List[str]							)			->  Tuple:


												"""simple docstring"""

												return



					def       lowerCAmelCase				(  self				:	Dict							)			->  int:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__a							)



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


												"""simple docstring"""

												__lowercase      :							str				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_backbone(*__a							)



					@unittest.skip("""Swin does not use inputs_embeds"""							)
					def       lowerCAmelCase				(  self				:	Optional[Any]							)			->  Tuple:


												"""simple docstring"""

												pass



					@unittest.skip("""Swin does not support feedforward chunking"""							)
					def       lowerCAmelCase				(  self				:	Union[str, Any]							)			->  Union[str, Any]:


												"""simple docstring"""

												pass



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


												"""simple docstring"""

												__lowercase      :							str				=     self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			__lowercase      :							Optional[Any]				=     model_class(__a							)
																			self.assertIsInstance(model.get_input_embeddings()		,     (nn.Module)							)
																			__lowercase      :							List[Any]				=     model.get_output_embeddings()
																			self.assertTrue(x is None or isinstance(__a		,     nn.Linear							)							)



					def       lowerCAmelCase				(  self				:	Any							)			->  Tuple:


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     self.model_tester.prepare_config_and_inputs_for_common()

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

																			__lowercase      :							List[str]				=     ["""pixel_values"""]
																			self.assertListEqual(arg_names[:1]		,     __a							)



					@unittest.skip(reason="""MaskFormerSwin is only used as backbone and doesn't support output_attentions"""							)
					def       lowerCAmelCase				(  self				:	Optional[int]							)			->  int:


												"""simple docstring"""

												pass



					@unittest.skip(reason="""MaskFormerSwin is only used as an internal backbone"""							)
					def       lowerCAmelCase				(  self				:	Any							)			->  str:


												"""simple docstring"""

												pass



					def       lowerCAmelCase				(  self				:	Tuple		,     __a				:	Any		,     __a				:	Any		,     __a				:	List[Any]		,     __a				:	Union[str, Any]							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							Tuple				=     model_class(__a							)
												model.to(__a							)
												model.eval()

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

												__lowercase      :							List[Any]				=     outputs.hidden_states

												__lowercase      :							Tuple				=     getattr(
												    self.model_tester		,     """expected_num_hidden_layers"""		,     len(self.model_tester.depths							) + 1							)
												self.assertEqual(len(__a							)		,     __a							)

												# Swin has a different seq_length
												__lowercase      :							Any				=     (
												    config.patch_size
												    if isinstance(config.patch_size		,     collections.abc.Iterable							)
												    else (config.patch_size, config.patch_size)
												)

												__lowercase      :							Optional[int]				=     (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

												self.assertListEqual(
												    list(hidden_states[0].shape[-2:]							)		,     [num_patches, self.model_tester.embed_dim]		,     )



					def       lowerCAmelCase				(  self				:	Dict							)			->  str:


												"""simple docstring"""

												__lowercase      :							Tuple				=     self.model_tester.prepare_config_and_inputs_for_common()

												__lowercase      :							Union[str, Any]				=     (
												    self.model_tester.image_size
												    if isinstance(self.model_tester.image_size		,     collections.abc.Iterable							)
												    else (self.model_tester.image_size, self.model_tester.image_size)
												)

												for model_class in self.all_model_classes:
																			__lowercase      :							Optional[int]				=     True
																			self.check_hidden_states_output(__a		,     __a		,     __a		,     __a							)

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

																			self.check_hidden_states_output(__a		,     __a		,     __a		,     __a							)



					def       lowerCAmelCase				(  self				:	Tuple							)			->  List[str]:


												"""simple docstring"""

												__lowercase      :							Dict				=     self.model_tester.prepare_config_and_inputs_for_common()
												__lowercase      :							Tuple				=     3

												__lowercase      :							Tuple				=     (
												    self.model_tester.image_size
												    if isinstance(self.model_tester.image_size		,     collections.abc.Iterable							)
												    else (self.model_tester.image_size, self.model_tester.image_size)
												)
												__lowercase      :							Tuple				=     (
												    config.patch_size
												    if isinstance(config.patch_size		,     collections.abc.Iterable							)
												    else (config.patch_size, config.patch_size)
												)

												__lowercase      :							Tuple				=     image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
												__lowercase      :							Dict				=     image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

												for model_class in self.all_model_classes:
																			__lowercase      :							Dict				=     True
																			self.check_hidden_states_output(__a		,     __a		,     __a		,     (padded_height, padded_width)							)

																			# check that output_hidden_states also work using config
																			del inputs_dict["output_hidden_states"]
																			__lowercase      :							Optional[int]				=     True
																			self.check_hidden_states_output(__a		,     __a		,     __a		,     (padded_height, padded_width)							)



					@unittest.skip(reason="""MaskFormerSwin doesn't have pretrained checkpoints"""							)
					def       lowerCAmelCase				(  self				:	Dict							)			->  Optional[Any]:


												"""simple docstring"""

												pass



					@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""							)
					def       lowerCAmelCase				(  self				:	str							)			->  Union[str, Any]:


												"""simple docstring"""

												pass



					@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""							)
					def       lowerCAmelCase				(  self				:	Optional[int]							)			->  str:


												"""simple docstring"""

												pass



					def       lowerCAmelCase				(  self				:	Dict							)			->  Any:


												"""simple docstring"""

												__lowercase      :							Any				=     self.model_tester.prepare_config_and_inputs_for_common()

												def set_nan_tensor_to_zero(__a				:	Optional[Any]							):
																			__lowercase      :							Union[str, Any]				=     0
																			return t

												def check_equivalence(__a				:	Optional[Any]		,     __a				:	Tuple		,     __a				:	Union[str, Any]		,     __a				:	List[Any]={}							):
																			with torch.no_grad():
																										__lowercase      :							List[str]				=     model(**__a		,     return_dict=__a		,     **__a							)
																										__lowercase      :							Dict				=     model(**__a		,     return_dict=__a		,     **__a							).to_tuple()

																										def recursive_check(__a				:	Optional[int]		,     __a				:	int							):
																																	if isinstance(__a		,     (List, Tuple)							):
																																								for tuple_iterable_value, dict_iterable_value in zip(__a		,     __a							):
																																															recursive_check(__a		,     __a							)
																																	elif isinstance(__a		,     __a							):
																																								for tuple_iterable_value, dict_iterable_value in zip(
																																								    tuple_object.values()		,     dict_object.values()							):
																																															recursive_check(__a		,     __a							)
																																	elif tuple_object is None:
																																								return
																																	else:
																																								self.assertTrue(
																																								    torch.allclose(
																																								        set_nan_tensor_to_zero(__a							)		,     set_nan_tensor_to_zero(__a							)		,     atol=1E-5							)		,     msg=(
																																								        """Tuple and dict output are not equal. Difference:"""
																																								        F" {torch.max(torch.abs(tuple_object - dict_object							)							)}. Tuple has `nan`:"
																																								        F" {torch.isnan(__a							).any()} and `inf`: {torch.isinf(__a							)}. Dict has"
																																								        F" `nan`: {torch.isnan(__a							).any()} and `inf`: {torch.isinf(__a							)}."
																																								    )		,     )

																										recursive_check(__a		,     __a							)

												for model_class in self.all_model_classes:
																			__lowercase      :							Optional[int]				=     model_class(__a							)
																			model.to(__a							)
																			model.eval()

																			__lowercase      :							int				=     self._prepare_for_class(__a		,     __a							)
																			__lowercase      :							Optional[Any]				=     self._prepare_for_class(__a		,     __a							)
																			check_equivalence(__a		,     __a		,     __a							)

																			__lowercase      :							List[Any]				=     self._prepare_for_class(__a		,     __a		,     return_labels=__a							)
																			__lowercase      :							List[str]				=     self._prepare_for_class(__a		,     __a		,     return_labels=__a							)
																			check_equivalence(__a		,     __a		,     __a							)

																			__lowercase      :							Optional[int]				=     self._prepare_for_class(__a		,     __a							)
																			__lowercase      :							List[Any]				=     self._prepare_for_class(__a		,     __a							)
																			check_equivalence(__a		,     __a		,     __a		,     {"""output_hidden_states""": True}							)

																			__lowercase      :							List[Any]				=     self._prepare_for_class(__a		,     __a		,     return_labels=__a							)
																			__lowercase      :							Tuple				=     self._prepare_for_class(__a		,     __a		,     return_labels=__a							)
																			check_equivalence(__a		,     __a		,     __a		,     {"""output_hidden_states""": True}							)







@require_torch
class 		lowerCAmelCase     ( unittest.TestCase      ,       __a			):

					'''simple docstring'''

					_A						:			List[str]									=      (MaskFormerSwinBackbone,) if is_torch_available() else ()
					_A						:			List[Any]									=      MaskFormerSwinConfig



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


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     MaskFormerSwinModelTester(self							)



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


												"""simple docstring"""

												__lowercase      :							Dict				=     self.model_tester.prepare_config_and_inputs_for_common()
												__lowercase      :							str				=     inputs_dict["""pixel_values"""].shape[0]

												for backbone_class in self.all_model_classes:
																			__lowercase      :							Tuple				=     backbone_class(__a							)
																			backbone.to(__a							)
																			backbone.eval()

																			__lowercase      :							Union[str, Any]				=     backbone(**__a							)

																			# Test default outputs and verify feature maps
																			self.assertIsInstance(outputs.feature_maps		,     __a							)
																			self.assertTrue(len(outputs.feature_maps							) == len(backbone.channels							)							)
																			for feature_map, n_channels in zip(outputs.feature_maps		,     backbone.channels							):
																										self.assertTrue(feature_map.shape[:2]		,     (batch_size, n_channels)							)
																			self.assertIsNone(outputs.hidden_states							)
																			self.assertIsNone(outputs.attentions							)

																			# Test output_hidden_states=True
																			__lowercase      :							Optional[Any]				=     backbone(**__a		,     output_hidden_states=__a							)
																			self.assertIsNotNone(outputs.hidden_states							)
																			self.assertTrue(len(outputs.hidden_states							)		,     len(backbone.stage_names							)							)
																			# We skip the stem layer
																			for hidden_states, n_channels in zip(outputs.hidden_states[1:]		,     backbone.channels							):
																										for hidden_state in hidden_states:
																																	# Hidden states are in the format (batch_size, (height * width), n_channels)
																																	__lowercase      :							str				=     hidden_state.shape
																																	self.assertTrue((h_batch_size, h_n_channels)		,     (batch_size, n_channels)							)

            # Test output_attentions=True
																			if self.has_attentions:
																										__lowercase      :							int				=     backbone(**__a		,     output_attentions=__a							)
																										self.assertIsNotNone(outputs.attentions							)










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, MobileNetVaForSemanticSegmentation, MobileNetVaModel
	from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from PIL import Image

	from transformers import MobileNetVaImageProcessor

class 		lowerCAmelCase     ( __a			):

					'''simple docstring'''

					def       lowerCAmelCase				(  self				:	List[str]							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							str				=     self.config_class(**self.inputs_dict							)
												self.parent.assertTrue(hasattr(__a		,     """tf_padding"""							)							)
												self.parent.assertTrue(hasattr(__a		,     """depth_multiplier"""							)							)







class 		lowerCAmelCase     :

					'''simple docstring'''

					def __init__(  self				:	Union[str, Any]		,     __a				:	Tuple		,     __a				:	str=13		,     __a				:	Dict=3		,     __a				:	List[Any]=32		,     __a				:	Any=0.25		,     __a				:	Any=8		,     __a				:	Optional[int]=8		,     __a				:	Optional[int]=6		,     __a				:	Dict=32		,     __a				:	Tuple=True		,     __a				:	List[Any]=True		,     __a				:	Optional[int]=True		,     __a				:	Tuple="relu6"		,     __a				:	Optional[Any]=1280		,     __a				:	str=0.1		,     __a				:	str=0.02		,     __a				:	Optional[Any]=True		,     __a				:	Tuple=True		,     __a				:	Dict=10		,     __a				:	Optional[Any]=None		,     )			->  Any:


												"""simple docstring"""

												__lowercase      :							List[str]				=     parent
												__lowercase      :							Tuple				=     batch_size
												__lowercase      :							Dict				=     num_channels
												__lowercase      :							Optional[int]				=     image_size
												__lowercase      :							int				=     depth_multiplier
												__lowercase      :							str				=     depth_divisible_by
												__lowercase      :							int				=     min_depth
												__lowercase      :							Tuple				=     expand_ratio
												__lowercase      :							Optional[int]				=     tf_padding
												__lowercase      :							Dict				=     output_stride
												__lowercase      :							Dict				=     first_layer_is_expansion
												__lowercase      :							Optional[Any]				=     finegrained_output
												__lowercase      :							str				=     hidden_act
												__lowercase      :							Union[str, Any]				=     last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier							)
												__lowercase      :							Optional[int]				=     classifier_dropout_prob
												__lowercase      :							int				=     use_labels
												__lowercase      :							Optional[int]				=     is_training
												__lowercase      :							Dict				=     num_labels
												__lowercase      :							Tuple				=     initializer_range
												__lowercase      :							Optional[Any]				=     scope



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


												"""simple docstring"""

												__lowercase      :							Tuple				=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

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

												__lowercase      :							List[Any]				=     self.get_config()

												return config, pixel_values, labels, pixel_labels



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


												"""simple docstring"""

												return MobileNetVaConfig(
												    num_channels=self.num_channels		,     image_size=self.image_size		,     depth_multiplier=self.depth_multiplier		,     depth_divisible_by=self.depth_divisible_by		,     min_depth=self.min_depth		,     expand_ratio=self.expand_ratio		,     output_stride=self.output_stride		,     first_layer_is_expansion=self.first_layer_is_expansion		,     finegrained_output=self.finegrained_output		,     hidden_act=self.hidden_act		,     tf_padding=self.tf_padding		,     classifier_dropout_prob=self.classifier_dropout_prob		,     initializer_range=self.initializer_range		,     )



					def       lowerCAmelCase				(  self				:	Tuple		,     __a				:	Dict		,     __a				:	Tuple		,     __a				:	Optional[int]		,     __a				:	Union[str, Any]							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							Optional[int]				=     MobileNetVaModel(config=__a							)
												model.to(__a							)
												model.eval()
												__lowercase      :							Tuple				=     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,
												    )		,     )
												self.parent.assertEqual(
												    result.pooler_output.shape		,     (self.batch_size, self.last_hidden_size)		,     )



					def       lowerCAmelCase				(  self				:	List[str]		,     __a				:	Optional[int]		,     __a				:	List[str]		,     __a				:	str		,     __a				:	Optional[int]							)			->  Tuple:


												"""simple docstring"""

												__lowercase      :							List[Any]				=     self.num_labels
												__lowercase      :							Dict				=     MobileNetVaForImageClassification(__a							)
												model.to(__a							)
												model.eval()
												__lowercase      :							Dict				=     model(__a		,     labels=__a							)
												self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_labels)							)



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


												"""simple docstring"""

												__lowercase      :							int				=     self.num_labels
												__lowercase      :							List[Any]				=     MobileNetVaForSemanticSegmentation(__a							)
												model.to(__a							)
												model.eval()
												__lowercase      :							Dict				=     model(__a							)
												self.parent.assertEqual(
												    result.logits.shape		,     (
												        self.batch_size,
												        self.num_labels,
												        self.image_size // self.output_stride,
												        self.image_size // self.output_stride,
												    )		,     )
												__lowercase      :							str				=     model(__a		,     labels=__a							)
												self.parent.assertEqual(
												    result.logits.shape		,     (
												        self.batch_size,
												        self.num_labels,
												        self.image_size // self.output_stride,
												        self.image_size // self.output_stride,
												    )		,     )



					def       lowerCAmelCase				(  self				:	Tuple							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							List[str]				=     self.prepare_config_and_inputs()
												__lowercase			,			__lowercase			,			__lowercase			,			__lowercase      :							List[str]				=     config_and_inputs
												__lowercase      :							List[Any]				=     {"""pixel_values""": pixel_values}
												return config, inputs_dict







@require_torch
class 		lowerCAmelCase     ( __a      ,       __a      ,       unittest.TestCase			):

					'''simple docstring'''

					_A						:			Tuple									=      (
					    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
					    if is_torch_available()
					    else ()
					)
					_A						:			Optional[Any]									=      (
					    {
					        '''feature-extraction''': MobileNetVaModel,
					        '''image-classification''': MobileNetVaForImageClassification,
					        '''image-segmentation''': MobileNetVaForSemanticSegmentation,
					    }
					    if is_torch_available()
					    else {}
					)

					_A						:			Tuple									=      False
					_A						:			List[str]									=      False
					_A						:			List[str]									=      False
					_A						:			Optional[int]									=      False



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


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     MobileNetVaModelTester(self							)
												__lowercase      :							int				=     MobileNetVaConfigTester(self		,     config_class=__a		,     has_text_modality=__a							)



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


												"""simple docstring"""

												self.config_tester.run_common_tests()



					@unittest.skip(reason="""MobileNetV2 does not use inputs_embeds"""							)
					def       lowerCAmelCase				(  self				:	List[str]							)			->  Union[str, Any]:


												"""simple docstring"""

												pass



					@unittest.skip(reason="""MobileNetV2 does not support input and output embeddings"""							)
					def       lowerCAmelCase				(  self				:	Any							)			->  Tuple:


												"""simple docstring"""

												pass



					@unittest.skip(reason="""MobileNetV2 does not output attentions"""							)
					def       lowerCAmelCase				(  self				:	List[str]							)			->  int:


												"""simple docstring"""

												pass



					def       lowerCAmelCase				(  self				:	List[str]							)			->  Dict:


												"""simple docstring"""

												__lowercase			,			__lowercase      :							Optional[int]				=     self.model_tester.prepare_config_and_inputs_for_common()

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

																			__lowercase      :							Any				=     ["""pixel_values"""]
																			self.assertListEqual(arg_names[:1]		,     __a							)



					def       lowerCAmelCase				(  self				:	Dict							)			->  Any:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__a							)



					def       lowerCAmelCase				(  self				:	List[str]							)			->  Tuple:


												"""simple docstring"""

												def check_hidden_states_output(__a				:	List[Any]		,     __a				:	Tuple		,     __a				:	List[str]							):
																			__lowercase      :							Optional[Any]				=     model_class(__a							)
																			model.to(__a							)
																			model.eval()

																			with torch.no_grad():
																										__lowercase      :							List[Any]				=     model(**self._prepare_for_class(__a		,     __a							)							)

																			__lowercase      :							Tuple				=     outputs.hidden_states

																			__lowercase      :							str				=     16
																			self.assertEqual(len(__a							)		,     __a							)

												__lowercase			,			__lowercase      :							int				=     self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			__lowercase      :							Any				=     True
																			check_hidden_states_output(__a		,     __a		,     __a							)

																			# check that output_hidden_states also work using config
																			del inputs_dict["output_hidden_states"]
																			__lowercase      :							Union[str, Any]				=     True

																			check_hidden_states_output(__a		,     __a		,     __a							)



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


												"""simple docstring"""

												__lowercase      :							Dict				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*__a							)



					def       lowerCAmelCase				(  self				:	List[str]							)			->  int:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_semantic_segmentation(*__a							)



					@slow
					def       lowerCAmelCase				(  self				:	Optional[int]							)			->  Optional[Any]:


												"""simple docstring"""

												for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			__lowercase      :							Optional[int]				=     MobileNetVaModel.from_pretrained(__a							)
																			self.assertIsNotNone(__a							)







def       snake_case_		(     ):
							__lowercase      :							List[Any]				=     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""      )
							return image



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

					'''simple docstring'''

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


												"""simple docstring"""

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



					@slow
					def       lowerCAmelCase				(  self				:	str							)			->  int:


												"""simple docstring"""

												__lowercase      :							Tuple				=     MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v2_1.0_224"""							).to(__a							)

												__lowercase      :							str				=     self.default_image_processor
												__lowercase      :							Tuple				=     prepare_img()
												__lowercase      :							Tuple				=     image_processor(images=__a		,     return_tensors="""pt"""							).to(__a							)

												# forward pass
												with torch.no_grad():
																			__lowercase      :							str				=     model(**__a							)

												# verify the logits
												__lowercase      :							Union[str, Any]				=     torch.Size((1, 1001)							)
												self.assertEqual(outputs.logits.shape		,     __a							)

												__lowercase      :							str				=     torch.tensor([0.2445, -1.1993, 0.1905]							).to(__a							)

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



					@slow
					def       lowerCAmelCase				(  self				:	Tuple							)			->  Any:


												"""simple docstring"""

												__lowercase      :							int				=     MobileNetVaForSemanticSegmentation.from_pretrained("""google/deeplabv3_mobilenet_v2_1.0_513"""							)
												__lowercase      :							Dict				=     model.to(__a							)

												__lowercase      :							Tuple				=     MobileNetVaImageProcessor.from_pretrained("""google/deeplabv3_mobilenet_v2_1.0_513"""							)

												__lowercase      :							List[str]				=     prepare_img()
												__lowercase      :							Optional[int]				=     image_processor(images=__a		,     return_tensors="""pt"""							).to(__a							)

												# forward pass
												with torch.no_grad():
																			__lowercase      :							Union[str, Any]				=     model(**__a							)
												__lowercase      :							Any				=     outputs.logits

												# verify the logits
												__lowercase      :							Dict				=     torch.Size((1, 21, 65, 65)							)
												self.assertEqual(logits.shape		,     __a							)

												__lowercase      :							str				=     torch.tensor(
												    [
												        [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
												        [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
												        [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
												    ]		,     device=__a		,     )

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