



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


A_		:     List[Any]        =     {
    '''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
}

A_		:     Optional[int]        =     logging.get_logger(__name__)



class 		_lowercase		(       UpperCAmelCase__	):
   _UpperCAmelCase     	=			'''maskformer'''
   _UpperCAmelCase     	=			{'''hidden_size''': '''mask_feature_size'''}
   _UpperCAmelCase     	=			['''resnet''', '''swin''']
   _UpperCAmelCase     	=			['''detr''']

   def __init__(      self			:       Tuple							,   __lowerCAmelCase			:       int = 256							,   __lowerCAmelCase			:       int = 256							,   __lowerCAmelCase			:       float = 0.1							,   __lowerCAmelCase			:       bool = False							,   __lowerCAmelCase			:       Optional[Dict] = None							,   __lowerCAmelCase			:       Optional[Dict] = None							,   __lowerCAmelCase			:       float = 0.0_2							,   __lowerCAmelCase			:       float = 1.0							,   __lowerCAmelCase			:       float = 1.0							,   __lowerCAmelCase			:       float = 1.0							,   __lowerCAmelCase			:       float = 2_0.0							,   __lowerCAmelCase			:       Optional[bool] = None							,   **__lowerCAmelCase			:       Dict							,   )       ->				Optional[Any]:


    """simple docstring"""






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

    # 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						=		DetrConfig()
    else:
     # verify that the decoder is supported
     a						=		(
         decoder_config.pop("model_type"							) if isinstance(__lowerCAmelCase							,   __lowerCAmelCase							) 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(__lowerCAmelCase							,   __lowerCAmelCase							):
      a						=		CONFIG_MAPPING[decoder_type]
      a						=		config_class.from_dict(__lowerCAmelCase							)

    a						=		backbone_config
    a						=		decoder_config
    # main feature dimension for the model
    a						=		fpn_feature_size
    a						=		mask_feature_size
    # initializer
    a						=		init_std
    a						=		init_xavier_std
    # Hungarian matcher && loss
    a						=		cross_entropy_weight
    a						=		dice_weight
    a						=		mask_weight
    a						=		use_auxiliary_loss
    a						=		no_object_weight
    a						=		output_auxiliary_logits

    a						=		self.decoder_config.encoder_attention_heads
    a						=		self.decoder_config.num_hidden_layers
    super().__init__(**__lowerCAmelCase							)

   @classmethod
   def 		A							(      cls			:       Optional[int]							,   __lowerCAmelCase			:       PretrainedConfig							,   __lowerCAmelCase			:       PretrainedConfig							,   **__lowerCAmelCase			:       str							)       ->				Tuple:


    """simple docstring"""






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




   def 		A							(      self			:       Any							)       ->				Dict[str, any]:


    """simple docstring"""






    a						=		copy.deepcopy(self.__dict__							)
    a						=		self.backbone_config.to_dict()
    a						=		self.decoder_config.to_dict()
    a						=		self.__class__.model_type
    return output






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_		:     int        =     logging.get_logger(__name__)

A_		:     str        =     {
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}



class 		_lowercase		(       UpperCAmelCase__,   UpperCAmelCase__	):
   _UpperCAmelCase     	=			'''focalnet'''

   def __init__(      self			:       int							,   __lowerCAmelCase			:       Optional[Any]=224							,   __lowerCAmelCase			:       Any=4							,   __lowerCAmelCase			:       Any=3							,   __lowerCAmelCase			:       Tuple=96							,   __lowerCAmelCase			:       Dict=False							,   __lowerCAmelCase			:       Optional[int]=[192, 384, 768, 768]							,   __lowerCAmelCase			:       Union[str, Any]=[2, 2, 6, 2]							,   __lowerCAmelCase			:       Optional[int]=[2, 2, 2, 2]							,   __lowerCAmelCase			:       Union[str, Any]=[3, 3, 3, 3]							,   __lowerCAmelCase			:       str="gelu"							,   __lowerCAmelCase			:       Any=4.0							,   __lowerCAmelCase			:       Optional[int]=0.0							,   __lowerCAmelCase			:       Tuple=0.1							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Optional[int]=1E-4							,   __lowerCAmelCase			:       Optional[Any]=False							,   __lowerCAmelCase			:       Union[str, Any]=False							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Any=0.0_2							,   __lowerCAmelCase			:       str=1E-5							,   __lowerCAmelCase			:       Optional[Any]=32							,   __lowerCAmelCase			:       Dict=None							,   __lowerCAmelCase			:       str=None							,   **__lowerCAmelCase			:       Any							,   )       ->				List[str]:


    """simple docstring"""






    super().__init__(**__lowerCAmelCase							)

    a						=		image_size
    a						=		patch_size
    a						=		num_channels
    a						=		embed_dim
    a						=		use_conv_embed
    a						=		hidden_sizes
    a						=		depths
    a						=		focal_levels
    a						=		focal_windows
    a						=		hidden_act
    a						=		mlp_ratio
    a						=		hidden_dropout_prob
    a						=		drop_path_rate
    a						=		use_layerscale
    a						=		layerscale_value
    a						=		use_post_layernorm
    a						=		use_post_layernorm_in_modulation
    a						=		normalize_modulator
    a						=		initializer_range
    a						=		layer_norm_eps
    a						=		encoder_stride
    a						=		["stem"] + [f"""stage{idx}""" for idx in range(1							,   len(self.depths							) + 1							)]
    a		,  a						=		get_aligned_output_features_output_indices(
        out_features=__lowerCAmelCase							,   out_indices=__lowerCAmelCase							,   stage_names=self.stage_names							)

