Skip to content
class

InceptionResNetV2

extendsPretrainedModelBackboneMixin
InceptionResNetV2(config: InceptionResNetConfig)

Inception-ResNet v2 feature-extracting backbone.

Implements the residual-Inception topology from Szegedy et al., "Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning", AAAI 2017. The body consists of three residual Inception block families — _Block35 (×10), _Block17 (×20), and _Block8 (×9 + 1 no-ReLU block) — separated by Reduction-A (_Mixed6a) and Reduction-B (_Mixed7a) blocks, with a leading Mixed_5b pre-block (_Mixed5b) and a final 1×11\times1 projection (conv2d_7b) to 1536 channels. Designed for 299×299299\times299 RGB inputs. State-dict naming matches the canonical timm / TensorFlow-Slim implementation so weight transfer is straightforward.

Parameters

Frozen architecture spec. Use inception_resnet_v2 for the paper-cited configuration with the recommended residual scale factors (0.17 / 0.10 / 0.20).

Attributes

Stored copy of the config that built this model.
conv2d_1a, conv2d_2a, conv2d_2b, conv2d_3b, conv2d_4ann.Module
Stem ConvBnReLU layers (TensorFlow-Slim naming preserved).
mixed_5b_Mixed5b
Pre-Block35 Inception block (192 → 320 channels) at 35×3535\times35.
Stack of 10 _Block35 residual Inception-A blocks.
mixed_6a_Mixed6a
Reduction-A block, 35×35→17×1735\times35 \to 17\times17, widening 320 → 1088 channels.
Stack of 20 _Block17 residual Inception-B blocks.
mixed_7a_Mixed7a
Reduction-B block, 17×17→8×817\times17 \to 8\times8, widening 1088 → 2080 channels.
Stack of 9 _Block8 residual Inception-C blocks.
block8_Block8
Final no-ReLU residual block (scale 1.0).
conv2d_7b_ConvBnReLU
1×11\times1 projection 2080 → 1536.
Global average pool to 1×11\times1.
feature_infolist[FeatureInfo]
Per-stage descriptor (channels + reduction factor) exposed via BackboneMixin.

Notes

Each residual Inception block computes

y=σ ⁣(x+α⋅Finception(x)),y = \sigma\!\left(x + \alpha \cdot \mathcal{F}_{\text{inception}}(x)\right),

with α\alpha a small fixed scale factor (0.10–0.20). The residual-scale trick was introduced specifically for Inception-ResNet because unscaled residuals caused training to diverge on networks with many filters per Inception module. Approximately 55.8 M parameters; achieves a top-5 ImageNet validation error of 3.08% in the original paper.

Examples

>>> import lucid
>>> from lucid.models.vision.inception_resnet import inception_resnet_v2
>>> backbone = inception_resnet_v2()
>>> x = lucid.randn(1, 3, 299, 299)
>>> out = backbone(x)
>>> out.last_hidden_state.shape   # (B, 1536, 1, 1)
(1, 1536, 8, 8)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: InceptionResNetConfig)

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.