






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__       :			List[str]			      =						{
    "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__       :			Optional[int]			      =						logging.get_logger(__name__)







class   __lowerCAmelCase			(					_UpperCamelCase  ):
   _UpperCamelCase :						List[str]     		=				"""maskformer"""
   _UpperCamelCase :						Tuple     		=				{"""hidden_size""": """mask_feature_size"""}
   _UpperCamelCase :						Optional[int]     		=				["""resnet""", """swin"""]
   _UpperCamelCase :						Any     		=				["""detr"""]





   def __init__( self					,			snake_case = 256					,			snake_case = 256					,			snake_case = 0.1					,			snake_case = False					,			snake_case = None					,			snake_case = None					,			snake_case = 0.02					,			snake_case = 1.0					,			snake_case = 1.0					,			snake_case = 1.0					,			snake_case = 20.0					,			snake_case = None					,			**snake_case					,			)				->  str:
      """simple docstring"""





      if backbone_config is None:
         # fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
         a__	:						Optional[int]      		=  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(UpperCAmelCase__					,			UpperCAmelCase__      ):
         a__	:						Any      		=  backbone_config.pop("model_type"      )
         a__	:						Union[str, Any]      		=  CONFIG_MAPPING[backbone_model_type]
         a__	:						int      		=  config_class.from_dict(UpperCAmelCase__      )

      # 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
         a__	:						int      		=  DetrConfig()
      else:
         # verify that the decoder is supported
         a__	:						List[str]      		=  (
             decoder_config.pop("model_type"      ) if isinstance(UpperCAmelCase__					,			UpperCAmelCase__      ) 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(UpperCAmelCase__					,			UpperCAmelCase__      ):
            a__	:						Optional[Any]      		=  CONFIG_MAPPING[decoder_type]
            a__	:						Optional[Any]      		=  config_class.from_dict(UpperCAmelCase__      )

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

      a__	:						Dict      		=  self.decoder_config.encoder_attention_heads
      a__	:						Tuple      		=  self.decoder_config.num_hidden_layers
      super().__init__(**UpperCAmelCase__      )





   @classmethod
   def 	_snake_case ( cls					,			snake_case					,			snake_case					,			**snake_case      )				->  Dict:
      """simple docstring"""





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





   def 	_snake_case ( self      )				->  Dict[str, any]:
      """simple docstring"""





      a__	:						Optional[int]      		=  copy.deepcopy(self.__dict__      )
      a__	:						Tuple      		=  self.backbone_config.to_dict()
      a__	:						str      		=  self.decoder_config.to_dict()
      a__	:						Optional[int]      		=  self.__class__.model_type
      return output








import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


SCREAMING_SNAKE_CASE__       :			int			      =						logging.get_logger(__name__)







class   __lowerCAmelCase			(					_UpperCamelCase  ):
   _UpperCamelCase :						int     		=				"""upernet"""





   def __init__( self					,			snake_case=None					,			snake_case=512					,			snake_case=0.02					,			snake_case=[1, 2, 3, 6]					,			snake_case=True					,			snake_case=0.4					,			snake_case=384					,			snake_case=256					,			snake_case=1					,			snake_case=False					,			snake_case=255					,			**snake_case					,			)				->  Optional[Any]:
      """simple docstring"""





      super().__init__(**snake_case      )

      if backbone_config is None:
         logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."      )
         a__	:						List[str]      		=  CONFIG_MAPPING["resnet"](out_features=["stage1", "stage2", "stage3", "stage4"]      )
      elif isinstance(snake_case					,			snake_case      ):
         a__	:						Optional[int]      		=  backbone_config.get("model_type"      )
         a__	:						str      		=  CONFIG_MAPPING[backbone_model_type]
         a__	:						str      		=  config_class.from_dict(snake_case      )

      a__	:						int      		=  backbone_config
      a__	:						Optional[Any]      		=  hidden_size
      a__	:						Optional[Any]      		=  initializer_range
      a__	:						Tuple      		=  pool_scales
      a__	:						Optional[Any]      		=  use_auxiliary_head
      a__	:						Optional[Any]      		=  auxiliary_loss_weight
      a__	:						Dict      		=  auxiliary_in_channels
      a__	:						Optional[int]      		=  auxiliary_channels
      a__	:						Any      		=  auxiliary_num_convs
      a__	:						Any      		=  auxiliary_concat_input
      a__	:						int      		=  loss_ignore_index





   def 	_snake_case ( self      )				->  str:
      """simple docstring"""





      a__	:						Tuple      		=  copy.deepcopy(self.__dict__      )
      a__	:						Optional[Any]      		=  self.backbone_config.to_dict()
      a__	:						List[Any]      		=  self.__class__.model_type
      return output

