Skip to content
class

Xception

extendsPretrainedModelBackboneMixin_XceptionBody
Xception(config: XceptionConfig)

Xception feature-extracting backbone (no classification head).

Implements the "Extreme Inception" topology from Chollet, "Xception: Deep Learning with Depthwise Separable Convolutions", CVPR 2017 (arXiv:1610.02357). The architecture replaces every Inception module of Inception-v3 with a depthwise separable convolution — the limiting case of an Inception block in which every output channel of the pointwise convolution receives its own independent spatial filter. This makes the cross-channel and spatial correlations fully decoupled, dramatically reducing parameters and FLOPs:

DK2⋅M⋅N  ⟶  M⋅N  +  DK2⋅M.D_K^2 \cdot M \cdot N \;\longrightarrow\; M \cdot N \;+\; D_K^2 \cdot M.

The body is organised into three phases — entry flow (3 blocks, with 1×1 strided residuals and channel doubling from 64 → 728), middle flow (8 identical 728-ch blocks with additive identity shortcuts), and exit flow (1 strided transition block plus two final separable convolutions expanding to 1536 → 2048 channels). Designed for a 299×299 input — the same crop size as Inception-v3 — so the spatial-reduction schedule isolates the depthwise-separable factorisation as the sole source of accuracy improvement.

Parameters

Frozen architecture spec. Use the xception factory for the paper-cited configuration.

Attributes

Stored copy of the config that built this model.
conv1, conv2nn.Conv2d
Two 3×3 stem convolutions; conv1 carries stride 2.
BatchNorm layers paired with the stem convs.
block1, block2, block3nn.Module
Entry-flow blocks — strided 1×1 residual shortcuts with channel projections 64→128, 128→256, 256→728.
block4, …, block11nn.Module
Eight identical middle-flow blocks with additive identity shortcuts at 728 channels.
block12nn.Module
Exit-flow strided transition block (728 → 1024).
conv3, conv4_ExitSepConv
Final two separable convolutions expanding to 1536 and 2048 channels.
BatchNorm layers paired with conv3 and conv4.
Global average pool collapsing the 2048-ch feature map to (B, 2048, 1, 1).
feature_infolist[FeatureInfo]
Per-stage descriptor exposed via BackboneMixin.

Notes

Sub-module attribute names match timm's legacy_xception layout so that state-dict round-trips are key-compatible with standard pretrained weight files.

Examples

Build an Xception backbone and run a forward pass at the
native 299×299 resolution:
>>> import lucid
>>> from lucid.models.vision.xception import xception
>>> backbone = xception()
>>> x = lucid.randn(2, 3, 299, 299)
>>> out = backbone(x)
>>> out.last_hidden_state.shape   # 299 / 32, rounded up — not pooled
(2, 2048, 10, 10)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: XceptionConfig)

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.