configuration_videomae.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # coding=utf-8
  2. # Copyright 2022 The HuggingFace Inc. team. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """VideoMAE model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class VideoMAEConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`VideoMAEModel`]. It is used to instantiate a
  22. VideoMAE model according to the specified arguments, defining the model architecture. Instantiating a configuration
  23. with the defaults will yield a similar configuration to that of the VideoMAE
  24. [MCG-NJU/videomae-base](https://huggingface.co/MCG-NJU/videomae-base) architecture.
  25. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  26. documentation from [`PretrainedConfig`] for more information.
  27. Args:
  28. image_size (`int`, *optional*, defaults to 224):
  29. The size (resolution) of each image.
  30. patch_size (`int`, *optional*, defaults to 16):
  31. The size (resolution) of each patch.
  32. num_channels (`int`, *optional*, defaults to 3):
  33. The number of input channels.
  34. num_frames (`int`, *optional*, defaults to 16):
  35. The number of frames in each video.
  36. tubelet_size (`int`, *optional*, defaults to 2):
  37. The number of tubelets.
  38. hidden_size (`int`, *optional*, defaults to 768):
  39. Dimensionality of the encoder layers and the pooler layer.
  40. num_hidden_layers (`int`, *optional*, defaults to 12):
  41. Number of hidden layers in the Transformer encoder.
  42. num_attention_heads (`int`, *optional*, defaults to 12):
  43. Number of attention heads for each attention layer in the Transformer encoder.
  44. intermediate_size (`int`, *optional*, defaults to 3072):
  45. Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  46. hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
  47. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  48. `"relu"`, `"selu"` and `"gelu_new"` are supported.
  49. hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
  50. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  51. attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):
  52. The dropout ratio for the attention probabilities.
  53. initializer_range (`float`, *optional*, defaults to 0.02):
  54. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  55. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  56. The epsilon used by the layer normalization layers.
  57. qkv_bias (`bool`, *optional*, defaults to `True`):
  58. Whether to add a bias to the queries, keys and values.
  59. use_mean_pooling (`bool`, *optional*, defaults to `True`):
  60. Whether to mean pool the final hidden states instead of using the final hidden state of the [CLS] token.
  61. decoder_num_attention_heads (`int`, *optional*, defaults to 6):
  62. Number of attention heads for each attention layer in the decoder.
  63. decoder_hidden_size (`int`, *optional*, defaults to 384):
  64. Dimensionality of the decoder.
  65. decoder_num_hidden_layers (`int`, *optional*, defaults to 4):
  66. Number of hidden layers in the decoder.
  67. decoder_intermediate_size (`int`, *optional*, defaults to 1536):
  68. Dimensionality of the "intermediate" (i.e., feed-forward) layer in the decoder.
  69. norm_pix_loss (`bool`, *optional*, defaults to `True`):
  70. Whether to normalize the target patch pixels.
  71. Example:
  72. ```python
  73. >>> from transformers import VideoMAEConfig, VideoMAEModel
  74. >>> # Initializing a VideoMAE videomae-base style configuration
  75. >>> configuration = VideoMAEConfig()
  76. >>> # Randomly initializing a model from the configuration
  77. >>> model = VideoMAEModel(configuration)
  78. >>> # Accessing the model configuration
  79. >>> configuration = model.config
  80. ```"""
  81. model_type = "videomae"
  82. def __init__(
  83. self,
  84. image_size=224,
  85. patch_size=16,
  86. num_channels=3,
  87. num_frames=16,
  88. tubelet_size=2,
  89. hidden_size=768,
  90. num_hidden_layers=12,
  91. num_attention_heads=12,
  92. intermediate_size=3072,
  93. hidden_act="gelu",
  94. hidden_dropout_prob=0.0,
  95. attention_probs_dropout_prob=0.0,
  96. initializer_range=0.02,
  97. layer_norm_eps=1e-12,
  98. qkv_bias=True,
  99. use_mean_pooling=True,
  100. decoder_num_attention_heads=6,
  101. decoder_hidden_size=384,
  102. decoder_num_hidden_layers=4,
  103. decoder_intermediate_size=1536,
  104. norm_pix_loss=True,
  105. **kwargs,
  106. ):
  107. super().__init__(**kwargs)
  108. self.image_size = image_size
  109. self.patch_size = patch_size
  110. self.num_channels = num_channels
  111. self.num_frames = num_frames
  112. self.tubelet_size = tubelet_size
  113. self.hidden_size = hidden_size
  114. self.num_hidden_layers = num_hidden_layers
  115. self.num_attention_heads = num_attention_heads
  116. self.intermediate_size = intermediate_size
  117. self.hidden_act = hidden_act
  118. self.hidden_dropout_prob = hidden_dropout_prob
  119. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  120. self.initializer_range = initializer_range
  121. self.layer_norm_eps = layer_norm_eps
  122. self.qkv_bias = qkv_bias
  123. self.use_mean_pooling = use_mean_pooling
  124. self.decoder_num_attention_heads = decoder_num_attention_heads
  125. self.decoder_hidden_size = decoder_hidden_size
  126. self.decoder_num_hidden_layers = decoder_num_hidden_layers
  127. self.decoder_intermediate_size = decoder_intermediate_size
  128. self.norm_pix_loss = norm_pix_loss
  129. __all__ = ["VideoMAEConfig"]