codingutf8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license van model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername vanpretrainedconfigarchivemap visualattentionnetworkvanbase https huggingface covisualattentionnetworkvanbaseblobmainconfig json class vanconfigpretrainedconfig r this is the configuration class to store the configuration of a vanmodel it is used to instantiate a van model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the van visualattentionnetworkvanbasehttps huggingface covisualattentionnetworkvanbase architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args imagesize int optional defaults to 224 the size resolution of each image numchannels int optional defaults to 3 the number of input channels patchsizes listint optional defaults to 7 3 3 3 patch size to use in each stage s embedding layer strides listint optional defaults to 4 2 2 2 stride size to use in each stage s embedding layer to downsample the input hiddensizes listint optional defaults to 64 128 320 512 dimensionality hidden size at each stage depths listint optional defaults to 3 3 12 3 depth number of layers for each stage mlpratios listint optional defaults to 8 8 4 4 the expansion ratio for mlp layer at each stage hiddenact str or function optional defaults to gelu the nonlinear activation function function or string in each layer if string gelu relu selu and gelunew are supported initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices layernormeps float optional defaults to 1e06 the epsilon used by the layer normalization layers layerscaleinitvalue float optional defaults to 0 01 the initial value for layer scaling droppathrate float optional defaults to 0 0 the dropout probability for stochastic depth dropoutrate float optional defaults to 0 0 the dropout probability for dropout example python from transformers import vanmodel vanconfig initializing a van vanbase style configuration configuration vanconfig initializing a model from the vanbase style configuration model vanmodelconfiguration accessing the model configuration configuration model config modeltype van def init self imagesize224 numchannels3 patchsizes7 3 3 3 strides4 2 2 2 hiddensizes64 128 320 512 depths3 3 12 3 mlpratios8 8 4 4 hiddenactgelu initializerrange0 02 layernormeps1e6 layerscaleinitvalue1e2 droppathrate0 0 dropoutrate0 0 kwargs super initkwargs self imagesize imagesize self numchannels numchannels self patchsizes patchsizes self strides strides self hiddensizes hiddensizes self depths depths self mlpratios mlpratios self hiddenact hiddenact self initializerrange initializerrange self layernormeps layernormeps self layerscaleinitvalue layerscaleinitvalue self droppathrate droppathrate self dropoutrate dropoutrate coding utf 8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license van model configuration this is the configuration class to store the configuration of a vanmodel it is used to instantiate a van model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the van visual attention network van base https huggingface co visual attention network van base architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args image_size int optional defaults to 224 the size resolution of each image num_channels int optional defaults to 3 the number of input channels patch_sizes list int optional defaults to 7 3 3 3 patch size to use in each stage s embedding layer strides list int optional defaults to 4 2 2 2 stride size to use in each stage s embedding layer to downsample the input hidden_sizes list int optional defaults to 64 128 320 512 dimensionality hidden size at each stage depths list int optional defaults to 3 3 12 3 depth number of layers for each stage mlp_ratios list int optional defaults to 8 8 4 4 the expansion ratio for mlp layer at each stage hidden_act str or function optional defaults to gelu the non linear activation function function or string in each layer if string gelu relu selu and gelu_new are supported initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices layer_norm_eps float optional defaults to 1e 06 the epsilon used by the layer normalization layers layer_scale_init_value float optional defaults to 0 01 the initial value for layer scaling drop_path_rate float optional defaults to 0 0 the dropout probability for stochastic depth dropout_rate float optional defaults to 0 0 the dropout probability for dropout example python from transformers import vanmodel vanconfig initializing a van van base style configuration configuration vanconfig initializing a model from the van base style configuration model vanmodel configuration accessing the model configuration configuration model config
from ....configuration_utils import PretrainedConfig
from ....utils import logging


logger = logging.get_logger(__name__)

VAN_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "Visual-Attention-Network/van-base": (
        "https://huggingface.co/Visual-Attention-Network/van-base/blob/main/config.json"
    ),
}


class VanConfig(PretrainedConfig):
    r

    model_type = "van"

    def __init__(
        self,
        image_size=224,
        num_channels=3,
        patch_sizes=[7, 3, 3, 3],
        strides=[4, 2, 2, 2],
        hidden_sizes=[64, 128, 320, 512],
        depths=[3, 3, 12, 3],
        mlp_ratios=[8, 8, 4, 4],
        hidden_act="gelu",
        initializer_range=0.02,
        layer_norm_eps=1e-6,
        layer_scale_init_value=1e-2,
        drop_path_rate=0.0,
        dropout_rate=0.0,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self.image_size = image_size
        self.num_channels = num_channels
        self.patch_sizes = patch_sizes
        self.strides = strides
        self.hidden_sizes = hidden_sizes
        self.depths = depths
        self.mlp_ratios = mlp_ratios
        self.hidden_act = hidden_act
        self.initializer_range = initializer_range
        self.layer_norm_eps = layer_norm_eps
        self.layer_scale_init_value = layer_scale_init_value
        self.drop_path_rate = drop_path_rate
        self.dropout_rate = dropout_rate