Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2023 Meta Platforms, Inc. and The HuggingFace Inc. team. All rights reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""ConvNeXTV2 model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices20 21 22logger = logging.get_logger(__name__)23 24 25class ConvNextV2Config(BackboneConfigMixin, PretrainedConfig):26 r"""27 This is the configuration class to store the configuration of a [`ConvNextV2Model`]. It is used to instantiate an28 ConvNeXTV2 model according to the specified arguments, defining the model architecture. Instantiating a29 configuration with the defaults will yield a similar configuration to that of the ConvNeXTV230 [facebook/convnextv2-tiny-1k-224](https://huggingface.co/facebook/convnextv2-tiny-1k-224) architecture.31 32 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the33 documentation from [`PretrainedConfig`] for more information.34 35 Args:36 num_channels (`int`, *optional*, defaults to 3):37 The number of input channels.38 patch_size (`int`, *optional*, defaults to 4):39 Patch size to use in the patch embedding layer.40 num_stages (`int`, *optional*, defaults to 4):41 The number of stages in the model.42 hidden_sizes (`list[int]`, *optional*, defaults to `[96, 192, 384, 768]`):43 Dimensionality (hidden size) at each stage.44 depths (`list[int]`, *optional*, defaults to `[3, 3, 9, 3]`):45 Depth (number of blocks) for each stage.46 hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):47 The non-linear activation function (function or string) in each block. If string, `"gelu"`, `"relu"`,48 `"selu"` and `"gelu_new"` are supported.49 initializer_range (`float`, *optional*, defaults to 0.02):50 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.51 layer_norm_eps (`float`, *optional*, defaults to 1e-12):52 The epsilon used by the layer normalization layers.53 drop_path_rate (`float`, *optional*, defaults to 0.0):54 The drop rate for stochastic depth.55 image_size (`int`, *optional*, defaults to 224):56 The size (resolution) of each image.57 out_features (`list[str]`, *optional*):58 If used as backbone, list of features to output. Can be any of `"stem"`, `"stage1"`, `"stage2"`, etc.59 (depending on how many stages the model has). If unset and `out_indices` is set, will default to the60 corresponding stages. If unset and `out_indices` is unset, will default to the last stage. Must be in the61 same order as defined in the `stage_names` attribute.62 out_indices (`list[int]`, *optional*):63 If used as backbone, list of indices of features to output. Can be any of 0, 1, 2, etc. (depending on how64 many stages the model has). If unset and `out_features` is set, will default to the corresponding stages.65 If unset and `out_features` is unset, will default to the last stage. Must be in the66 same order as defined in the `stage_names` attribute.67 68 Example:69 ```python70 >>> from transformers import ConvNeXTV2Config, ConvNextV2Model71 72 >>> # Initializing a ConvNeXTV2 convnextv2-tiny-1k-224 style configuration73 >>> configuration = ConvNeXTV2Config()74 75 >>> # Initializing a model (with random weights) from the convnextv2-tiny-1k-224 style configuration76 >>> model = ConvNextV2Model(configuration)77 78 >>> # Accessing the model configuration79 >>> configuration = model.config80 ```"""81 82 model_type = "convnextv2"83 84 def __init__(85 self,86 num_channels=3,87 patch_size=4,88 num_stages=4,89 hidden_sizes=None,90 depths=None,91 hidden_act="gelu",92 initializer_range=0.02,93 layer_norm_eps=1e-12,94 drop_path_rate=0.0,95 image_size=224,96 out_features=None,97 out_indices=None,98 **kwargs,99 ):100 super().__init__(**kwargs)101 102 self.num_channels = num_channels103 self.patch_size = patch_size104 self.num_stages = num_stages105 self.hidden_sizes = [96, 192, 384, 768] if hidden_sizes is None else hidden_sizes106 self.depths = [3, 3, 9, 3] if depths is None else depths107 self.hidden_act = hidden_act108 self.initializer_range = initializer_range109 self.layer_norm_eps = layer_norm_eps110 self.drop_path_rate = drop_path_rate111 self.image_size = image_size112 self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.depths) + 1)]113 self._out_features, self._out_indices = get_aligned_output_features_output_indices(114 out_features=out_features, out_indices=out_indices, stage_names=self.stage_names115 )116 117 118__all__ = ["ConvNextV2Config"]119 