Xception: Deep Learning with Depthwise Separable Convolutions
- Publication
- CVPR 2017Conference
- First submitted to arXiv
- arXiv:1610.02357
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{classiccnnsxception2016,
title = {{Xception: Deep Learning with Depthwise Separable Convolutions}},
author = {François Chollet},
year = {2016},
eprint = {1610.02357},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1610.02357}
}
By 2016, Inception was already in its fourth generation, from GoogLeNet, through Inception-v2 with BN added and Inception-v3 with factorized convolutions, all the way to Inception-ResNet with residuals wired in. Every generation ranked near the top on ImageNet, but the modules grew more complicated each time, with branches, channel counts, and kernel shapes all needing to be tuned one by one.
François Chollet, the creator of Keras, was at Google at the time. He wanted to understand why Inception modules work, how they differ from ordinary convolutions, and where things could go after Inception.
This paper is his answer.
Defining the Problem
In an ordinary convolutional layer, each kernel is a 3D filter, with a channel dimension on top of width and height. A kernel looking at 256 input channels has weights, and it handles at the same time the relationships between different channels at the same position (cross-channel correlations) and the relationships between neighboring positions (spatial correlations).
The Inception module handles these two things separately. It first uses a few convolutions to deal with cross-channel relationships, projecting the input into 3 or 4 smaller spaces, then uses or convolutions within each smaller space to deal with spatial relationships.
The author calls the idea behind this design the Inception hypothesis, namely that cross-channel correlations and spatial correlations are independent enough that handling them separately works better than handling them together.
If “partly separating them” works, what about separating them more thoroughly?
Solving the Problem
Inception from Another Angle
The author first simplifies the Inception module, keeping only one kind of convolution, , and removing the average-pooling branch. That leaves three branches, each a followed by a .
These three convolutions all look at the same input, so they can be merged into a single convolution with more output channels. After the merge, each of the three convolutions handles its own segment of those output channels:

The two forms are exactly equivalent. PyTorch's groups=3 means exactly “split the channels into three segments and convolve each one separately,” so this simplified Inception module is really just a convolution plus a convolution split into three groups.
Seen this way, the simplified Inception module has only one number left to tune, the number of segments the channels are split into.
Splitting All the Way
The more segments, the fewer channels in each. Taken to the extreme, each segment has just one channel, and every output channel gets a convolution of its own:

Fix the channels at 96 and raise the number of segments from 1 to 96: the layer's weight shape goes from (96, 96, 3, 3) to (96, 1, 3, 3), and its parameters drop from 82,944 to 864. The second number in the weight shape is how many input channels each kernel can see. groups=1 is an ordinary convolution, with every kernel seeing all 96 channels; at groups=96, each kernel sees only one channel, leaving just the spatial .
The author views this whole series as a spectrum. At one end is an ordinary convolution (preceded by a ), with a single segment; at the other end, there is one segment per channel. Inception modules sit in between, splitting a few hundred channels into 3 or 4 segments.
The Other End of the Spectrum
The author points out that the extreme module at the other end of the spectrum is almost identical to an operation that already existed, the depthwise separable convolution. It works in two steps:
- Depthwise convolution: each input channel gets its own spatial convolution, with no exchange between channels.
- Pointwise convolution: a convolution projects the previous step's output onto a new channel space.
This is what TensorFlow and Keras call a separable convolution. Image processing also uses the name separable convolution, for spatial factorizations such as splitting a into a and a , which Inception-v3 used; don't mix the two up.
There are still two small differences between the “extreme” Inception module and the depthwise separable convolution:
- Order. A depthwise separable convolution does the depthwise step first, then the ; Inception does the first. The author considers this unimportant, because networks are built by stacking layers, so one module's is followed by the next module's depthwise step, and the order differs only at the two ends.
- Whether there's a nonlinearity in between. In Inception, both steps are followed by ReLU; a depthwise separable convolution usually has no activation function between its two steps. The author thinks this one might matter and leaves it for the experiments.
Xception
Since the Inception hypothesis says that “cross-channel and spatial relationships can be partly separated,” the author goes all the way with a stronger hypothesis, that the two can be completely separated. The network based on this hypothesis is built entirely from depthwise separable convolutions and is named Xception, after Extreme Inception.

Data moves through three sections from left to right. The entry flow starts from a image; the first two layers are ordinary convolutions, followed by three modules, each of which halves the feature map and widens the channels, ending at . The middle flow repeats the same module 8 times without changing the size. The exit flow shrinks it once more and raises the channels to 2048, and global average pooling is followed by the classification layer.
The whole network has 36 convolutional layers organized into 14 modules, and every module except the first and the last is wrapped by a residual connection. Modules that don't shrink the feature map use an identity shortcut; those that do put a stride-2 convolution on the shortcut.
Compared with Inception-v3, this diagram is much simpler, just depthwise separable convolutions and residual connections stacked layer by layer; the author says it takes only 30 to 40 lines in Keras. Let's build it in PyTorch following the figure:
import torch
import torch.nn as nn
class SeparableConv(nn.Sequential):
"""Per-channel 3×3 convolution followed by a 1×1 convolution; no activation function in between, BN at the end"""
def __init__(self, cin, cout):
super().__init__(
nn.Conv2d(cin, cin, 3, padding=1, groups=cin, bias=False), # depthwise
nn.Conv2d(cin, cout, 1, bias=False), # pointwise
nn.BatchNorm2d(cout))
class Block(nn.Module):
def __init__(self, cin, widths, relu_first=True, downsample=True):
super().__init__()
layers, c = [], cin
for i, w in enumerate(widths):
if relu_first or i > 0:
layers.append(nn.ReLU())
layers.append(SeparableConv(c, w))
c = w
if downsample:
layers.append(nn.MaxPool2d(3, 2, padding=1))
self.shortcut = nn.Sequential(nn.Conv2d(cin, c, 1, 2, bias=False), nn.BatchNorm2d(c))
else:
self.shortcut = nn.Identity()
self.body = nn.Sequential(*layers)
def forward(self, x):
return self.body(x) + self.shortcut(x)
def conv_bn_relu(cin, cout, stride):
return nn.Sequential(nn.Conv2d(cin, cout, 3, stride, bias=False), nn.BatchNorm2d(cout), nn.ReLU())
entry = nn.Sequential(conv_bn_relu(3, 32, 2), conv_bn_relu(32, 64, 1),
Block(64, [128, 128], relu_first=False), Block(128, [256, 256]), Block(256, [728, 728]))
middle = nn.Sequential(*[Block(728, [728, 728, 728], downsample=False) for _ in range(8)])
exit_ = nn.Sequential(Block(728, [728, 1024]),
SeparableConv(1024, 1536), nn.ReLU(), SeparableConv(1536, 2048), nn.ReLU(),
nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(2048, 1000))
model = nn.Sequential(entry, middle, exit_)
x = torch.randn(1, 3, 299, 299)
for name, part in [("entry flow", entry), ("middle flow", middle)]:
x = part(x)
print(f"After {name}:", tuple(x.shape[1:]))
print("After exit flow:", tuple(exit_(x).shape[1:]))
params = sum(p.numel() for p in model.parameters())
print(f"Parameters: {params:,}")
After entry flow: (728, 19, 19)
After middle flow: (728, 19, 19)
After exit flow: (1000,)
Parameters: 22,855,952
The parameter count is exactly the 22,855,952 reported in the paper. PyTorch has no ready-made separable convolution layer; as above, a convolution with groups set to the number of input channels, followed by a convolution, does the job. Keras has SeparableConv2D built in, and Xception itself is included in Keras Applications.
Following the details in the figure, each SeparableConv has a ReLU in front and BN behind, with nothing between the depthwise and pointwise steps. The first SeparableConv of the entry flow's first residual module has no ReLU in front, because the Conv 64 before it already ends with a ReLU; in the last two layers of the exit flow, the ReLU comes after.
Discussion
The author compares against Inception-v3 because the two have almost the same number of parameters, so any gap can't be attributed to model capacity. The comparison is run on two datasets:
- ImageNet: single-label classification over 1000 classes.
- JFT: an internal Google dataset of over 350 million high-resolution images in 17,000 classes, where each image can have multiple labels. Evaluation uses a separate set of 14,000 images, FastEval14k, averaging 36.5 labels per image; the metric is MAP@100 over the top 100 predictions, weighted by how common each class is on social media.
Both networks use the same training setup, one carefully tuned for Inception-v3, and the author didn't tune it separately for Xception. The one exception is weight decay, where Inception-v3's 4e-5 is clearly poor for Xception, so 1e-5 is used instead. All models are trained on 60 NVIDIA K80 GPUs; each ImageNet run takes about 3 days, and each JFT run over a month, without being trained to convergence.
ImageNet
| Network | Top-1 accuracy | Top-5 accuracy |
|---|---|---|
| VGG-16 | 0.715 | 0.901 |
| ResNet-152 | 0.770 | 0.933 |
| Inception-v3 | 0.782 | 0.941 |
| Xception | 0.790 | 0.945 |
Xception is 0.8 percentage points higher than Inception-v3, a small gap. VGG-16 and ResNet-152 are there only for reference.
JFT
| Network | FastEval14k MAP@100 |
|---|---|
| Inception-v3, no fully connected layers | 6.36 |
| Xception, no fully connected layers | 6.70 |
| Inception-v3, with fully connected layers | 6.50 |
| Xception, with fully connected layers | 6.78 |
On JFT the gap is much larger, a 4.3% relative improvement for the versions with fully connected layers. The author's explanation is that Inception-v3 was developed with ImageNet in mind, so its design may already be overfit to that dataset, while neither network was tuned for JFT.
Similar Parameters, a Bit Slower
| Network | Parameters | Training steps per second |
|---|---|---|
| Inception-v3 | 23,626,728 | 31 |
| Xception | 22,855,952 | 28 |
The two differ in parameter count by less than 3.5%, so the author says Xception's gains come from using its parameters more efficiently, not from added capacity.
In speed, Xception is actually a little slower. Depthwise convolutions have few parameters and little computation, but on GPUs it's hard to get a matching speedup out of them.
Residual Connections
The author also trained a version of Xception with all the residual connections removed. On ImageNet, the version without residuals converges much more slowly and ends at clearly lower accuracy.
The author also cautions that the non-residual version used the same training setup, which may not be quite fair to it, and that this only shows residual connections matter for this particular architecture. Separately, he tried VGG-style networks with every convolution replaced by a depthwise separable convolution and no residuals at all, and on JFT they likewise beat an Inception-v3 with the same parameter count.
An Activation in Between?
Back to the question left open earlier. Should there be a nonlinearity between the depthwise and pointwise steps? The author tried three options, none, ReLU, and ELU:

The red line, with no activation function at all, converges fastest and ends with the highest accuracy; the green line with ELU is in the middle, and the blue line with ReLU is the worst.
This is the opposite of what the Inception-v3 paper found. When Inception-v3 factorized a into two layers, it found that adding ReLU in between worked better. The author's guess is that the key lies in how “thick” the feature space is in which the spatial convolution operates. In an Inception module, each segment has dozens to hundreds of channels, and the nonlinearity helps; in a depthwise separable convolution, each segment has just one channel, and when ReLU chops off the negative values, information may simply be lost.
MobileNetV2 later removed ReLU from the narrowest layers of the network, on the same grounds that “nonlinearities in low-dimensional spaces lose information”; you can continue with MobileNet-V2.
Conclusion
Xception looks at Inception from a new angle. Simplified, an Inception module is just a convolution plus a convolution split into a few groups; turn the group count from 1 up to the number of channels, and you go from an ordinary convolution to a depthwise separable convolution. Xception goes straight to the end, with almost the same parameter count as Inception-v3, slightly better on ImageNet and quite a bit better on JFT.
It may be called Extreme Inception, but there's nothing extreme about its speed; it even manages 3 fewer training steps per second than Inception-v3. The author expected it to pull ahead once depthwise convolution implementations were optimized. That wait lasted years, and EfficientNetV2 eventually just replaced the depthwise convolutions in the early part of the network.
As for whether the end is the best place to be, even the author wasn't sure; in his closing section he writes that some points in the middle of the spectrum might be better. A little over a month later, ResNeXt used convolutions split into 32 groups, landing right in the middle.