


import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class  SCREAMING_SNAKE_CASE__  (				lowercase__			):
      snake_case__				:     Tuple        =						['''image_processor''', '''tokenizer''']
      snake_case__				:     Union[str, Any]        =						'''CLIPImageProcessor'''
      snake_case__				:     Dict        =						('''CLIPTokenizer''', '''CLIPTokenizerFast''')
      def __init__(       self				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]=None     ,							SCREAMING_SNAKE_CASE__				:       List[str]=None     ,							**SCREAMING_SNAKE_CASE__				:       int     )		->			Any:
             a_					:		List[Any]							=  None
             if "feature_extractor" in kwargs:
                    warnings.warn(
                        'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
                        ' instead.'     ,							SCREAMING_SNAKE_CASE__     ,							)
                    a_					:		Tuple							=  kwargs.pop('feature_extractor'     )

             a_					:		Tuple							=  image_processor if image_processor is not None else feature_extractor
             if image_processor is None:
                    raise ValueError('You need to specify an `image_processor`.'     )
             if tokenizer is None:
                    raise ValueError('You need to specify a `tokenizer`.'     )

             super().__init__(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      def __call__(       self				:       List[Any]     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=None     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]=None     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]=None     ,							**SCREAMING_SNAKE_CASE__				:       str     )		->			Optional[Any]:

             if text is None and images is None:
                    raise ValueError('You have to specify either text or images. Both cannot be none.'     )

             if text is not None:
                    a_					:		List[str]							=  self.tokenizer(SCREAMING_SNAKE_CASE__     ,							return_tensors=SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )

             if images is not None:
                    a_					:		Dict							=  self.image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors=SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )

             if text is not None and images is not None:
                    a_					:		Dict							=  image_features.pixel_values
                    return encoding
             elif text is not None:
                    return encoding
             else:
                    return BatchEncoding(data=dict(**SCREAMING_SNAKE_CASE__     )     ,							tensor_type=SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     ,							*SCREAMING_SNAKE_CASE__				:       List[Any]     ,							**SCREAMING_SNAKE_CASE__				:       Optional[int]     )		->			List[Any]:
             return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     ,							*SCREAMING_SNAKE_CASE__				:       List[Any]     ,							**SCREAMING_SNAKE_CASE__				:       Dict     )		->			Optional[Any]:
             return self.tokenizer.decode(*SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )
      @property
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Any:
             a_					:		str							=  self.tokenizer.model_input_names
             a_					:		Tuple							=  self.image_processor.model_input_names
             return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )
      @property
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			str:
             warnings.warn(
                 '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'     ,							SCREAMING_SNAKE_CASE__     ,							)
             return self.image_processor_class

      @property
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Tuple:
             warnings.warn(
                 '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'     ,							SCREAMING_SNAKE_CASE__     ,							)
             return self.image_processor






import copy
from typing import Dict, List, Optional

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


UpperCAmelCase_      : Optional[int]  					=       {
    'facebook/mask2former-swin-small-coco-instance': (
        'https://huggingface.co/facebook/mask2former-swin-small-coco-instance/blob/main/config.json'
    )
    # See all Mask2Former models at https://huggingface.co/models?filter=mask2former
}

UpperCAmelCase_      : List[str]  					=       logging.get_logger(__name__)
class  SCREAMING_SNAKE_CASE__  (				lowercase__			):
      snake_case__				:     Any        =						'''mask2former'''
      snake_case__				:     Any        =						['''swin''']
      snake_case__				:     str        =						{'''hidden_size''': '''hidden_dim'''}
      def __init__(       self				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Optional[Dict] = None     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0_2_4     ,							SCREAMING_SNAKE_CASE__				:       str = "relu"     ,							SCREAMING_SNAKE_CASE__				:       int = 6     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0     ,							SCREAMING_SNAKE_CASE__				:       int = 8     ,							SCREAMING_SNAKE_CASE__				:       float = 0.0     ,							SCREAMING_SNAKE_CASE__				:       int = 2_0_4_8     ,							SCREAMING_SNAKE_CASE__				:       bool = False     ,							SCREAMING_SNAKE_CASE__				:       bool = False     ,							SCREAMING_SNAKE_CASE__				:       int = 4     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_5     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0_0     ,							SCREAMING_SNAKE_CASE__				:       float = 0.1     ,							SCREAMING_SNAKE_CASE__				:       float = 2.0     ,							SCREAMING_SNAKE_CASE__				:       float = 5.0     ,							SCREAMING_SNAKE_CASE__				:       float = 5.0     ,							SCREAMING_SNAKE_CASE__				:       int = 1_2_5_4_4     ,							SCREAMING_SNAKE_CASE__				:       float = 3.0     ,							SCREAMING_SNAKE_CASE__				:       float = 0.75     ,							SCREAMING_SNAKE_CASE__				:       float = 0.02     ,							SCREAMING_SNAKE_CASE__				:       float = 1.0     ,							SCREAMING_SNAKE_CASE__				:       bool = True     ,							SCREAMING_SNAKE_CASE__				:       List[int] = [4, 8, 1_6, 3_2]     ,							SCREAMING_SNAKE_CASE__				:       bool = None     ,							**SCREAMING_SNAKE_CASE__				:       int     ,							)		->			List[Any]:
             if backbone_config is None:
                    logger.info('`backbone_config` is `None`. Initializing the config with the default `Swin` backbone.'     )
                    a_					:		Dict							=  CONFIG_MAPPING['swin'](
                        image_size=2_2_4     ,							in_channels=3     ,							patch_size=4     ,							embed_dim=9_6     ,							depths=[2, 2, 1_8, 2]     ,							num_heads=[3, 6, 1_2, 2_4]     ,							window_size=7     ,							drop_path_rate=0.3     ,							use_absolute_embeddings=SCREAMING_SNAKE_CASE__     ,							out_features=['stage1', 'stage2', 'stage3', 'stage4']     ,							)

             if isinstance(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ):
                    a_					:		Any							=  backbone_config.pop('model_type'     )
                    a_					:		Optional[Any]							=  CONFIG_MAPPING[backbone_model_type]
                    a_					:		List[str]							=  config_class.from_dict(SCREAMING_SNAKE_CASE__     )

             # 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 Mask2Former. """
                        F"""Supported model types: {",".join(self.backbones_supported     )}"""     )

             a_					:		Dict							=  backbone_config
             a_					:		List[str]							=  feature_size
             a_					:		List[str]							=  mask_feature_size
             a_					:		int							=  hidden_dim
             a_					:		Dict							=  encoder_feedforward_dim
             a_					:		str							=  activation_function
             a_					:		List[str]							=  encoder_layers
             a_					:		List[str]							=  decoder_layers
             a_					:		Dict							=  num_attention_heads
             a_					:		str							=  dropout
             a_					:		Tuple							=  dim_feedforward
             a_					:		List[str]							=  pre_norm
             a_					:		Optional[int]							=  enforce_input_projection
             a_					:		Any							=  common_stride
             a_					:		Optional[int]							=  ignore_value
             a_					:		int							=  num_queries
             a_					:		Tuple							=  no_object_weight
             a_					:		Dict							=  class_weight
             a_					:		Optional[int]							=  mask_weight
             a_					:		Optional[int]							=  dice_weight
             a_					:		str							=  train_num_points
             a_					:		List[str]							=  oversample_ratio
             a_					:		List[Any]							=  importance_sample_ratio
             a_					:		Any							=  init_std
             a_					:		Union[str, Any]							=  init_xavier_std
             a_					:		Union[str, Any]							=  use_auxiliary_loss
             a_					:		Dict							=  feature_strides
             a_					:		List[str]							=  output_auxiliary_logits
             a_					:		Dict							=  decoder_layers

             super().__init__(**SCREAMING_SNAKE_CASE__     )
      @classmethod
      def        SCREAMING_SNAKE_CASE							(       cls				:       str     ,							SCREAMING_SNAKE_CASE__				:       PretrainedConfig     ,							**SCREAMING_SNAKE_CASE__				:       Union[str, Any]     )		->			List[Any]:
             return cls(
                 backbone_config=SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     ,							)

      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Dict[str, any]:
             a_					:		Optional[int]							=  copy.deepcopy(self.__dict__     )
             a_					:		List[Any]							=  self.backbone_config.to_dict()
             a_					:		Optional[Any]							=  self.__class__.model_type
             return output


