configuration_mobilevitv2.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. """MobileViTV2 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="apple/mobilevitv2-1.0")
  19. @strict
  20. class MobileViTV2Config(PreTrainedConfig):
  21. r"""
  22. aspp_out_channels (`int`, *optional*, defaults to 512):
  23. Number of output channels used in the ASPP layer for semantic segmentation.
  24. atrous_rates (`list[int]`, *optional*, defaults to `[6, 12, 18]`):
  25. Dilation (atrous) factors used in the ASPP layer for semantic segmentation.
  26. aspp_dropout_prob (`float`, *optional*, defaults to 0.1):
  27. The dropout ratio for the ASPP layer for semantic segmentation.
  28. n_attn_blocks (`list[int]`, *optional*, defaults to `[2, 4, 3]`):
  29. The number of attention blocks in each MobileViTV2Layer
  30. base_attn_unit_dims (`list[int]`, *optional*, defaults to `[128, 192, 256]`):
  31. The base multiplier for dimensions of attention blocks in each MobileViTV2Layer
  32. width_multiplier (`float`, *optional*, defaults to 1.0):
  33. The width multiplier for MobileViTV2.
  34. ffn_multiplier (`int`, *optional*, defaults to 2):
  35. The FFN multiplier for MobileViTV2.
  36. ffn_dropout (`float`, *optional*, defaults to 0.0):
  37. The dropout between FFN layers.
  38. Example:
  39. ```python
  40. >>> from transformers import MobileViTV2Config, MobileViTV2Model
  41. >>> # Initializing a mobilevitv2-small style configuration
  42. >>> configuration = MobileViTV2Config()
  43. >>> # Initializing a model from the mobilevitv2-small style configuration
  44. >>> model = MobileViTV2Model(configuration)
  45. >>> # Accessing the model configuration
  46. >>> configuration = model.config
  47. ```"""
  48. model_type = "mobilevitv2"
  49. num_channels: int = 3
  50. image_size: int | list[int] | tuple[int, int] = 256
  51. patch_size: int | list[int] | tuple[int, int] = 2
  52. expand_ratio: float = 2.0
  53. hidden_act: str = "swish"
  54. conv_kernel_size: int = 3
  55. output_stride: int = 32
  56. classifier_dropout_prob: float | int = 0.1
  57. initializer_range: float = 0.02
  58. layer_norm_eps: float = 1e-5
  59. aspp_out_channels: int = 512
  60. atrous_rates: list[int] | tuple[int, ...] = (6, 12, 18)
  61. aspp_dropout_prob: float | int = 0.1
  62. semantic_loss_ignore_index: int = 255
  63. n_attn_blocks: list[int] | tuple[int, ...] = (2, 4, 3)
  64. base_attn_unit_dims: list[int] | tuple[int, ...] = (128, 192, 256)
  65. width_multiplier: float | int = 1.0
  66. ffn_multiplier: int = 2
  67. attn_dropout: float | int = 0.0
  68. ffn_dropout: float | int = 0.0
  69. __all__ = ["MobileViTV2Config"]