ConvNeXtForImageClassification
ImageClassificationModelClassificationHeadMixinConvNeXtForImageClassification(config: ConvNeXtConfig)ConvNeXt with a linear classification head (Liu et al., 2022).
Wraps the same four-stage trunk as ConvNeXt (patchify stem
→ four stages of ConvNeXt blocks with between-stage downsamplers)
and adds a global average pool, a final channel-last LayerNorm, and
a single nn.Linear classification head:
Pass labels to forward to compute the cross-entropy
loss in the same pass.
Parameters
configConvNeXtConfignum_classes to the
desired number of output categories (default 1000 for
ImageNet-1k). See ConvNeXtConfig.Attributes
stem_StemWithNormstagesnn.ModuleListdownsamplersnn.ModuleListhead_normnn.LayerNormavgpoolnn.AdaptiveAvgPool2dclassifiernn.Linear(num_classes, dims[-1]).Notes
Reference: Zhuang Liu et al., "A ConvNet for the 2020s", CVPR 2022. ConvNeXt-T / S / B / L reach 82.1 / 83.1 / 83.8 / 84.3 % top-1 on ImageNet-1k (Table 1 upper block, 224x224) — matching or exceeding Swin at equal FLOPs. There is no ImageNet-1k-only XL row: XL appears only among the 22k-pretrained models (87.0 at 224x224). The 85.5 previously attributed to XL is ConvNeXt-L at 384x384.
Examples
End-to-end inference with the default ConvNeXt-T classifier:
>>> import lucid
>>> from lucid.models.vision.convnext import (
... ConvNeXtConfig, ConvNeXtForImageClassification,
... )
>>> model = ConvNeXtForImageClassification(ConvNeXtConfig())
>>> x = lucid.randn(1, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(1, 1000)Used by 2
Constructors
1Instance methods
1forward(x: Tensor, labels: Tensor | None = None)