Skip to content
data

ConvNeXtConfig

extendsModelConfig
ConvNeXtConfig(num_classes: int = 1000, in_channels: int = 3, depths: tuple[int, ...] = (3, 3, 9, 3), dims: tuple[int, ...] = (96, 192, 384, 768), layer_scale_init: float = 1e-06, layer_norm_eps: float = 1e-06, dropout: float = 0.0)

Configuration dataclass for every ConvNeXt variant.

ConvNeXtConfig is an immutable container that fully specifies the architecture of a ConvNeXt. It is consumed by both ConvNeXt (backbone) and ConvNeXtForImageClassification (classifier). All five canonical variants described in Liu et al. (2022) — Tiny / Small / Base / Large / XLarge — can be expressed by choosing different depths and dims.

Each ConvNeXt block applies a depthwise 7×77 \times 7 convolution followed by a LayerNorm and an inverted-bottleneck MLP, with a learnable per-channel layer scale γ\gamma on the residual branch:

x←x+γ⊙Linear4d→d ⁣(GELU ⁣(Lineard→4d ⁣(LN(DWConv7×7(x))))).x \leftarrow x + \gamma \odot \mathrm{Linear}_{4d \to d}\!\bigl( \mathrm{GELU}\!\bigl(\mathrm{Linear}_{d \to 4d}\!\bigl( \mathrm{LN}(\mathrm{DWConv}_{7 \times 7}(x))\bigr)\bigr)\bigr).

Parameters

num_classesint= 1000
Number of output classes for the classification head. Defaults to 1000 (ImageNet-1k).
in_channelsint= 3
Number of input image channels. Defaults to 3 (RGB).
depthstuple of int= (3, 3, 9, 3)
Number of ConvNeXt blocks in each of the four stages. Defaults to (3, 3, 9, 3) (ConvNeXt-T).
dimstuple of int= (96, 192, 384, 768)
Output channel width of each of the four stages. Defaults to (96, 192, 384, 768) (ConvNeXt-T).
layer_scale_initfloat= 1e-06
Initial value γ0\gamma_0 of the per-channel layer-scale parameter applied to every residual branch. Defaults to 1e-6 (Touvron et al., 2021).
dropoutfloat= 0.0
Maximum stochastic-depth rate; linearly scheduled across all blocks of the trunk (Liu et al., 2022, §3). Defaults to 0.0.

Attributes

model_typeClassVar[str]
Constant string "convnext" used by the model registry.

Notes

The canonical variants registered as factory functions in lucid.models.vision.convnext are:

================ ============= =================================== Variant depths dims ================ ============= =================================== ConvNeXt-T (3, 3, 9, 3) (96, 192, 384, 768) ConvNeXt-S (3, 3, 27, 3) (96, 192, 384, 768) ConvNeXt-B (3, 3, 27, 3) (128, 256, 512, 1024) ConvNeXt-L (3, 3, 27, 3) (192, 384, 768, 1536) ConvNeXt-XL (3, 3, 27, 3) (256, 512, 1024, 2048) ================ ============= ===================================

Reference: Zhuang Liu et al., "A ConvNet for the 2020s", CVPR 2022, arXiv:2201.03545.

Examples

Build a ConvNeXt-T configuration for CIFAR-10 (10 classes):
>>> from lucid.models.vision.convnext import ConvNeXtConfig
>>> cfg = ConvNeXtConfig(num_classes=10)
>>> cfg.depths, cfg.dims, cfg.num_classes
((3, 3, 9, 3), (96, 192, 384, 768), 10)

Used by 3