configuration_vitpose.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2024 The HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """VitPose model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...backbone_utils import consolidate_backbone_kwargs_to_config
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...utils import auto_docstring
  19. from ..auto.configuration_auto import AutoConfig
  20. @auto_docstring(checkpoint="usyd-community/vitpose-base-simple")
  21. @strict
  22. class VitPoseConfig(PreTrainedConfig):
  23. r"""
  24. scale_factor (`int`, *optional*, defaults to 4):
  25. Factor to upscale the feature maps coming from the ViT backbone.
  26. use_simple_decoder (`bool`, *optional*, defaults to `True`):
  27. Whether to use a `VitPoseSimpleDecoder` to decode the feature maps from the backbone into heatmaps. Otherwise it uses `VitPoseClassicDecoder`.
  28. Example:
  29. ```python
  30. >>> from transformers import VitPoseConfig, VitPoseForPoseEstimation
  31. >>> # Initializing a VitPose configuration
  32. >>> configuration = VitPoseConfig()
  33. >>> # Initializing a model (with random weights) from the configuration
  34. >>> model = VitPoseForPoseEstimation(configuration)
  35. >>> # Accessing the model configuration
  36. >>> configuration = model.config
  37. ```"""
  38. model_type = "vitpose"
  39. sub_configs = {"backbone_config": AutoConfig}
  40. backbone_config: dict | PreTrainedConfig | None = None
  41. initializer_range: float = 0.02
  42. scale_factor: int = 4
  43. use_simple_decoder: bool = True
  44. def __post_init__(self, **kwargs):
  45. self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
  46. backbone_config=self.backbone_config,
  47. default_config_type="vitpose_backbone",
  48. default_config_kwargs={"out_indices": [4]},
  49. **kwargs,
  50. )
  51. super().__post_init__(**kwargs)
  52. __all__ = ["VitPoseConfig"]