CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
configuration_mgp_str.py138 linesDownload Raw Back to mgp_str
1# coding=utf-82# Copyright 2023 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"""MGP-STR model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class MgpstrConfig(PretrainedConfig):25    r"""26    This is the configuration class to store the configuration of an [`MgpstrModel`]. It is used to instantiate an27    MGP-STR model according to the specified arguments, defining the model architecture. Instantiating a configuration28    with the defaults will yield a similar configuration to that of the MGP-STR29    [alibaba-damo/mgp-str-base](https://huggingface.co/alibaba-damo/mgp-str-base) architecture.30 31    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the32    documentation from [`PretrainedConfig`] for more information.33 34    Args:35        image_size (`list[int]`, *optional*, defaults to `[32, 128]`):36            The size (resolution) of each image.37        patch_size (`int`, *optional*, defaults to 4):38            The size (resolution) of each patch.39        num_channels (`int`, *optional*, defaults to 3):40            The number of input channels.41        max_token_length (`int`, *optional*, defaults to 27):42            The max number of output tokens.43        num_character_labels (`int`, *optional*, defaults to 38):44            The number of classes for character head .45        num_bpe_labels (`int`, *optional*, defaults to 50257):46            The number of classes for bpe head .47        num_wordpiece_labels (`int`, *optional*, defaults to 30522):48            The number of classes for wordpiece head .49        hidden_size (`int`, *optional*, defaults to 768):50            The embedding dimension.51        num_hidden_layers (`int`, *optional*, defaults to 12):52            Number of hidden layers in the Transformer encoder.53        num_attention_heads (`int`, *optional*, defaults to 12):54            Number of attention heads for each attention layer in the Transformer encoder.55        mlp_ratio (`float`, *optional*, defaults to 4.0):56            The ratio of mlp hidden dim to embedding dim.57        qkv_bias (`bool`, *optional*, defaults to `True`):58            Whether to add a bias to the queries, keys and values.59        distilled (`bool`, *optional*, defaults to `False`):60            Model includes a distillation token and head as in DeiT models.61        layer_norm_eps (`float`, *optional*, defaults to 1e-05):62            The epsilon used by the layer normalization layers.63        drop_rate (`float`, *optional*, defaults to 0.0):64            The dropout probability for all fully connected layers in the embeddings, encoder.65        attn_drop_rate (`float`, *optional*, defaults to 0.0):66            The dropout ratio for the attention probabilities.67        drop_path_rate (`float`, *optional*, defaults to 0.0):68            The stochastic depth rate.69        output_a3_attentions (`bool`, *optional*, defaults to `False`):70            Whether or not the model should returns A^3 module attentions.71        initializer_range (`float`, *optional*, defaults to 0.02):72            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.73 74    Example:75 76    ```python77    >>> from transformers import MgpstrConfig, MgpstrForSceneTextRecognition78 79    >>> # Initializing a Mgpstr mgp-str-base style configuration80    >>> configuration = MgpstrConfig()81 82    >>> # Initializing a model (with random weights) from the mgp-str-base style configuration83    >>> model = MgpstrForSceneTextRecognition(configuration)84 85    >>> # Accessing the model configuration86    >>> configuration = model.config87    ```"""88 89    model_type = "mgp-str"90 91    def __init__(92        self,93        image_size=[32, 128],94        patch_size=4,95        num_channels=3,96        max_token_length=27,97        num_character_labels=38,98        num_bpe_labels=50257,99        num_wordpiece_labels=30522,100        hidden_size=768,101        num_hidden_layers=12,102        num_attention_heads=12,103        mlp_ratio=4.0,104        qkv_bias=True,105        distilled=False,106        layer_norm_eps=1e-5,107        drop_rate=0.0,108        attn_drop_rate=0.0,109        drop_path_rate=0.0,110        output_a3_attentions=False,111        initializer_range=0.02,112        **kwargs,113    ):114        super().__init__(**kwargs)115 116        self.image_size = image_size117        self.patch_size = patch_size118        self.num_channels = num_channels119        self.max_token_length = max_token_length120        self.num_character_labels = num_character_labels121        self.num_bpe_labels = num_bpe_labels122        self.num_wordpiece_labels = num_wordpiece_labels123        self.hidden_size = hidden_size124        self.num_hidden_layers = num_hidden_layers125        self.num_attention_heads = num_attention_heads126        self.mlp_ratio = mlp_ratio127        self.distilled = distilled128        self.layer_norm_eps = layer_norm_eps129        self.drop_rate = drop_rate130        self.qkv_bias = qkv_bias131        self.attn_drop_rate = attn_drop_rate132        self.drop_path_rate = drop_path_rate133        self.output_a3_attentions = output_a3_attentions134        self.initializer_range = initializer_range135 136 137__all__ = ["MgpstrConfig"]138 
Aluode/PerceptionLabPortable · CoolFace