Paper commentary
Context Encoders: Feature Learning by Inpainting
Context encoders learn visual features by filling in missing image regions
- Problem Autoencoders and denoising autoencoders learn from small, local corruptions, so their task needs little semantic understanding of the scene. Nearby pixels give away most of the answer.
- Method Context Encoders are CNNs that fill a missing image region from its surroundings. They use an encoder-decoder with a channel-wise fully-connected layer, trained with reconstruction plus adversarial loss.
- Results The joint-loss model reached a mean L2 error of 1.96%, compared to 6.92% for HOG nearest-neighbor inpainting. Its features also raised classification accuracy to 56.5%, against 53.8% for an autoencoder.
Why small corruptions teach little
An autoencoder squeezes an image through a low-dimensional bottleneck and rebuilds it. The code can then end up compressing pixels without capturing what the scene contains. Denoising autoencoders repair a corrupted input, but the corruption is usually small and local. Nearby pixels give away most of the answer, so the network needs little semantic knowledge to succeed.
Other self-supervised methods use a different question, such as where one patch sits relative to another. Doersch et al. ask whether patch A lies above or below patch B, which is one choice among 8. The authors instead ask for pixel intensities that fill the hole, a much richer target of roughly 15,000 real values per training example. That richer target is what pushes the network toward semantic content rather than low-level cues.
Encoder-decoder with a channel-wise bridge
The model is an encoder-decoder: the encoder reads the image with the hole, and the decoder writes the missing pixels. The encoder is AlexNet's first five convolutional layers plus pool5, trained from scratch with random weights. It produces a 6×6×256 feature map from a 227×227 input. Convolutions alone never link distant locations within one feature map, so the authors need a layer that does.
The authors instead use a channel-wise fully-connected layer, which mixes locations inside each feature map and never mixes different maps. A stride 1 convolution then mixes information across channels, and five up-convolutions with ReLU grow the features back to image size.
Reconstruction plus adversarial loss
The L2 loss rewards the average of plausible fills, so its output is a blurry mean. The adversarial loss, based on GAN, asks the output to look real and so tends to pick one mode from the distribution. The authors also tried L1 and found no significant difference from L2, so the squared form is what they kept.
A conditional GAN, fed the context as input to the discriminator, was hard to train because the discriminator spots the seam between real and generated pixels. So the authors condition only the generator \( F \) on the context, and the discriminator sees the whole output. The adversarial loss is \( L_{adv} = \max_D \; E_{x}[\log D(x)] + E[\log(1 - D(F((1-\hat{M}) \odot x)))] \), optimized with alternating SGD.
The joint objective is \( L = \lambda_{rec} L_{rec} + \lambda_{adv} L_{adv} \), and this term is used only for the inpainting experiments.
Choosing the dropped region
A single central square is the simplest mask, but the network learns features that latch onto its boundary. Those features transfer poorly to images with no mask, so the authors move away from a fixed hole. Random block masks use several smaller, possibly overlapping blocks, but their sharp edges still give the network a cue. Random region masks paste deformed shapes from PASCAL VOC 2012 masks into other images, so no edge is left to latch onto.
The authors found random region and random block masks give similarly general features, and both beat the central region. They therefore use random region dropout for all feature-based experiments, and the missing pixels are set to a constant mean value.
Semantic inpainting results
The authors compare the joint-loss context encoder with nearest-neighbor inpainting on held-out Paris StreetView images. Nearest-neighbor inpainting with HOG features had a mean L1 error of 19.92%, a mean L2 error of 6.92%, and a PSNR of 12.79 dB. Swapping in the context encoder's learned features improved those numbers to 15.10%, 4.30%, and 14.70 dB.
The joint-loss model reached 9.37%, 1.96%, and 18.58 dB, so the learned decoder beats the retrieval baseline on every measure in this table.
Training used the joint loss with λrec = 0.999 and λadv = 0.001, plus a 4000-unit bottleneck. Visually, the reconstruction-only output is well aligned but not sharp, and the adversarial-only output is sharp but incoherent. The joint loss keeps the alignment of the first and the sharpness of the second, and the authors read this as the reason for the gap.
Texture synthesis can still do better when the hole holds low-level texture rather than semantic content.
Feature learning and nearest neighbors
For feature learning the encoder is AlexNet, trained with reconstruction loss only. Training converges in about 100K iterations, which took 14 hours on a Titan X GPU. To test the features, the authors retrieve nearest neighbors for the masked patch using only its context. Those retrievals are decent, even though the L2-trained prediction itself is blurry, and HOG fails to find matching semantics.
Transfer to classification, detection and segmentation
Context encoder pre-training reached 56.5%, compared to 53.8% for the autoencoder and 53.3% for random Gaussian initialization. ImageNet-trained AlexNet scored 78.2%, so the gap to labeled pre-training remains large. The authors describe this result as competitive with concurrent self-supervised methods.
For detection, the pre-trained encoder weights up to pool5 initialize Fast R-CNN, and the upper layers are re-initialized. Context encoders scored 44.5%, compared to 43.4% for random initialization and 41.9% for the autoencoder. Doersch et al. still scored higher at 46.6%. For segmentation on PASCAL VOC 2012, the encoder replaces the ImageNet backbone of FCN and scores 30.0%, compared to 25.2% for the autoencoder and 19.8% for random initialization.
Krähenbühl et al. rescaling lifts Doersch et al. to 65.3% for classification and 51.1% for detection. The authors report that this rescaling doesn't help their own features, so the comparison is not settled by it. Pre-training took 14 hours for the context encoder, compared to 4 weeks for Doersch et al.
Limitations
The adversarial loss did not converge with AlexNet, so the feature experiments use reconstruction loss alone. The quantitative inpainting table covers only Paris StreetView held-out images. Detection is below Doersch et al., and segmentation is compared only with random initialization and the autoencoder. Low-level textured holes are better handled by texture synthesis than by the context encoder.
Paper info
- Authors
- Deepak Pathak, Philipp Krahenbuhl, Jeff Donahue, Trevor Darrell, Alexei A. Efros
- Venue
- arXiv · Preprint
- First published
- 2016-4-25
- Added
- 2026-11-11
- Updated
- 2016-11-21
- Version
- v2
- arXiv
- 1604.07379
- Category
- cs.CV · cs.AI · cs.GR · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Deepak Pathak, Philipp Krahenbuhl, Jeff Donahue, Trevor Darrell, Alexei A. Efros (2016). Context Encoders: Feature Learning by Inpainting. arXiv:1604.07379v2. https://arxiv.org/abs/1604.07379v2
BibTeX
@misc{pathak2016context,
title = {{Context Encoders: Feature Learning by Inpainting}},
author = {Deepak Pathak and Philipp Krahenbuhl and Jeff Donahue and Trevor Darrell and Alexei A. Efros},
year = {2016},
eprint = {1604.07379},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1604.07379v2}
}