| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # This file was automatically generated from src/transformers/models/edgetam/modular_edgetam.py.
- # Do NOT edit this file manually as any edits will be overwritten by the generation of
- # the file from the modular. If any change should be done, please apply the change to the
- # modular_edgetam.py file directly. One of our CI enforces this.
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # Copyright 2025 The Meta AI Authors and The HuggingFace Team. All rights reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- from huggingface_hub.dataclasses import strict
- from ...configuration_utils import PreTrainedConfig
- from ...utils import auto_docstring
- from ..auto import CONFIG_MAPPING, AutoConfig
- @auto_docstring(checkpoint="yonigozlan/EdgeTAM-hf")
- @strict
- class EdgeTamVisionConfig(PreTrainedConfig):
- r"""
- backbone_channel_list (`List[int]`, *optional*, defaults to `[384, 192, 96, 48]`):
- The list of channel dimensions for the backbone.
- backbone_feature_sizes (`List[List[int]]`, *optional*, defaults to `[[256, 256], [128, 128], [64, 64]]`):
- The spatial sizes of the feature maps from the backbone.
- fpn_hidden_size (`int`, *optional*, defaults to 256):
- The hidden dimension of the FPN.
- fpn_kernel_size (`int`, *optional*, defaults to 1):
- The kernel size for the convolutions in the neck.
- fpn_stride (`int`, *optional*, defaults to 1):
- The stride for the convolutions in the neck.
- fpn_padding (`int`, *optional*, defaults to 0):
- The padding for the convolutions in the neck.
- fpn_top_down_levels (`List[int]`, *optional*, defaults to `[2, 3]`):
- The levels for the top-down FPN connections.
- num_feature_levels (`int`, *optional*, defaults to 3):
- The number of feature levels from the FPN to use.
- """
- base_config_key = "vision_config"
- model_type = "edgetam_vision_model"
- sub_configs = {
- "backbone_config": AutoConfig,
- }
- backbone_config: dict | PreTrainedConfig | None = None
- backbone_channel_list: list[int] | None = None
- backbone_feature_sizes: list | None = None
- fpn_hidden_size: int = 256
- fpn_kernel_size: int = 1
- fpn_stride: int = 1
- fpn_padding: int = 0
- fpn_top_down_levels: list[int] | None = None
- num_feature_levels: int = 3
- hidden_act: str = "gelu"
- layer_norm_eps: float = 1e-6
- initializer_range: float = 0.02
- def __post_init__(self, **kwargs):
- self.backbone_channel_list = (
- [384, 192, 96, 48] if self.backbone_channel_list is None else self.backbone_channel_list
- )
- self.backbone_feature_sizes = (
- [[256, 256], [128, 128], [64, 64]] if self.backbone_feature_sizes is None else self.backbone_feature_sizes
- )
- self.fpn_top_down_levels = [2, 3] if self.fpn_top_down_levels is None else self.fpn_top_down_levels
- if isinstance(self.backbone_config, dict):
- self.backbone_config["model_type"] = self.backbone_config.get("model_type", "timm_wrapper")
- self.backbone_config = CONFIG_MAPPING[self.backbone_config["model_type"]](**self.backbone_config)
- elif self.backbone_config is None:
- self.backbone_config = AutoConfig.from_pretrained(
- "timm/repvit_m1.dist_in1k",
- model_args={"in_chans": 3, "features_only": True, "out_indices": [0, 1, 2, 3]},
- )
- super().__post_init__(**kwargs)
- @auto_docstring(checkpoint="yonigozlan/EdgeTAM-hf")
- @strict
- class EdgeTamPromptEncoderConfig(PreTrainedConfig):
- r"""
- mask_input_channels (`int`, *optional*, defaults to 16):
- The number of channels to be fed to the `MaskDecoder` module.
- num_point_embeddings (`int`, *optional*, defaults to 4):
- The number of point embeddings to be used.
- scale (`float`, *optional*, defaults to 1):
- The scale factor for the prompt encoder.
- """
- base_config_key = "prompt_encoder_config"
- hidden_size: int = 256
- image_size: int | list[int] | tuple[int, int] = 1024
- patch_size: int | list[int] | tuple[int, int] = 16
- mask_input_channels: int = 16
- num_point_embeddings: int = 4
- hidden_act: str = "gelu"
- layer_norm_eps: float = 1e-6
- scale: int = 1
- @auto_docstring(checkpoint="yonigozlan/EdgeTAM-hf")
- @strict
- class EdgeTamMaskDecoderConfig(PreTrainedConfig):
- r"""
- mlp_dim (`int`, *optional*, defaults to 2048):
- The dimension of the MLP in the two-way transformer.
- attention_downsample_rate (`int`, *optional*, defaults to 2):
- The downsample rate for the attention layers.
- num_multimask_outputs (`int`, *optional*, defaults to 3):
- The number of multimask outputs.
- iou_head_depth (`int`, *optional*, defaults to 3):
- The depth of the IoU head.
- iou_head_hidden_dim (`int`, *optional*, defaults to 256):
- The hidden dimension of the IoU head.
- dynamic_multimask_via_stability (`bool`, *optional*, defaults to `True`):
- Whether to use dynamic multimask via stability.
- dynamic_multimask_stability_delta (`float`, *optional*, defaults to 0.05):
- The stability delta for the dynamic multimask.
- dynamic_multimask_stability_thresh (`float`, *optional*, defaults to 0.98):
- The stability threshold for the dynamic multimask.
- """
- base_config_key = "mask_decoder_config"
- hidden_size: int = 256
- hidden_act: str = "gelu"
- mlp_dim: int = 2048
- num_hidden_layers: int = 2
- num_attention_heads: int = 8
- attention_downsample_rate: int = 2
- num_multimask_outputs: int = 3
- iou_head_depth: int = 3
- iou_head_hidden_dim: int = 256
- dynamic_multimask_via_stability: bool = True
- dynamic_multimask_stability_delta: float = 0.05
- dynamic_multimask_stability_thresh: float = 0.98
- @auto_docstring(checkpoint="yonigozlan/EdgeTAM-hf")
- @strict
- class EdgeTamConfig(PreTrainedConfig):
- r"""
- prompt_encoder_config (Union[`dict`, `EdgeTamPromptEncoderConfig`], *optional*):
- Dictionary of configuration options used to initialize [`EdgeTamPromptEncoderConfig`].
- mask_decoder_config (Union[`dict`, `EdgeTamMaskDecoderConfig`], *optional*):
- Dictionary of configuration options used to initialize [`EdgeTamMaskDecoderConfig`].
- Example:
- ```python
- >>> from transformers import (
- ... EdgeTamVisionConfig,
- ... EdgeTamPromptEncoderConfig,
- ... EdgeTamMaskDecoderConfig,
- ... EdgeTamModel,
- ... )
- >>> # Initializing a EdgeTamConfig with `"facebook/edgetam.1_hiera_tiny"` style configuration
- >>> configuration = EdgeTamConfig()
- >>> # Initializing a EdgeTamModel (with random weights) from the `"facebook/edgetam.1_hiera_tiny"` style configuration
- >>> model = EdgeTamModel(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- >>> # We can also initialize a EdgeTamConfig from a EdgeTamVisionConfig, EdgeTamPromptEncoderConfig, and EdgeTamMaskDecoderConfig
- >>> # Initializing EDGETAM vision encoder, memory attention, and memory encoder configurations
- >>> vision_config = EdgeTamVisionConfig()
- >>> prompt_encoder_config = EdgeTamPromptEncoderConfig()
- >>> mask_decoder_config = EdgeTamMaskDecoderConfig()
- >>> config = EdgeTamConfig(vision_config, prompt_encoder_config, mask_decoder_config)
- ```
- """
- model_type = "edgetam"
- sub_configs = {
- "vision_config": AutoConfig,
- "prompt_encoder_config": EdgeTamPromptEncoderConfig,
- "mask_decoder_config": EdgeTamMaskDecoderConfig,
- }
- vision_config: dict | PreTrainedConfig | None = None
- prompt_encoder_config: dict | PreTrainedConfig | None = None
- mask_decoder_config: dict | PreTrainedConfig | None = None
- initializer_range: float = 0.02
- def __post_init__(self, **kwargs):
- if isinstance(self.vision_config, dict):
- self.vision_config["model_type"] = self.vision_config.get("model_type", "edgetam_vision_model")
- self.vision_config = CONFIG_MAPPING[self.vision_config["model_type"]](**self.vision_config)
- elif self.vision_config is None:
- self.vision_config = CONFIG_MAPPING["edgetam_vision_model"]()
- if isinstance(self.prompt_encoder_config, dict):
- self.prompt_encoder_config = EdgeTamPromptEncoderConfig(**self.prompt_encoder_config)
- elif self.prompt_encoder_config is None:
- self.prompt_encoder_config = EdgeTamPromptEncoderConfig()
- if isinstance(self.mask_decoder_config, dict):
- self.mask_decoder_config = EdgeTamMaskDecoderConfig(**self.mask_decoder_config)
- elif self.mask_decoder_config is None:
- self.mask_decoder_config = EdgeTamMaskDecoderConfig()
- super().__post_init__(**kwargs)
- __all__ = ["EdgeTamConfig", "EdgeTamVisionConfig", "EdgeTamPromptEncoderConfig", "EdgeTamMaskDecoderConfig"]
|