





import copy
from typing import Dict, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING
from ..detr import DetrConfig
from ..swin import SwinConfig


_SCREAMING_SNAKE_CASE     :   int      	=		{
    """facebook/maskformer-swin-base-ade""": (
        """https://huggingface.co/facebook/maskformer-swin-base-ade/blob/main/config.json"""
    )
    # See all MaskFormer models at https://huggingface.co/models?filter=maskformer
}

_SCREAMING_SNAKE_CASE     :   List[Any]      	=		logging.get_logger(__name__)
class SCREAMING_SNAKE_CASE_						(					snake_case_					):
						__magic_name__:			List[Any]       =       "maskformer"
						__magic_name__:			Optional[Any]       =       {"hidden_size": "mask_feature_size"}
						__magic_name__:			Optional[int]       =       ["resnet", "swin"]
						__magic_name__:			List[Any]       =       ["detr"]






						def __init__(      self      :      Any		,   _A      :      int = 256		,   _A      :      int = 256		,   _A      :      float = 0.1		,   _A      :      bool = False		,   _A      :      Optional[Dict] = None		,   _A      :      Optional[Dict] = None		,   _A      :      float = 0.0_2		,   _A      :      float = 1.0		,   _A      :      float = 1.0		,   _A      :      float = 1.0		,   _A      :      float = 20.0		,   _A      :      Optional[bool] = None		,   **_A      :      Optional[Any]		,   )							->    Any:







							"""simple docstring"""


							if backbone_config is None:
								# fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
								snake_case_		:			Union[str, Any]											=	SwinConfig(
								    image_size=384		,   in_channels=3		,   patch_size=4		,   embed_dim=128		,   depths=[2, 2, 18, 2]		,   num_heads=[4, 8, 16, 32]		,   window_size=12		,   drop_path_rate=0.3		,   out_features=['stage1', 'stage2', 'stage3', 'stage4']		,   )

							if isinstance(_A		,   _A	):
								snake_case_		:			Optional[int]											=	backbone_config.pop('model_type'	)
								snake_case_		:			Tuple											=	CONFIG_MAPPING[backbone_model_type]
								snake_case_		:			Any											=	config_class.from_dict(_A	)

							# verify that the backbone is supported
							if backbone_config.model_type not in self.backbones_supported:
								logger.warning_once(
								    F"""Backbone {backbone_config.model_type} is not a supported model and may not be compatible with MaskFormer. """
								    F"""Supported model types: {','.join(self.backbones_supported	)}"""	)

							if decoder_config is None:
								# fall back to https://huggingface.co/facebook/detr-resnet-50
								snake_case_		:			Optional[Any]											=	DetrConfig()
							else:
								# verify that the decoder is supported
								snake_case_		:			List[str]											=	(
								    decoder_config.pop('model_type'	) if isinstance(_A		,   _A	) else decoder_config.model_type
								)
								if decoder_type not in self.decoders_supported:
									raise ValueError(
									    F"""Transformer Decoder {decoder_type} not supported, please use one of"""
									    F""" {','.join(self.decoders_supported	)}"""	)
								if isinstance(_A		,   _A	):
									snake_case_		:			Optional[int]											=	CONFIG_MAPPING[decoder_type]
									snake_case_		:			Optional[int]											=	config_class.from_dict(_A	)

							snake_case_		:			List[Any]											=	backbone_config
							snake_case_		:			Optional[Any]											=	decoder_config
							# main feature dimension for the model
							snake_case_		:			List[Any]											=	fpn_feature_size
							snake_case_		:			Optional[Any]											=	mask_feature_size
							# initializer
							snake_case_		:			Union[str, Any]											=	init_std
							snake_case_		:			int											=	init_xavier_std
							# Hungarian matcher && loss
							snake_case_		:			List[str]											=	cross_entropy_weight
							snake_case_		:			str											=	dice_weight
							snake_case_		:			int											=	mask_weight
							snake_case_		:			List[Any]											=	use_auxiliary_loss
							snake_case_		:			Tuple											=	no_object_weight
							snake_case_		:			List[str]											=	output_auxiliary_logits

							snake_case_		:			Dict											=	self.decoder_config.encoder_attention_heads
							snake_case_		:			int											=	self.decoder_config.num_hidden_layers
							super().__init__(**_A	)






						@classmethod
						def UpperCAmelCase_				(      cls      :      Optional[int]		,   _A      :      PretrainedConfig		,   _A      :      PretrainedConfig		,   **_A      :      List[str]	)							->    Union[str, Any]:







							"""simple docstring"""


							return cls(
							    backbone_config=_A		,   decoder_config=_A		,   **_A		,   )






						def UpperCAmelCase_				(      self      :      List[str]	)							->    Dict[str, any]:







							"""simple docstring"""


							snake_case_		:			Any											=	copy.deepcopy(self.__dict__	)
							snake_case_		:			Union[str, Any]											=	self.backbone_config.to_dict()
							snake_case_		:			Union[str, Any]											=	self.decoder_config.to_dict()
							snake_case_		:			Dict											=	self.__class__.model_type
							return output








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_SCREAMING_SNAKE_CASE      	=		{
    """configuration_lxmert""": ["""LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LxmertConfig"""],
    """tokenization_lxmert""": ["""LxmertTokenizer"""],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_SCREAMING_SNAKE_CASE      	=		["""LxmertTokenizerFast"""]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_SCREAMING_SNAKE_CASE      	=		[
						    """LxmertEncoder""",
						    """LxmertForPreTraining""",
						    """LxmertForQuestionAnswering""",
						    """LxmertModel""",
						    """LxmertPreTrainedModel""",
						    """LxmertVisualFeatureEncoder""",
						    """LxmertXLayer""",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_SCREAMING_SNAKE_CASE      	=		[
						    """TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """TFLxmertForPreTraining""",
						    """TFLxmertMainLayer""",
						    """TFLxmertModel""",
						    """TFLxmertPreTrainedModel""",
						    """TFLxmertVisualFeatureEncoder""",
						]


if TYPE_CHECKING:
						from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
						from .tokenization_lxmert import LxmertTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_lxmert_fast import LxmertTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_lxmert import (
												    LxmertEncoder,
												    LxmertForPreTraining,
												    LxmertForQuestionAnswering,
												    LxmertModel,
												    LxmertPreTrainedModel,
												    LxmertVisualFeatureEncoder,
												    LxmertXLayer,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_lxmert import (
												    TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFLxmertForPreTraining,
												    TFLxmertMainLayer,
												    TFLxmertModel,
												    TFLxmertPreTrainedModel,
												    TFLxmertVisualFeatureEncoder,
												)

else:
						import sys

						_SCREAMING_SNAKE_CASE      	=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

