Deep unsupervised learning through spatial contrasting

Elad Hoffer, Itay Hubara, Nir AilonarXiv 2016

Abstract

Researchers have introduced Spatial Contrasting (SC), a novel unsupervised learning criterion that trains Convolutional Neural Networks (CNNs) by comparing different regions within the same image. By forcing the network to recognize that patches from the same image are semantically "closer" than patches from different images, the model learns powerful representations that significantly outperform previous state-of-the-art unsupervised methods on benchmarks like STL-10.

Introduction

Deep learning’s greatest success stories usually rely on supervised learning, which requires massive amounts of human-labeled data. Unsupervised learning—learning from raw, unlabeled data—remains a primary goal in computer vision. Historically, unsupervised methods for CNNs relied on Autoencoders, which try to reconstruct an image pixel-by-pixel. However, this approach has two major flaws:

  1. Pixel Obsession: Minimizing Mean Squared Error (MSE) at the pixel level forces the network to prioritize low-level details (like minor shifts) that are often irrelevant to high-level semantic understanding.
  2. Architectural Complexity: Many unsupervised methods require specialized architectures that do not easily translate to standard CNNs used for downstream tasks.

The authors propose a method that is "discriminative" (focusing on features rather than pixels) and "plug-and-play" with standard CNN architectures.

Methods: Spatial Contrasting

The core idea is Spatial Contrasting, based on the observation that different regions of the same image (e.g., the head and tail of a dog) are likely to be semantically similar, while regions from two random images are likely to be different.

The Spatial Contrasting workflow: extracting patches, embedding them via a ConvNet, and applying a distance ratio loss.

The workflow consists of three main steps:

  1. Sampling: For a given image, the network extracts two different spatial patches (an "anchor" $x_1^{(1)}$ and a "positive" sample $x_1^{(2)}$). It also takes a patch from a different image in the training batch (the "negative" sample $x_2^{(1)}$).
  2. Embedding: These patches are passed through a standard CNN to produce feature vectors (embeddings $f_1^{(1)}, f_1^{(2)}, f_2^{(1)}$).
  3. Loss Function: A distance ratio loss is applied. The goal is to maximize the probability that the anchor is closer to the positive sample than it is to the negative sample in the feature space.

This process is entirely differentiable and uses standard stochastic gradient descent (SGD), allowing it to pre-train any conventional CNN.

Key Results

The method was evaluated on three standard datasets: STL-10 (primary benchmark), CIFAR-10 (limited label scenario), and MNIST.

The results were particularly striking on the STL-10 dataset, which is designed for unsupervised learning with 100,000 unlabeled images.

Comparison of STL-10 test accuracy across various unsupervised models, showing the significant gain from Spatial Contrasting.

As shown in the table above, the SC-initialized model achieved 81.34% accuracy, a massive jump over the previous state-of-the-art (Stacked What-Where Autoencoders) at 74.33%.

Other notable results include:

  • CIFAR-10: With only 400 labels per class, the SC pre-trained model reached 79.2%, compared to 72.4% for the same model trained from scratch.
  • MNIST: Even on a dataset where spatial contrasting is less intuitive due to sparse information, the error rate dropped from 0.63% to 0.34%.

Discussion and Insights

The success of Spatial Contrasting stems from leveraging Semantic Stationarity. Because features in natural images are somewhat stationary, a network that learns to associate different parts of the same object effectively learns "object-ness" without explicit labels. By contrasting embeddings rather than reconstructing pixels, the model becomes agnostic to low-level noise, focusing instead on consistent high-level concepts.

Limitations and Future Work

While effective, SC is less impactful on datasets like MNIST where spatial regions often contain little information (e.g., black backgrounds). Future research could extend this "contrasting" logic to the temporal dimension in video frames or integrate SC directly into semi-supervised frameworks for joint optimization.

Summary updated

BibTeX
@misc{hoffer2016deep,
  author = {Elad Hoffer and Itay Hubara and Nir Ailon},
  title = {{Deep unsupervised learning through spatial contrasting}},
  year = {2016},
  eprint = {1610.00243},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1610.00243},
}
Figure