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 upernet model configuration from configurationutils import pretrainedconfig from utils import logging from auto configurationauto import configmapping logger logging getloggername class upernetconfigpretrainedconfig r this is the configuration class to store the configuration of an upernetforsemanticsegmentation it is used to instantiate an upernet 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 upernet openmmlabupernetconvnexttinyhttps huggingface coopenmmlabupernetconvnexttiny 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 resnetconfig the configuration of the backbone model hiddensize int optional defaults to 512 the number of hidden units in the convolutional layers initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices poolscales tupleint optional defaults to 1 2 3 6 pooling scales used in pooling pyramid module applied on the last feature map useauxiliaryhead bool optional defaults to true whether to use an auxiliary head during training auxiliarylossweight float optional defaults to 0 4 weight of the crossentropy loss of the auxiliary head auxiliarychannels int optional defaults to 256 number of channels to use in the auxiliary head auxiliarynumconvs int optional defaults to 1 number of convolutional layers to use in the auxiliary head auxiliaryconcatinput bool optional defaults to false whether to concatenate the output of the auxiliary head with the input before the classification layer lossignoreindex int optional defaults to 255 the index that is ignored by the loss function examples python from transformers import upernetconfig upernetforsemanticsegmentation initializing a configuration configuration upernetconfig initializing a model with random weights from the configuration model upernetforsemanticsegmentationconfiguration accessing the model configuration configuration model config modeltype upernet def init self backboneconfignone hiddensize512 initializerrange0 02 poolscales1 2 3 6 useauxiliaryheadtrue auxiliarylossweight0 4 auxiliaryinchannels384 auxiliarychannels256 auxiliarynumconvs1 auxiliaryconcatinputfalse lossignoreindex255 kwargs super initkwargs if backboneconfig is none logger infobackboneconfig is none initializing the config with the default resnet backbone backboneconfig configmappingresnetoutfeaturesstage1 stage2 stage3 stage4 elif isinstancebackboneconfig dict backbonemodeltype backboneconfig getmodeltype configclass configmappingbackbonemodeltype backboneconfig configclass fromdictbackboneconfig self backboneconfig backboneconfig self hiddensize hiddensize self initializerrange initializerrange self poolscales poolscales self useauxiliaryhead useauxiliaryhead self auxiliarylossweight auxiliarylossweight self auxiliaryinchannels auxiliaryinchannels self auxiliarychannels auxiliarychannels self auxiliarynumconvs auxiliarynumconvs self auxiliaryconcatinput auxiliaryconcatinput self lossignoreindex lossignoreindex 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 upernet model configuration this is the configuration class to store the configuration of an upernetforsemanticsegmentation it is used to instantiate an upernet 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 upernet openmmlab upernet convnext tiny https huggingface co openmmlab upernet convnext tiny 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 resnetconfig the configuration of the backbone model hidden_size int optional defaults to 512 the number of hidden units in the convolutional layers initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices pool_scales tuple int optional defaults to 1 2 3 6 pooling scales used in pooling pyramid module applied on the last feature map use_auxiliary_head bool optional defaults to true whether to use an auxiliary head during training auxiliary_loss_weight float optional defaults to 0 4 weight of the cross entropy loss of the auxiliary head auxiliary_channels int optional defaults to 256 number of channels to use in the auxiliary head auxiliary_num_convs int optional defaults to 1 number of convolutional layers to use in the auxiliary head auxiliary_concat_input bool optional defaults to false whether to concatenate the output of the auxiliary head with the input before the classification layer loss_ignore_index int optional defaults to 255 the index that is ignored by the loss function examples python from transformers import upernetconfig upernetforsemanticsegmentation initializing a configuration configuration upernetconfig initializing a model with random weights from the configuration model upernetforsemanticsegmentation configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


logger = logging.get_logger(__name__)


class UperNetConfig(PretrainedConfig):
    r

    model_type = "upernet"

    def __init__(
        self,
        backbone_config=None,
        hidden_size=512,
        initializer_range=0.02,
        pool_scales=[1, 2, 3, 6],
        use_auxiliary_head=True,
        auxiliary_loss_weight=0.4,
        auxiliary_in_channels=384,
        auxiliary_channels=256,
        auxiliary_num_convs=1,
        auxiliary_concat_input=False,
        loss_ignore_index=255,
        **kwargs,
    ):
        super().__init__(**kwargs)

        if backbone_config is None:
            logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.")
            backbone_config = CONFIG_MAPPING["resnet"](out_features=["stage1", "stage2", "stage3", "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.hidden_size = hidden_size
        self.initializer_range = initializer_range
        self.pool_scales = pool_scales
        self.use_auxiliary_head = use_auxiliary_head
        self.auxiliary_loss_weight = auxiliary_loss_weight
        self.auxiliary_in_channels = auxiliary_in_channels
        self.auxiliary_channels = auxiliary_channels
        self.auxiliary_num_convs = auxiliary_num_convs
        self.auxiliary_concat_input = auxiliary_concat_input
        self.loss_ignore_index = loss_ignore_index