configuration_glpn.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright 2022 KAIST and 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. """GLPN model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="vinvino02/glpn-kitti")
  19. @strict
  20. class GLPNConfig(PreTrainedConfig):
  21. r"""
  22. num_encoder_blocks (`int`, *optional*, defaults to 4):
  23. The number of encoder blocks (i.e. stages in the Mix Transformer encoder).
  24. depths (`list[int]`, *optional*, defaults to `[2, 2, 2, 2]`):
  25. The number of layers in each encoder block.
  26. sr_ratios (`list[int]`, *optional*, defaults to `[8, 4, 2, 1]`):
  27. Sequence reduction ratios in each encoder block.
  28. patch_sizes (`list[int]`, *optional*, defaults to `[7, 3, 3, 3]`):
  29. Patch size before each encoder block.
  30. strides (`list[int]`, *optional*, defaults to `[4, 2, 2, 2]`):
  31. Stride before each encoder block.
  32. num_attention_heads (`list[int]`, *optional*, defaults to `[1, 2, 5, 8]`):
  33. Number of attention heads for each attention layer in each block of the Transformer encoder.
  34. mlp_ratios (`list[int]`, *optional*, defaults to `[4, 4, 4, 4]`):
  35. Ratio of the size of the hidden layer compared to the size of the input layer of the Mix FFNs in the
  36. encoder blocks.
  37. decoder_hidden_size (`int`, *optional*, defaults to 64):
  38. The dimension of the decoder.
  39. max_depth (`int`, *optional*, defaults to 10):
  40. The maximum depth of the decoder.
  41. head_in_index (`int`, *optional*, defaults to -1):
  42. The index of the features to use in the head.
  43. Example:
  44. ```python
  45. >>> from transformers import GLPNModel, GLPNConfig
  46. >>> # Initializing a GLPN vinvino02/glpn-kitti style configuration
  47. >>> configuration = GLPNConfig()
  48. >>> # Initializing a model from the vinvino02/glpn-kitti style configuration
  49. >>> model = GLPNModel(configuration)
  50. >>> # Accessing the model configuration
  51. >>> configuration = model.config
  52. ```"""
  53. model_type = "glpn"
  54. num_channels: int = 3
  55. num_encoder_blocks: int = 4
  56. depths: list[int] | tuple[int, ...] = (2, 2, 2, 2)
  57. sr_ratios: list[int] | tuple[int, ...] = (8, 4, 2, 1)
  58. hidden_sizes: list[int] | tuple[int, ...] = (32, 64, 160, 256)
  59. patch_sizes: list[int] | tuple[int, ...] = (7, 3, 3, 3)
  60. strides: list[int] | tuple[int, ...] = (4, 2, 2, 2)
  61. num_attention_heads: list[int] | tuple[int, ...] = (1, 2, 5, 8)
  62. mlp_ratios: list[int] | tuple[int, ...] = (4, 4, 4, 4)
  63. hidden_act: str = "gelu"
  64. hidden_dropout_prob: float | int = 0.0
  65. attention_probs_dropout_prob: float | int = 0.0
  66. initializer_range: float = 0.02
  67. drop_path_rate: float | int = 0.1
  68. layer_norm_eps: float = 1e-6
  69. decoder_hidden_size: int = 64
  70. max_depth: int = 10
  71. head_in_index: int = -1
  72. __all__ = ["GLPNConfig"]