Skip to content
class

ConvNeXt

extendsPretrainedModelBackboneMixin
ConvNeXt(config: ConvNeXtConfig)

ConvNeXt backbone (Liu et al., 2022).

ConvNeXt is a pure-convolutional backbone built by systematically modernising a ResNet using design choices borrowed from the Swin Transformer. The trunk is a four-stage pyramid that starts with a non-overlapping 4×44 \times 4 patchify stem and processes the feature map through stacks of identical ConvNeXt blocks:

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),

where γ∈Rd\gamma \in \mathbb{R}^d is a per-channel layer-scale parameter initialised to 10−610^{-6} (Touvron et al., 2021). Between stages a 2×22 \times 2 stride-2 LN + Conv2d downsampler halves the resolution and doubles the channel width.

forward_features returns a global-average-pooled (B,Cout)(B, C_{\text{out}}) feature where Cout=dims[-1]C_{\text{out}} = \texttt{dims[-1]}. Use this backbone when you want features for transfer learning or dense prediction; for end-to-end classification use ConvNeXtForImageClassification.

Parameters

Frozen dataclass specifying depths, dims, layer_scale_init, dropout, and in_channels. See ConvNeXtConfig.

Attributes

stem_StemWithNorm
Patchify stem: 4×44 \times 4 stride-4 Conv2d followed by a channel-last LayerNorm.
Four stages of stacked _ConvNeXtBlock modules.
downsamplersnn.ModuleList
Three between-stage LN + stride-2 Conv2d downsamplers.
head_normnn.LayerNorm
Final LayerNorm applied (channel-last) to the pooled feature.
1×11 \times 1 adaptive average pool over spatial dims.
feature_infolist[FeatureInfo]
Four-stage feature description with reductions (4,8,16,32)(4, 8, 16, 32) and channel counts from config.dims.

Notes

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

Examples

Build a ConvNeXt-T backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.convnext import ConvNeXt, ConvNeXtConfig
>>> model = ConvNeXt(ConvNeXtConfig())
>>> x = lucid.randn(1, 3, 224, 224)
>>> feat = model.forward_features(x)
>>> feat.shape                       # (B, dims[-1])
(1, 768)
>>> out = model(x)
>>> out.last_hidden_state.shape      # (B, 1, dims[-1])
(1, 1, 768)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: ConvNeXtConfig)

Properties

1
prop

stage_features

→list[Tensor]
stage_features: list[Tensor]

The four stage outputs from the last forward_features.

Ordered stem-to-deepest, so entry i corresponds to feature_info[i] — reductions 4, 8, 16 and 32. Empty until a forward pass has run.

Instance methods

2
fn

forward_features

→Tensor
forward_features(x: Tensor)

Pooled (B, C) feature vector, post head-norm.

The per-stage maps this backbone's feature_info describes are left on stage_features for pyramid consumers.