codingutf8 2023 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 vitmatte model configuration import copy from typing import list from configurationutils import pretrainedconfig from utils import logging from auto configurationauto import configmapping logger logging getloggername vitmattepretrainedconfigarchivemap hustvlvitmattesmallcomposition1k https huggingface cohustvlvitmattesmallcomposition1kresolvemainconfig json class vitmatteconfigpretrainedconfig r this is the configuration class to store the configuration of vitmatteforimagematting it is used to instantiate a vitmatte 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 vitmatte hustvlvitmattesmallcomposition1khttps huggingface cohustvlvitmattesmallcomposition1k architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args backboneconfig pretrainedconfig or dict optional defaults to vitdetconfig the configuration of the backbone model hiddensize int optional defaults to 384 the number of input channels of the decoder batchnormeps float optional defaults to 1e05 the epsilon used by the batch norm layers initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices convstreamhiddensizes listint optional defaults to 48 96 192 the output channels of the convstream module fusionhiddensizes listint optional defaults to 256 128 64 32 the output channels of the fusion blocks example python from transformers import vitmatteconfig vitmatteforimagematting initializing a vitmatte hustvlvitmattesmallcomposition1k style configuration configuration vitmatteconfig initializing a model with random weights from the hustvlvitmattesmallcomposition1k style configuration model vitmatteforimagemattingconfiguration accessing the model configuration configuration model config modeltype vitmatte def init self backboneconfig pretrainedconfig none hiddensize int 384 batchnormeps float 1e5 initializerrange float 0 02 convstreamhiddensizes listint 48 96 192 fusionhiddensizes listint 256 128 64 32 kwargs super initkwargs if backboneconfig is none logger infobackboneconfig is none initializing the config with the default vitdet backbone backboneconfig configmappingvitdetoutfeaturesstage4 elif isinstancebackboneconfig dict backbonemodeltype backboneconfig getmodeltype configclass configmappingbackbonemodeltype backboneconfig configclass fromdictbackboneconfig self backboneconfig backboneconfig self batchnormeps batchnormeps self hiddensize hiddensize self initializerrange initializerrange self convstreamhiddensizes convstreamhiddensizes self fusionhiddensizes fusionhiddensizes def todictself output copy deepcopyself dict outputbackboneconfig self backboneconfig todict outputmodeltype self class modeltype return output coding utf 8 2023 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 vitmatte model configuration this is the configuration class to store the configuration of vitmatteforimagematting it is used to instantiate a vitmatte 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 vitmatte hustvl vitmatte small composition 1k https huggingface co hustvl vitmatte small composition 1k architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args backbone_config pretrainedconfig or dict optional defaults to vitdetconfig the configuration of the backbone model hidden_size int optional defaults to 384 the number of input channels of the decoder batch_norm_eps float optional defaults to 1e 05 the epsilon used by the batch norm layers initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices convstream_hidden_sizes list int optional defaults to 48 96 192 the output channels of the convstream module fusion_hidden_sizes list int optional defaults to 256 128 64 32 the output channels of the fusion blocks example python from transformers import vitmatteconfig vitmatteforimagematting initializing a vitmatte hustvl vitmatte small composition 1k style configuration configuration vitmatteconfig initializing a model with random weights from the hustvl vitmatte small composition 1k style configuration model vitmatteforimagematting configuration accessing the model configuration configuration model config serializes this instance to a python dictionary override the default pretrainedconfig to_dict returns dict str any dictionary of all the attributes that make up this configuration instance
import copy
from typing import List

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


logger = logging.get_logger(__name__)

VITMATTE_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "hustvl/vitmatte-small-composition-1k": "https://huggingface.co/hustvl/vitmatte-small-composition-1k/resolve/main/config.json",
}


class VitMatteConfig(PretrainedConfig):
    r

    model_type = "vitmatte"

    def __init__(
        self,
        backbone_config: PretrainedConfig = None,
        hidden_size: int = 384,
        batch_norm_eps: float = 1e-5,
        initializer_range: float = 0.02,
        convstream_hidden_sizes: List[int] = [48, 96, 192],
        fusion_hidden_sizes: List[int] = [256, 128, 64, 32],
        **kwargs,
    ):
        super().__init__(**kwargs)

        if backbone_config is None:
            logger.info("`backbone_config` is `None`. Initializing the config with the default `VitDet` backbone.")
            backbone_config = CONFIG_MAPPING["vitdet"](out_features=["stage4"])
        elif isinstance(backbone_config, dict):
            backbone_model_type = backbone_config.get("model_type")
            config_class = CONFIG_MAPPING[backbone_model_type]
            backbone_config = config_class.from_dict(backbone_config)

        self.backbone_config = backbone_config
        self.batch_norm_eps = batch_norm_eps
        self.hidden_size = hidden_size
        self.initializer_range = initializer_range
        self.convstream_hidden_sizes = convstream_hidden_sizes
        self.fusion_hidden_sizes = fusion_hidden_sizes

    def to_dict(self):
        
        output = copy.deepcopy(self.__dict__)
        output["backbone_config"] = self.backbone_config.to_dict()
        output["model_type"] = self.__class__.model_type
        return output