DoruC/Grounded-Segment-Anything
0
1# coding=utf-82# Copyright 2021 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 at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# 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 and14# limitations under the License.15""" VisualBERT model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP = {24 "uclanlp/visualbert-vqa": "https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json",25 "uclanlp/visualbert-vqa-pre": "https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json",26 "uclanlp/visualbert-vqa-coco-pre": (27 "https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json"28 ),29 "uclanlp/visualbert-vcr": "https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json",30 "uclanlp/visualbert-vcr-pre": "https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json",31 "uclanlp/visualbert-vcr-coco-pre": (32 "https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json"33 ),34 "uclanlp/visualbert-nlvr2": "https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json",35 "uclanlp/visualbert-nlvr2-pre": "https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json",36 "uclanlp/visualbert-nlvr2-coco-pre": (37 "https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json"38 )39 # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert40}41 42 43class VisualBertConfig(PretrainedConfig):44 r"""45 This is the configuration class to store the configuration of a [`VisualBertModel`]. It is used to instantiate an46 VisualBERT model according to the specified arguments, defining the model architecture. Instantiating a47 configuration with the defaults will yield a similar configuration to that of the VisualBERT48 [uclanlp/visualbert-vqa-coco-pre](https://huggingface.co/uclanlp/visualbert-vqa-coco-pre) architecture.49 50 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the51 documentation from [`PretrainedConfig`] for more information.52 53 54 Args:55 vocab_size (`int`, *optional*, defaults to 30522):56 Vocabulary size of the VisualBERT model. Defines the number of different tokens that can be represented by57 the `inputs_ids` passed when calling [`VisualBertModel`]. Vocabulary size of the model. Defines the58 different tokens that can be represented by the `inputs_ids` passed to the forward method of59 [`VisualBertModel`].60 hidden_size (`int`, *optional*, defaults to 768):61 Dimensionality of the encoder layers and the pooler layer.62 visual_embedding_dim (`int`, *optional*, defaults to 512):63 Dimensionality of the visual embeddings to be passed to the model.64 num_hidden_layers (`int`, *optional*, defaults to 12):65 Number of hidden layers in the Transformer encoder.66 num_attention_heads (`int`, *optional*, defaults to 12):67 Number of attention heads for each attention layer in the Transformer encoder.68 intermediate_size (`int`, *optional*, defaults to 3072):69 Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.70 hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):71 The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,72 `"relu"`, `"selu"` and `"gelu_new"` are supported.73 hidden_dropout_prob (`float`, *optional*, defaults to 0.1):74 The dropout probabilitiy for all fully connected layers in the embeddings, encoder, and pooler.75 attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):76 The dropout ratio for the attention probabilities.77 max_position_embeddings (`int`, *optional*, defaults to 512):78 The maximum sequence length that this model might ever be used with. Typically set this to something large79 just in case (e.g., 512 or 1024 or 2048).80 type_vocab_size (`int`, *optional*, defaults to 2):81 The vocabulary size of the `token_type_ids` passed when calling [`VisualBertModel`].82 initializer_range (`float`, *optional*, defaults to 0.02):83 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.84 layer_norm_eps (`float`, *optional*, defaults to 1e-12):85 The epsilon used by the layer normalization layers.86 bypass_transformer (`bool`, *optional*, defaults to `False`):87 Whether or not the model should bypass the transformer for the visual embeddings. If set to `True`, the88 model directly concatenates the visual embeddings from [`VisualBertEmbeddings`] with text output from89 transformers, and then pass it to a self-attention layer.90 special_visual_initialize (`bool`, *optional*, defaults to `True`):91 Whether or not the visual token type and position type embedding weights should be initialized the same as92 the textual token type and positive type embeddings. When set to `True`, the weights of the textual token93 type and position type embeddings are copied to the respective visual embedding layers.94 95 96 Example:97 98 ```python99 >>> from transformers import VisualBertConfig, VisualBertModel100 101 >>> # Initializing a VisualBERT visualbert-vqa-coco-pre style configuration102 >>> configuration = VisualBertConfig.from_pretrained("uclanlp/visualbert-vqa-coco-pre")103 104 >>> # Initializing a model (with random weights) from the visualbert-vqa-coco-pre style configuration105 >>> model = VisualBertModel(configuration)106 107 >>> # Accessing the model configuration108 >>> configuration = model.config109 ```"""110 111 model_type = "visual_bert"112 113 def __init__(114 self,115 vocab_size=30522,116 hidden_size=768,117 visual_embedding_dim=512,118 num_hidden_layers=12,119 num_attention_heads=12,120 intermediate_size=3072,121 hidden_act="gelu",122 hidden_dropout_prob=0.1,123 attention_probs_dropout_prob=0.1,124 max_position_embeddings=512,125 type_vocab_size=2,126 initializer_range=0.02,127 layer_norm_eps=1e-12,128 bypass_transformer=False,129 special_visual_initialize=True,130 pad_token_id=1,131 bos_token_id=0,132 eos_token_id=2,133 **kwargs,134 ):135 super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)136 137 self.vocab_size = vocab_size138 self.max_position_embeddings = max_position_embeddings139 self.hidden_size = hidden_size140 self.visual_embedding_dim = visual_embedding_dim141 self.num_hidden_layers = num_hidden_layers142 self.num_attention_heads = num_attention_heads143 self.intermediate_size = intermediate_size144 self.hidden_act = hidden_act145 self.hidden_dropout_prob = hidden_dropout_prob146 self.attention_probs_dropout_prob = attention_probs_dropout_prob147 self.initializer_range = initializer_range148 self.type_vocab_size = type_vocab_size149 self.layer_norm_eps = layer_norm_eps150 self.bypass_transformer = bypass_transformer151 self.special_visual_initialize = special_visual_initialize152 