configuration_vitmatte.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright 2023 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. """VitMatte 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="hustvl/vitmatte-small-composition-1k")
  21. @strict
  22. class VitMatteConfig(PreTrainedConfig):
  23. r"""
  24. batch_norm_eps (`float`, *optional*, defaults to 1e-05):
  25. The epsilon used by the batch norm layers.
  26. convstream_hidden_sizes (`list[int]`, *optional*, defaults to `[48, 96, 192]`):
  27. The output channels of the ConvStream module.
  28. fusion_hidden_sizes (`list[int]`, *optional*, defaults to `[256, 128, 64, 32]`):
  29. The output channels of the Fusion blocks.
  30. Example:
  31. ```python
  32. >>> from transformers import VitMatteConfig, VitMatteForImageMatting
  33. >>> # Initializing a ViTMatte hustvl/vitmatte-small-composition-1k style configuration
  34. >>> configuration = VitMatteConfig()
  35. >>> # Initializing a model (with random weights) from the hustvl/vitmatte-small-composition-1k style configuration
  36. >>> model = VitMatteForImageMatting(configuration)
  37. >>> # Accessing the model configuration
  38. >>> configuration = model.config
  39. ```"""
  40. model_type = "vitmatte"
  41. sub_configs = {"backbone_config": AutoConfig}
  42. backbone_config: dict | PreTrainedConfig | None = None
  43. hidden_size: int = 384
  44. batch_norm_eps: float = 1e-5
  45. initializer_range: float = 0.02
  46. convstream_hidden_sizes: list[int] | tuple[int, ...] = (48, 96, 192)
  47. fusion_hidden_sizes: list[int] | tuple[int, ...] = (256, 128, 64, 32)
  48. def __post_init__(self, **kwargs):
  49. self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
  50. backbone_config=self.backbone_config,
  51. default_config_type="vitdet",
  52. default_config_kwargs={"out_features": ["stage4"]},
  53. **kwargs,
  54. )
  55. super().__post_init__(**kwargs)
  56. __all__ = ["VitMatteConfig"]