codingutf8 2023 meta platforms inc and 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 convnextv2 model configuration from configurationutils import pretrainedconfig from utils import logging from utils backboneutils import backboneconfigmixin getalignedoutputfeaturesoutputindices logger logging getloggername convnextv2pretrainedconfigarchivemap facebookconvnextv2tiny1k224 https huggingface cofacebookconvnextv2tiny1k224resolvemainconfig json class convnextv2configbackboneconfigmixin pretrainedconfig r this is the configuration class to store the configuration of a convnextv2model it is used to instantiate an convnextv2 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 convnextv2 facebookconvnextv2tiny1k224https huggingface cofacebookconvnextv2tiny1k224 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args numchannels int optional defaults to 3 the number of input channels patchsize int optional defaults to 4 patch size to use in the patch embedding layer numstages int optional defaults to 4 the number of stages in the model hiddensizes listint optional defaults to 96 192 384 768 dimensionality hidden size at each stage depths listint optional defaults to 3 3 9 3 depth number of blocks for each stage hiddenact str or function optional defaults to gelu the nonlinear activation function function or string in each block 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 1e12 the epsilon used by the layer normalization layers droppathrate float optional defaults to 0 0 the drop rate for stochastic depth outfeatures liststr optional if used as backbone list of features to output can be any of stem stage1 stage2 etc depending on how many stages the model has if unset and outindices is set will default to the corresponding stages if unset and outindices is unset will default to the last stage 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 if unset and outfeatures is set will default to the corresponding stages if unset and outfeatures is unset will default to the last stage example python from transformers import convnextv2config convnextv2model initializing a convnextv2 convnextv2tiny1k224 style configuration configuration convnextv2config initializing a model with random weights from the convnextv2tiny1k224 style configuration model convnextv2modelconfiguration accessing the model configuration configuration model config modeltype convnextv2 def init self numchannels3 patchsize4 numstages4 hiddensizesnone depthsnone hiddenactgelu initializerrange0 02 layernormeps1e12 droppathrate0 0 imagesize224 outfeaturesnone outindicesnone kwargs super initkwargs self numchannels numchannels self patchsize patchsize self numstages numstages self hiddensizes 96 192 384 768 if hiddensizes is none else hiddensizes self depths 3 3 9 3 if depths is none else depths self hiddenact hiddenact self initializerrange initializerrange self layernormeps layernormeps self droppathrate droppathrate self imagesize imagesize self stagenames stem fstageidx for idx in range1 lenself depths 1 self outfeatures self outindices getalignedoutputfeaturesoutputindices outfeaturesoutfeatures outindicesoutindices stagenamesself stagenames coding utf 8 2023 meta platforms inc and 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 convnextv2 model configuration this is the configuration class to store the configuration of a convnextv2model it is used to instantiate an convnextv2 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 convnextv2 facebook convnextv2 tiny 1k 224 https huggingface co facebook convnextv2 tiny 1k 224 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args num_channels int optional defaults to 3 the number of input channels patch_size int optional defaults to 4 patch size to use in the patch embedding layer num_stages int optional defaults to 4 the number of stages in the model hidden_sizes list int optional defaults to 96 192 384 768 dimensionality hidden size at each stage depths list int optional defaults to 3 3 9 3 depth number of blocks for each stage hidden_act str or function optional defaults to gelu the non linear activation function function or string in each block 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 12 the epsilon used by the layer normalization layers drop_path_rate float optional defaults to 0 0 the drop rate for stochastic depth out_features list str optional if used as backbone list of features to output can be any of stem stage1 stage2 etc depending on how many stages the model has if unset and out_indices is set will default to the corresponding stages if unset and out_indices is unset will default to the last stage 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 if unset and out_features is set will default to the corresponding stages if unset and out_features is unset will default to the last stage example python from transformers import convnextv2config convnextv2model initializing a convnextv2 convnextv2 tiny 1k 224 style configuration configuration convnextv2config initializing a model with random weights from the convnextv2 tiny 1k 224 style configuration model convnextv2model configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


logger = logging.get_logger(__name__)

CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "facebook/convnextv2-tiny-1k-224": "https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json",
}


class ConvNextV2Config(BackboneConfigMixin, PretrainedConfig):
    r

    model_type = "convnextv2"

    def __init__(
        self,
        num_channels=3,
        patch_size=4,
        num_stages=4,
        hidden_sizes=None,
        depths=None,
        hidden_act="gelu",
        initializer_range=0.02,
        layer_norm_eps=1e-12,
        drop_path_rate=0.0,
        image_size=224,
        out_features=None,
        out_indices=None,
        **kwargs,
    ):
        super().__init__(**kwargs)

        self.num_channels = num_channels
        self.patch_size = patch_size
        self.num_stages = num_stages
        self.hidden_sizes = [96, 192, 384, 768] if hidden_sizes is None else hidden_sizes
        self.depths = [3, 3, 9, 3] if depths is None else depths
        self.hidden_act = hidden_act
        self.initializer_range = initializer_range
        self.layer_norm_eps = layer_norm_eps
        self.drop_path_rate = drop_path_rate
        self.image_size = image_size
        self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.depths) + 1)]
        self._out_features, self._out_indices = get_aligned_output_features_output_indices(
            out_features=out_features, out_indices=out_indices, stage_names=self.stage_names
        )