configuration_mobilevit.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright 2022 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. """MobileViT 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="google/mobilenet_v2_1.0_224")
  19. @strict
  20. class MobileViTConfig(PreTrainedConfig):
  21. r"""
  22. neck_hidden_sizes (`list[int]`, *optional*, defaults to `[16, 32, 64, 96, 128, 160, 640]`):
  23. The number of channels for the feature maps of the backbone.
  24. aspp_out_channels (`int`, *optional*, defaults to 256):
  25. Number of output channels used in the ASPP layer for semantic segmentation.
  26. atrous_rates (`list[int]`, *optional*, defaults to `[6, 12, 18]`):
  27. Dilation (atrous) factors used in the ASPP layer for semantic segmentation.
  28. aspp_dropout_prob (`float`, *optional*, defaults to 0.1):
  29. The dropout ratio for the ASPP layer for semantic segmentation.
  30. Example:
  31. ```python
  32. >>> from transformers import MobileViTConfig, MobileViTModel
  33. >>> # Initializing a mobilevit-small style configuration
  34. >>> configuration = MobileViTConfig()
  35. >>> # Initializing a model from the mobilevit-small style configuration
  36. >>> model = MobileViTModel(configuration)
  37. >>> # Accessing the model configuration
  38. >>> configuration = model.config
  39. ```"""
  40. model_type = "mobilevit"
  41. num_channels: int = 3
  42. image_size: int | list[int] | tuple[int, int] = 256
  43. patch_size: int | list[int] | tuple[int, int] = 2
  44. hidden_sizes: list[int] | tuple[int, ...] = (144, 192, 240)
  45. neck_hidden_sizes: list[int] | tuple[int, ...] = (16, 32, 64, 96, 128, 160, 640)
  46. num_attention_heads: int = 4
  47. mlp_ratio: float = 2.0
  48. expand_ratio: float = 4.0
  49. hidden_act: str = "silu"
  50. conv_kernel_size: int = 3
  51. output_stride: int = 32
  52. hidden_dropout_prob: float | int = 0.1
  53. attention_probs_dropout_prob: float | int = 0.0
  54. classifier_dropout_prob: float | int = 0.1
  55. initializer_range: float = 0.02
  56. layer_norm_eps: float = 1e-5
  57. qkv_bias: bool = True
  58. aspp_out_channels: int = 256
  59. atrous_rates: list[int] | tuple[int, ...] = (6, 12, 18)
  60. aspp_dropout_prob: float | int = 0.1
  61. semantic_loss_ignore_index: int = 255
  62. __all__ = ["MobileViTConfig"]