configuration_convnext.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. """ConvNeXT model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...backbone_utils import BackboneConfigMixin
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...utils import auto_docstring
  19. @auto_docstring(checkpoint="facebook/convnext-tiny-224")
  20. @strict
  21. class ConvNextConfig(BackboneConfigMixin, PreTrainedConfig):
  22. r"""
  23. num_stages (`int`, *optional*, defaults to 4):
  24. The number of stages in the model.
  25. Example:
  26. ```python
  27. >>> from transformers import ConvNextConfig, ConvNextModel
  28. >>> # Initializing a ConvNext convnext-tiny-224 style configuration
  29. >>> configuration = ConvNextConfig()
  30. >>> # Initializing a model (with random weights) from the convnext-tiny-224 style configuration
  31. >>> model = ConvNextModel(configuration)
  32. >>> # Accessing the model configuration
  33. >>> configuration = model.config
  34. ```"""
  35. model_type = "convnext"
  36. num_channels: int = 3
  37. patch_size: int | list[int] | tuple[int, int] = 4
  38. num_stages: int = 4
  39. hidden_sizes: list[int] | tuple[int, ...] | None = (96, 192, 384, 768)
  40. depths: list[int] | tuple[int, ...] | None = (3, 3, 9, 3)
  41. hidden_act: str = "gelu"
  42. initializer_range: float = 0.02
  43. layer_norm_eps: float = 1e-12
  44. layer_scale_init_value: float = 1e-6
  45. drop_path_rate: float | int = 0.0
  46. image_size: int | list[int] | tuple[int, int] = 224
  47. _out_features: list[str] | None = None
  48. _out_indices: list[int] | None = None
  49. def __post_init__(self, **kwargs):
  50. self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.depths) + 1)]
  51. self.set_output_features_output_indices(
  52. out_indices=kwargs.pop("out_indices", None), out_features=kwargs.pop("out_features", None)
  53. )
  54. super().__post_init__(**kwargs)
  55. __all__ = ["ConvNextConfig"]