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 configuration for backbone models from configurationutils import pretrainedconfig from utils import logging logger logging getloggername class timmbackboneconfigpretrainedconfig r this is the configuration class to store the configuration for a timm backbone timmbackbone it is used to instantiate a timm backbone model according to the specified arguments defining the model configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args backbone str optional the timm checkpoint to load numchannels int optional defaults to 3 the number of input channels featuresonly bool optional defaults to true whether to output only the features or also the logits usepretrainedbackbone bool optional defaults to true whether to use a pretrained backbone outindices listint optional if used as backbone list of indices of features to output can be any of 0 1 2 etc depending on how many stages the model has will default to the last stage if unset freezebatchnorm2d bool optional defaults to false converts all batchnorm2d and syncbatchnorm layers of provided module into frozenbatchnorm2d example python from transformers import timmbackboneconfig timmbackbone initializing a timm backbone configuration timmbackboneconfigresnet50 initializing a model from the configuration model timmbackboneconfiguration accessing the model configuration configuration model config 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 configuration for backbone models this is the configuration class to store the configuration for a timm backbone timmbackbone it is used to instantiate a timm backbone model according to the specified arguments defining the model configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args backbone str optional the timm checkpoint to load num_channels int optional defaults to 3 the number of input channels features_only bool optional defaults to true whether to output only the features or also the logits use_pretrained_backbone bool optional defaults to true whether to use a pretrained backbone out_indices list int optional if used as backbone list of indices of features to output can be any of 0 1 2 etc depending on how many stages the model has will default to the last stage if unset freeze_batch_norm_2d bool optional defaults to false converts all batchnorm2d and syncbatchnorm layers of provided module into frozenbatchnorm2d example python from transformers import timmbackboneconfig timmbackbone initializing a timm backbone configuration timmbackboneconfig resnet50 initializing a model from the configuration model timmbackbone configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging


logger = logging.get_logger(__name__)


class TimmBackboneConfig(PretrainedConfig):
    r

    model_type = "timm_backbone"

    def __init__(
        self,
        backbone=None,
        num_channels=3,
        features_only=True,
        use_pretrained_backbone=True,
        out_indices=None,
        freeze_batch_norm_2d=False,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self.backbone = backbone
        self.num_channels = num_channels
        self.features_only = features_only
        self.use_pretrained_backbone = use_pretrained_backbone
        self.use_timm_backbone = True
        self.out_indices = out_indices if out_indices is not None else (-1,)
        self.freeze_batch_norm_2d = freeze_batch_norm_2d