



'''simple docstring'''





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


_lowerCAmelCase										=     {
    '''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
}

_lowerCAmelCase										=     logging.get_logger(__name__)






class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				List[Any]           =				'''maskformer'''
  __lowercase							:				Optional[Any]           =				{'''hidden_size''': '''mask_feature_size'''}
  __lowercase							:				Union[str, Any]           =				['''resnet''', '''swin''']
  __lowercase							:				int           =				['''detr''']




  def __init__(   self  ,__UpperCAmelCase = 256  ,__UpperCAmelCase = 256  ,__UpperCAmelCase = 0.1  ,__UpperCAmelCase = False  ,__UpperCAmelCase = None  ,__UpperCAmelCase = None  ,__UpperCAmelCase = 0.0_2  ,__UpperCAmelCase = 1.0  ,__UpperCAmelCase = 1.0  ,__UpperCAmelCase = 1.0  ,__UpperCAmelCase = 2_0.0  ,__UpperCAmelCase = None  ,**__UpperCAmelCase  ,)   ->		List[str]:
      if backbone_config is None:
          # fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
          lowerCAmelCase__			:  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				):
          lowerCAmelCase__			:  List[Any]											= backbone_config.pop("""model_type"""				)
          lowerCAmelCase__			:  Dict											= CONFIG_MAPPING[backbone_model_type]
          lowerCAmelCase__			:  List[Any]											= 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
          lowerCAmelCase__			:  int											= DetrConfig()
      else:
          # verify that the decoder is supported
          lowerCAmelCase__			:  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				):
              lowerCAmelCase__			:  Optional[Any]											= CONFIG_MAPPING[decoder_type]
              lowerCAmelCase__			:  Optional[int]											= config_class.from_dict(__UpperCAmelCase				)

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

      lowerCAmelCase__			:  str											= self.decoder_config.encoder_attention_heads
      lowerCAmelCase__			:  Any											= self.decoder_config.num_hidden_layers
      super().__init__(**__UpperCAmelCase				)




  @classmethod
  def 							UpperCAmelCase_     (   cls  ,__UpperCAmelCase  ,__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		Optional[int]:
      return cls(
          backbone_config=__UpperCAmelCase  ,decoder_config=__UpperCAmelCase  ,**__UpperCAmelCase  ,)






  def 							UpperCAmelCase_     (   self				)   ->		Dict[str, any]:
      lowerCAmelCase__			:  Any											= copy.deepcopy(self.__dict__				)
      lowerCAmelCase__			:  Optional[int]											= self.backbone_config.to_dict()
      lowerCAmelCase__			:  str											= self.decoder_config.to_dict()
      lowerCAmelCase__			:  int											= self.__class__.model_type
      return output







'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCAmelCase										=     {
    '''configuration_blip_2''': [
        '''BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''Blip2Config''',
        '''Blip2QFormerConfig''',
        '''Blip2VisionConfig''',
    ],
    '''processing_blip_2''': ['''Blip2Processor'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase										=     [
     '''BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''Blip2Model''',
     '''Blip2QFormerModel''',
     '''Blip2PreTrainedModel''',
     '''Blip2ForConditionalGeneration''',
     '''Blip2VisionModel''',
 ]

if TYPE_CHECKING:
 from .configuration_blip_a import (
     BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     BlipaConfig,
     BlipaQFormerConfig,
     BlipaVisionConfig,
 )
 from .processing_blip_a import BlipaProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_blip_a import (
      BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST,
      BlipaForConditionalGeneration,
      BlipaModel,
      BlipaPreTrainedModel,
      BlipaQFormerModel,
      BlipaVisionModel,
  )

else:
 import sys

 _lowerCAmelCase										=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


