configuration_chmv2.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/chmv2/modular_chmv2.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_chmv2.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2026 Meta Platforms, Inc. and The HuggingFace Inc. team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. from typing import Literal
  21. from huggingface_hub.dataclasses import strict
  22. from ...backbone_utils import consolidate_backbone_kwargs_to_config
  23. from ...configuration_utils import PreTrainedConfig
  24. from ...utils import auto_docstring
  25. from ..auto import AutoConfig
  26. @auto_docstring(checkpoint="facebook/dinov3-vitl16-chmv2-dpt-head")
  27. @strict
  28. class CHMv2Config(PreTrainedConfig):
  29. r"""
  30. backbone_config (`Union[dict, "PreTrainedConfig"]`, *optional*):
  31. The configuration of the backbone model. Only DINOv3ViTConfig is currently supported.
  32. patch_size (`int`, *optional*, defaults to 16):
  33. The patch size used by the backbone vision transformer.
  34. reassemble_factors (`list[float]`, *optional*, defaults to `[4, 2, 1, 0.5]`):
  35. The up/downsampling factors of the reassemble layers.
  36. post_process_channels (`list[int]`, *optional*, defaults to `[128, 256, 512, 1024]`):
  37. The output channel sizes of the reassemble stage for each backbone feature level.
  38. fusion_hidden_size (`int`, *optional*, defaults to 256):
  39. The number of channels before fusion.
  40. head_hidden_size (`int`, *optional*, defaults to 128):
  41. The number of channels in the hidden layer of the depth estimation head.
  42. number_output_channels (`int`, *optional*, defaults to 256):
  43. Number of output channels for the CHMv2 head (number of depth bins).
  44. readout_type (`str`, *optional*, defaults to `"project"`):
  45. Type of readout operation for the CLS token. One of `["ignore", "add", "project"]`.
  46. min_depth (`float`, *optional*, defaults to 0.001):
  47. The minimum depth value for depth bin calculation.
  48. max_depth (`float`, *optional*, defaults to 96.0):
  49. The maximum depth value for depth bin calculation.
  50. bins_strategy (`str`, *optional*, defaults to `"chmv2_mixlog"`):
  51. The strategy for depth bins distribution. One of `["linear", "log", "chmv2_mixlog"]`.
  52. norm_strategy (`str`, *optional*, defaults to `"chmv2_mixlog"`):
  53. The normalization strategy for depth prediction. One of `["linear", "softmax", "sigmoid", "chmv2_mixlog"]`.
  54. ```python
  55. >>> from transformers import CHMv2Config, CHMv2ForDepthEstimation
  56. >>> configuration = CHMv2Config()
  57. >>> model = CHMv2ForDepthEstimation(configuration)
  58. >>> configuration = model.config
  59. ```
  60. """
  61. model_type = "chmv2"
  62. sub_configs = {"backbone_config": AutoConfig}
  63. backbone_config: dict | PreTrainedConfig | None = None
  64. patch_size: int = 16
  65. initializer_range: float = 0.02
  66. reassemble_factors: list[float | int] | None = None
  67. post_process_channels: list[int] | None = None
  68. fusion_hidden_size: int = 256
  69. head_hidden_size: int = 128
  70. number_output_channels: int = 256
  71. readout_type: str = "project"
  72. min_depth: float = 0.001
  73. max_depth: float = 96.0
  74. bins_strategy: Literal["linear", "log", "chmv2_mixlog"] = "chmv2_mixlog"
  75. norm_strategy: Literal["linear", "softmax", "sigmoid", "chmv2_mixlog"] = "chmv2_mixlog"
  76. def __post_init__(self, **kwargs):
  77. if self.reassemble_factors is None:
  78. self.reassemble_factors = [4, 2, 1, 0.5]
  79. if self.post_process_channels is None:
  80. self.post_process_channels = [128, 256, 512, 1024]
  81. default_config_kwargs = {
  82. "image_size": 416,
  83. "hidden_size": 1024,
  84. "intermediate_size": 4096,
  85. "num_attention_heads": 16,
  86. "num_hidden_layers": 24,
  87. "num_register_tokens": 4,
  88. "key_bias": True,
  89. "out_indices": [6, 12, 18, 24],
  90. "reshape_hidden_states": True,
  91. "apply_layernorm": True,
  92. "layer_norm_eps": 1e-6,
  93. "return_class_token": True,
  94. }
  95. self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
  96. backbone_config=self.backbone_config,
  97. default_config_type="dinov3_vit",
  98. default_config_kwargs=default_config_kwargs,
  99. **kwargs,
  100. )
  101. super().__post_init__(**kwargs)
  102. __all__ = ["CHMv2Config"]