ResNeXt feature-extracting backbone (no classification head).
Implements the grouped-convolution residual topology from Xie et
al., "Aggregated Residual Transformations for Deep Neural
Networks", CVPR 2017. Macroscopically identical to ResNet-50+ — a
stride-2 stem, a stride-2
max-pool, then four stages of _ResNeXtBottleneck blocks
producing feature maps at strides 4, 8, 16, 32. Microscopically
different: the convolution inside each bottleneck
is grouped into config.cardinality groups of
config.width_per_group channels each, which is mathematically
equivalent to summing the outputs of cardinality parallel
low-dimensional residual branches.
Parameters
configResNeXtConfigresnext_50_32x4d, resnext_101_32x8d, …) for
paper-cited configurations.Attributes
configResNeXtConfigstemnn.Sequentialmaxpoolnn.MaxPool2dlayer1, layer2, layer3, layer4nn.Sequential_ResNeXtBottleneck blocks.
layer1 keeps the input spatial size; layer2 / layer3
/ layer4 each halve it. All four end with 2048 channels
(same as ResNet-50+ — only the internal width changes).feature_ infolist[FeatureInfo]BackboneMixin.Notes
A ResNeXt block of cardinality computes
where each is a low-dimensional
bottleneck. This
"split-transform-merge" pattern is implemented as a single
bottleneck with a groups=C convolution — a
one-line change versus ResNet but a substantial accuracy gain at
matched FLOPs. ResNeXt-50 (32x4d) outperforms ResNet-50 by roughly
one percentage point on ImageNet top-1 at the same compute budget.
Examples
Build a ResNeXt-50 (32x4d) backbone:
>>> import lucid
>>> from lucid.models.vision.resnext import resnext_50_32x4d
>>> backbone = resnext_50_32x4d()
>>> x = lucid.randn(1, 3, 224, 224)
>>> out = backbone(x)
>>> out.last_hidden_state.shape # (B, 2048, 7, 7)
(1, 2048, 7, 7)Used by 2
Constructors
1Instance methods
2forward(x: Tensor)Override in subclasses to define the computation.
Run the backbone's feature-extraction pass.
Parameters
(B, C, H, W).Returns
TensorFeature map at the deepest stage. Concrete subclasses may additionally stash earlier stages on the instance so multi-stage consumers can fetch them.
Examples
The map returned is the one feature_info lists last, so a
neck can size itself from that entry without running the model.
>>> import lucid
>>> from lucid.models import create_model
>>> backbone = create_model("resnet_18").eval()
>>> last = backbone.feature_info[-1]
>>> last.num_channels, last.reduction
(512, 32)
>>> backbone.forward_features(lucid.randn((1, 3, 64, 96))).shape
(1, 512, 2, 3)
Each side is divided by the advertised reduction on its own, so
a non-square input keeps its aspect ratio.