configuration_regnet.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2022 Meta Platforms, Inc. 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. """RegNet 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="facebook/regnet-y-040")
  19. @strict
  20. class RegNetConfig(PreTrainedConfig):
  21. r"""
  22. groups_width (`int`, *optional*, defaults to 64):
  23. Width of group for each stage.
  24. layer_type (`str`, *optional*, defaults to `"y"`):
  25. The layer to use, it can be either `"x" or `"y"`. An `x` layer is a ResNet's BottleNeck layer with
  26. `reduction` fixed to `1`. While a `y` layer is a `x` but with squeeze and excitation. Please refer to the
  27. paper for a detailed explanation of how these layers were constructed.
  28. downsample_in_first_stage (`bool`, *optional*, defaults to `False`):
  29. If `True`, the first stage will downsample the inputs using a `stride` of 2.
  30. Example:
  31. ```python
  32. >>> from transformers import RegNetConfig, RegNetModel
  33. >>> # Initializing a RegNet regnet-y-40 style configuration
  34. >>> configuration = RegNetConfig()
  35. >>> # Initializing a model from the regnet-y-40 style configuration
  36. >>> model = RegNetModel(configuration)
  37. >>> # Accessing the model configuration
  38. >>> configuration = model.config
  39. ```
  40. """
  41. model_type = "regnet"
  42. layer_types = ["x", "y"]
  43. num_channels: int = 3
  44. embedding_size: int = 32
  45. hidden_sizes: list[int] | tuple[int, ...] = (128, 192, 512, 1088)
  46. depths: list[int] | tuple[int, ...] = (2, 6, 12, 2)
  47. groups_width: int = 64
  48. layer_type: str = "y"
  49. hidden_act: str = "relu"
  50. downsample_in_first_stage: bool = True
  51. def validate_architecture(self):
  52. """Part of `@strict`-powered validation. Validates the architecture of the config."""
  53. if self.layer_type not in self.layer_types:
  54. raise ValueError(f"layer_type={self.layer_type} is not one of {','.join(self.layer_types)}")
  55. __all__ = ["RegNetConfig"]