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 patchify stem and processes the feature map through stacks of identical ConvNeXt blocks:
where is a per-channel layer-scale parameter initialised to (Touvron et al., 2021). Between stages a stride-2 LN + Conv2d downsampler halves the resolution and doubles the channel width.
forward_features returns a global-average-pooled
feature where
. Use this backbone when
you want features for transfer learning or dense prediction; for
end-to-end classification use
ConvNeXtForImageClassification.
Parameters
configConvNeXtConfigdepths, dims,
layer_scale_init, dropout, and in_channels. See
ConvNeXtConfig.Attributes
stem_StemWithNormstagesnn.ModuleList_ConvNeXtBlock modules.downsamplersnn.ModuleListhead_normnn.LayerNormavgpoolnn.AdaptiveAvgPool2dfeature_infolist[FeatureInfo]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)