






"""simple docstring"""





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase					=     logging.get_logger(__name__)

UpperCamelCase					=     {
    """facebook/sam-vit-huge""": """https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json""",
    """facebook/sam-vit-large""": """https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json""",
    """facebook/sam-vit-base""": """https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json""",
}







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   def __init__(       self					, UpperCAmelCase_=256					, UpperCAmelCase_=1_024					, UpperCAmelCase_=16					, UpperCAmelCase_=16					, UpperCAmelCase_=4					, UpperCAmelCase_="gelu"					, UpperCAmelCase_=1E-6					, **UpperCAmelCase_					, )			->   Any:




          '''simple docstring'''




          super().__init__(**UpperCAmelCase_)
          lowercase__:							Dict         =     hidden_size
          lowercase__:							List[Any]         =     image_size
          lowercase__:							int         =     patch_size
          lowercase__:							Optional[Any]         =     image_size // patch_size
          lowercase__:							str         =     mask_input_channels
          lowercase__:							Any         =     num_point_embeddings
          lowercase__:							Optional[Any]         =     hidden_act
          lowercase__:							List[str]         =     layer_norm_eps







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   def __init__(       self					, UpperCAmelCase_=256					, UpperCAmelCase_="relu"					, UpperCAmelCase_=2_048					, UpperCAmelCase_=2					, UpperCAmelCase_=8					, UpperCAmelCase_=2					, UpperCAmelCase_=3					, UpperCAmelCase_=3					, UpperCAmelCase_=256					, UpperCAmelCase_=1E-6					, **UpperCAmelCase_					, )			->   Optional[Any]:




          '''simple docstring'''




          super().__init__(**UpperCAmelCase_)
          lowercase__:							Dict         =     hidden_size
          lowercase__:							Dict         =     hidden_act
          lowercase__:							List[str]         =     mlp_dim
          lowercase__:							List[str]         =     num_hidden_layers
          lowercase__:							List[str]         =     num_attention_heads
          lowercase__:							int         =     attention_downsample_rate
          lowercase__:							Optional[int]         =     num_multimask_outputs
          lowercase__:							str         =     iou_head_depth
          lowercase__:							List[Any]         =     iou_head_hidden_dim
          lowercase__:							List[str]         =     layer_norm_eps







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   def __init__(       self					, UpperCAmelCase_=768					, UpperCAmelCase_=256					, UpperCAmelCase_=12					, UpperCAmelCase_=12					, UpperCAmelCase_=3					, UpperCAmelCase_=1_024					, UpperCAmelCase_=16					, UpperCAmelCase_="gelu"					, UpperCAmelCase_=1E-0_6					, UpperCAmelCase_=0.0					, UpperCAmelCase_=1E-1_0					, UpperCAmelCase_=True					, UpperCAmelCase_=4.0					, UpperCAmelCase_=True					, UpperCAmelCase_=True					, UpperCAmelCase_=14					, UpperCAmelCase_=[2, 5, 8, 11]					, UpperCAmelCase_=128					, UpperCAmelCase_=None					, **UpperCAmelCase_					, )			->   Any:




          '''simple docstring'''




          super().__init__(**UpperCAmelCase_)

          lowercase__:							Tuple         =     hidden_size
          lowercase__:							Union[str, Any]         =     output_channels
          lowercase__:							List[str]         =     num_hidden_layers
          lowercase__:							Any         =     num_attention_heads
          lowercase__:							Optional[int]         =     num_channels
          lowercase__:							List[Any]         =     image_size
          lowercase__:							Dict         =     patch_size
          lowercase__:							Tuple         =     hidden_act
          lowercase__:							Union[str, Any]         =     layer_norm_eps
          lowercase__:							Dict         =     attention_dropout
          lowercase__:							List[str]         =     initializer_range
          lowercase__:							List[str]         =     qkv_bias
          lowercase__:							Tuple         =     mlp_ratio
          lowercase__:							Optional[int]         =     use_abs_pos
          lowercase__:							Dict         =     use_rel_pos
          lowercase__:							List[str]         =     window_size
          lowercase__:							Optional[int]         =     global_attn_indexes
          lowercase__:							List[Any]         =     num_pos_feats
          lowercase__:							List[Any]         =     int(hidden_size * mlp_ratio) if mlp_dim is None else mlp_dim







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   UpperCamelCase__     	=							"""sam"""
   UpperCamelCase__     	=							True





   def __init__(       self					, UpperCAmelCase_=None					, UpperCAmelCase_=None					, UpperCAmelCase_=None					, UpperCAmelCase_=0.02					, **UpperCAmelCase_					, )			->   Optional[int]:




          '''simple docstring'''




          super().__init__(**UpperCAmelCase_)
          lowercase__:							Tuple         =     vision_config if vision_config is not None else {}
          lowercase__:							Optional[int]         =     prompt_encoder_config if prompt_encoder_config is not None else {}
          lowercase__:							Dict         =     mask_decoder_config if mask_decoder_config is not None else {}

          if isinstance(UpperCAmelCase_					, UpperCAmelCase_):
                 lowercase__:							str         =     vision_config.to_dict()
          if isinstance(UpperCAmelCase_					, UpperCAmelCase_):
                 lowercase__:							List[str]         =     prompt_encoder_config.to_dict()
          if isinstance(UpperCAmelCase_					, UpperCAmelCase_):
                 lowercase__:							List[str]         =     mask_decoder_config.to_dict()

          lowercase__:							int         =     SamVisionConfig(**UpperCAmelCase_)
          lowercase__:							Optional[int]         =     SamPromptEncoderConfig(**UpperCAmelCase_)
          lowercase__:							Optional[Any]         =     SamMaskDecoderConfig(**UpperCAmelCase_)
          lowercase__:							Optional[int]         =     initializer_range





   def __lowercase							(       self)			->   Optional[Any]:




          '''simple docstring'''




          lowercase__:							List[Any]         =     copy.deepcopy(self.__dict__)
          lowercase__:							Any         =     self.vision_config.to_dict()
          lowercase__:							int         =     self.prompt_encoder_config.to_dict()
          lowercase__:							List[Any]         =     self.mask_decoder_config.to_dict()
          lowercase__:							Any         =     self.__class__.model_type
          return output











from ...configuration_utils import PretrainedConfig
from ...utils import is_detectrona_available, logging


UpperCamelCase_									=   logging.get_logger(__name__)

UpperCamelCase_									=   {
    '''layoutlmv2-base-uncased''': '''https://huggingface.co/microsoft/layoutlmv2-base-uncased/resolve/main/config.json''',
    '''layoutlmv2-large-uncased''': '''https://huggingface.co/microsoft/layoutlmv2-large-uncased/resolve/main/config.json''',
    # See all LayoutLMv2 models at https://huggingface.co/models?filter=layoutlmv2
}

# soft dependency
if is_detectrona_available():
      import detectrona







class       _snake_case				(     __snake_case ):






   '''simple docstring'''






   A__      : List[Any]       =						"layoutlmv2"


   def __init__(    self:     Tuple  ,lowerCamelCase_:     Dict=30522  ,lowerCamelCase_:     str=768  ,lowerCamelCase_:     Any=12  ,lowerCamelCase_:     Tuple=12  ,lowerCamelCase_:     int=3072  ,lowerCamelCase_:     int="gelu"  ,lowerCamelCase_:     Dict=0.1  ,lowerCamelCase_:     List[Any]=0.1  ,lowerCamelCase_:     List[Any]=512  ,lowerCamelCase_:     Tuple=2  ,lowerCamelCase_:     Dict=0.0_2  ,lowerCamelCase_:     Dict=1e-12  ,lowerCamelCase_:     Dict=0  ,lowerCamelCase_:     List[str]=1024  ,lowerCamelCase_:     Optional[Any]=128  ,lowerCamelCase_:     List[Any]=32  ,lowerCamelCase_:     List[Any]=True  ,lowerCamelCase_:     Dict=256  ,lowerCamelCase_:     int=64  ,lowerCamelCase_:     str=True  ,lowerCamelCase_:     Tuple=[7, 7, 256]  ,lowerCamelCase_:     Union[str, Any]=128  ,lowerCamelCase_:     Any=128  ,lowerCamelCase_:     int=True  ,lowerCamelCase_:     Union[str, Any]=True  ,lowerCamelCase_:     Optional[int]=False  ,lowerCamelCase_:     List[str]=None  ,**lowerCamelCase_:     str  ,)	->      Any:
       super().__init__(
           vocab_size=lowerCamelCase_  ,hidden_size=lowerCamelCase_  ,num_hidden_layers=lowerCamelCase_  ,num_attention_heads=lowerCamelCase_  ,intermediate_size=lowerCamelCase_  ,hidden_act=lowerCamelCase_  ,hidden_dropout_prob=lowerCamelCase_  ,attention_probs_dropout_prob=lowerCamelCase_  ,max_position_embeddings=lowerCamelCase_  ,type_vocab_size=lowerCamelCase_  ,initializer_range=lowerCamelCase_  ,layer_norm_eps=lowerCamelCase_  ,pad_token_id=lowerCamelCase_  ,**lowerCamelCase_  ,)
       UpperCAmelCase_     :       Optional[int]  		=					max_ad_position_embeddings
       UpperCAmelCase_     :       Optional[int]  		=					max_rel_pos
       UpperCAmelCase_     :       Optional[int]  		=					rel_pos_bins
       UpperCAmelCase_     :       List[str]  		=					fast_qkv
       UpperCAmelCase_     :       int  		=					max_rel_ad_pos
       UpperCAmelCase_     :       int  		=					rel_ad_pos_bins
       UpperCAmelCase_     :       Optional[Any]  		=					convert_sync_batchnorm
       UpperCAmelCase_     :       str  		=					image_feature_pool_shape
       UpperCAmelCase_     :       List[Any]  		=					coordinate_size
       UpperCAmelCase_     :       int  		=					shape_size
       UpperCAmelCase_     :       Optional[Any]  		=					has_relative_attention_bias
       UpperCAmelCase_     :       str  		=					has_spatial_attention_bias
       UpperCAmelCase_     :       Tuple  		=					has_visual_segment_embedding
       UpperCAmelCase_     :       Optional[Any]  		=					(
           detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
       )


   @classmethod
   def       A__    (    self:     Any							)	->      Dict:
       return {
           "MODEL.MASK_ON": True,
           "MODEL.PIXEL_STD": [5_7.3_7_5, 5_7.1_2_0, 5_8.3_9_5],
           "MODEL.BACKBONE.NAME": "build_resnet_fpn_backbone",
           "MODEL.FPN.IN_FEATURES": ["res2", "res3", "res4", "res5"],
           "MODEL.ANCHOR_GENERATOR.SIZES": [[32], [64], [128], [256], [512]],
           "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
           "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2000,
           "MODEL.RPN.PRE_NMS_TOPK_TEST": 1000,
           "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1000,
           "MODEL.POST_NMS_TOPK_TEST": 1000,
           "MODEL.ROI_HEADS.NAME": "StandardROIHeads",
           "MODEL.ROI_HEADS.NUM_CLASSES": 5,
           "MODEL.ROI_HEADS.IN_FEATURES": ["p2", "p3", "p4", "p5"],
           "MODEL.ROI_BOX_HEAD.NAME": "FastRCNNConvFCHead",
           "MODEL.ROI_BOX_HEAD.NUM_FC": 2,
           "MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION": 14,
           "MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
           "MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
           "MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
           "MODEL.RESNETS.DEPTH": 101,
           "MODEL.RESNETS.SIZES": [[32], [64], [128], [256], [512]],
           "MODEL.RESNETS.ASPECT_RATIOS": [[0.5, 1.0, 2.0]],
           "MODEL.RESNETS.OUT_FEATURES": ["res2", "res3", "res4", "res5"],
           "MODEL.RESNETS.NUM_GROUPS": 32,
           "MODEL.RESNETS.WIDTH_PER_GROUP": 8,
           "MODEL.RESNETS.STRIDE_IN_1X1": False,
       }






   def       A__    (    self:     Tuple							)	->      int:
       UpperCAmelCase_     :       Any  		=					detectrona.config.get_cfg()
       for k, v in self.detectrona_config_args.items():
           UpperCAmelCase_     :       Optional[int]  		=					k.split("""."""							)
           UpperCAmelCase_     :       List[str]  		=					detectrona_config
           for attribute in attributes[:-1]:
               UpperCAmelCase_     :       Optional[Any]  		=					getattr(lowerCamelCase_  ,lowerCamelCase_							)
           setattr(lowerCamelCase_  ,attributes[-1]  ,lowerCamelCase_							)

       return detectrona_config
