Skip to content
class

ResNeXt

extendsPretrainedModelBackboneMixin
ResNeXt(config: ResNeXtConfig)

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 7×77\times7 stride-2 stem, a 3×33\times3 stride-2 max-pool, then four stages of _ResNeXtBottleneck blocks producing feature maps at strides 4, 8, 16, 32. Microscopically different: the 3×33\times3 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

Frozen architecture spec. Use the factory functions (resnext_50_32x4d, resnext_101_32x8d, …) for paper-cited configurations.

Attributes

Stored copy of the config that built this model.
Conv 7×77\times7 stride-2 → BatchNorm → ReLU.
3×33\times3 stride-2 max-pool (further reduces spatial size to H/4×W/4H/4 \times W/4).
layer1, layer2, layer3, layer4nn.Sequential
The four residual stages of _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]
Per-stage descriptor (channels + reduction factor) exposed via BackboneMixin.

Notes

A ResNeXt block of cardinality CC computes

y=x+∑i=1CTi(x),y = x + \sum_{i=1}^{C} \mathcal{T}_i(x),

where each Ti\mathcal{T}_i is a low-dimensional 1×1→3×3→1×11\times1 \to 3\times3 \to 1\times1 bottleneck. This "split-transform-merge" pattern is implemented as a single bottleneck with a groups=C 3×33\times3 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

1
dunder

__init__

→None
__init__(config: ResNeXtConfig)

Instance methods

2
fn

forward_features

→Tensor
forward_features(x: Tensor)

Run the backbone's feature-extraction pass.

Parameters

Input image batch, shape (B, C, H, W).

Returns

Tensor

Feature 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.