# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/hgnet_v2/modular_hgnet_v2.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_hgnet_v2.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2025 Baidu Inc and The HuggingFace Inc. team. # # 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 collections.abc import Sequence from huggingface_hub.dataclasses import strict from ...backbone_utils import BackboneConfigMixin from ...configuration_utils import PreTrainedConfig from ...utils import auto_docstring # TODO: Modular conversion for resnet must be fixed as # it provides incorrect import for configuration like resnet_resnet @auto_docstring(checkpoint="ustc-community/dfine_x_coco") @strict class HGNetV2Config(BackboneConfigMixin, PreTrainedConfig): r""" stem_channels (`list[int]`, *optional*, defaults to `[3, 32, 48]`): Channel dimensions for the stem layers: - First number (3) is input image channels - Second number (32) is intermediate stem channels - Third number (48) is output stem channels stem_strides (`Sequence[int | list[int] | tuple[int, ...]]`, *optional*, defaults to `(2, 1, 1, 2, 1)`): Stride patterns for the stem layers. stage_in_channels (`list[int]`, *optional*, defaults to `[48, 128, 512, 1024]`): Input channel dimensions for each stage of the backbone. This defines how many channels the input to each stage will have. stage_mid_channels (`list[int]`, *optional*, defaults to `[48, 96, 192, 384]`): Mid-channel dimensions for each stage of the backbone. This defines the number of channels used in the intermediate layers of each stage. stage_out_channels (`list[int]`, *optional*, defaults to `[128, 512, 1024, 2048]`): Output channel dimensions for each stage of the backbone. This defines how many channels the output of each stage will have. stage_num_blocks (`list[int]`, *optional*, defaults to `[1, 1, 3, 1]`): Number of blocks to be used in each stage of the backbone. This controls the depth of each stage by specifying how many convolutional blocks to stack. stage_downsample (`list[bool]`, *optional*, defaults to `[False, True, True, True]`): Indicates whether to downsample the feature maps at each stage. If `True`, the spatial dimensions of the feature maps will be reduced. stage_downsample_strides (`Sequence[int | list[int] | tuple[int, ...]]`, *optional*, defaults to `(2, 2, 2, 2)`): Stride patterns for each stage layer. stage_light_block (`list[bool]`, *optional*, defaults to `[False, False, True, True]`): Indicates whether to use light blocks in each stage. Light blocks are a variant of convolutional blocks that may have fewer parameters. stage_kernel_size (`list[int]`, *optional*, defaults to `[3, 3, 5, 5]`): Kernel sizes for the convolutional layers in each stage. stage_numb_of_layers (`list[int]`, *optional*, defaults to `[6, 6, 6, 6]`): Number of layers to be used in each block of the stage. use_learnable_affine_block (`bool`, *optional*, defaults to `False`): Whether to use Learnable Affine Blocks (LAB) in the network. LAB adds learnable scale and bias parameters after certain operations. """ model_type = "hgnet_v2" num_channels: int = 3 embedding_size: int = 64 depths: list[int] | tuple[int, ...] = (3, 4, 6, 3) hidden_sizes: list[int] | tuple[int, ...] = (256, 512, 1024, 2048) hidden_act: str = "relu" _out_features: list[str] | None = None _out_indices: list[int] | None = None stem_channels: list[int] | tuple[int, ...] = (3, 32, 48) stem_strides: Sequence[int | list[int] | tuple[int, ...]] = (2, 1, 1, 2, 1) stage_in_channels: list[int] | tuple[int, ...] = (48, 128, 512, 1024) stage_mid_channels: list[int] | tuple[int, ...] = (48, 96, 192, 384) stage_out_channels: list[int] | tuple[int, ...] = (128, 512, 1024, 2048) stage_num_blocks: list[int] | tuple[int, ...] = (1, 1, 3, 1) stage_downsample: list[bool] | tuple[bool, ...] = (False, True, True, True) stage_downsample_strides: Sequence[int | list[int] | tuple[int, ...]] = (2, 2, 2, 2) stage_light_block: list[bool] | tuple[bool, ...] = (False, False, True, True) stage_kernel_size: list[int] | tuple[int, ...] = (3, 3, 5, 5) stage_numb_of_layers: list[int] | tuple[int, ...] = (6, 6, 6, 6) use_learnable_affine_block: bool = False initializer_range: float = 0.02 def __post_init__(self, **kwargs): self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.depths) + 1)] self.set_output_features_output_indices( out_indices=kwargs.pop("out_indices", None), out_features=kwargs.pop("out_features", None) ) self.hidden_sizes = list(self.hidden_sizes) super().__post_init__(**kwargs) def validate_architecture(self): """Part of `@strict`-powered validation. Validates the architecture of the config.""" if not ( len(self.stage_in_channels) == len(self.stage_mid_channels) == len(self.stage_out_channels) == len(self.stage_num_blocks) == len(self.stage_downsample) == len(self.stage_light_block) == len(self.stage_kernel_size) == len(self.stage_numb_of_layers) ): raise ValueError("All stage configuration lists must have the same length.") __all__ = ["HGNetV2Config"]