configuration_convnextv2.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2023 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. """ConvNeXTV2 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/convnextv2-tiny-1k-224")
  20. @strict
  21. class ConvNextV2Config(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 ConvNeXTV2Config, ConvNextV2Model
  28. >>> # Initializing a ConvNeXTV2 convnextv2-tiny-1k-224 style configuration
  29. >>> configuration = ConvNeXTV2Config()
  30. >>> # Initializing a model (with random weights) from the convnextv2-tiny-1k-224 style configuration
  31. >>> model = ConvNextV2Model(configuration)
  32. >>> # Accessing the model configuration
  33. >>> configuration = model.config
  34. ```"""
  35. model_type = "convnextv2"
  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. drop_path_rate: float | int = 0.0
  45. image_size: int | list[int] | tuple[int, int] = 224
  46. _out_features: list[str] | None = None
  47. _out_indices: list[int] | None = None
  48. def __post_init__(self, **kwargs):
  49. self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.depths) + 1)]
  50. self.set_output_features_output_indices(
  51. out_indices=kwargs.pop("out_indices", None), out_features=kwargs.pop("out_features", None)
  52. )
  53. super().__post_init__(**kwargs)
  54. __all__ = ["ConvNextV2Config"]