DeepEMD: Few-Shot Image Classification with Differentiable Earth Mover's Distance and Structured Classifiers

Chi Zhang, Yujun Cai, Guosheng Lin, Chunhua Shen

Abstract

Few-shot learning (FSL) aims to recognize new categories from very few labeled examples. Traditional metric-based FSL methods often rely on global image embeddings, which can be sensitive to background clutter and spatial variations. This paper introduces DeepEMD, a framework that represents images as sets of local features and employs the Earth Mover’s Distance (EMD) as a differentiable metric to find optimal matching flows between regions. By focusing on structural similarity at the local level, DeepEMD achieves state-of-the-art performance across several benchmarks and demonstrates significant robustness to domain shifts.

Introduction

Standard deep learning models typically require vast amounts of labeled data to generalize effectively. In contrast, few-shot learning (FSL) seeks to mimic human-like learning by identifying new classes from just one or five examples. Most existing metric-based FSL approaches compress an image into a single global vector via global average pooling. However, this process discards critical spatial information. If an object is occluded, posed differently, or set against a complex background, the global vector changes significantly, leading to poor classification.

DeepEMD addresses this by comparing images at a local level—matching semantic parts like a bird's wing or a dog's head—while remaining robust to noise and irrelevant background features.

Methods: Structural Matching with DeepEMD

The core of DeepEMD is treating image comparison as an optimal transport problem. The framework consists of several key components:

  1. Local Feature Extraction: A backbone network (e.g., ResNet-12) generates a dense representation—a grid of feature vectors—instead of a single global embedding.
  2. Earth Mover’s Distance (EMD): EMD is used to calculate the minimum cost to transform the feature distribution of a query image into that of a support image. This finds the optimal "flow" between corresponding regions.
  3. Differentiable Solver: To enable end-to-end training, the authors utilize the implicit function theorem to compute gradients through the EMD optimization step.
  4. Cross-Reference Mechanism: This mechanism weights regions based on their relevance to the target image. Regions with no clear counterpart (like background grass) receive lower weights, effectively filtering out distractions.
Overview of the DeepEMD architecture, illustrating the extraction of local embeddings and the calculation of EMD between query and support images. Three variants are shown: (a) FCN, (b) Grid, and (c) Sampling.

To handle $k$-shot scenarios ($k > 1$), the authors propose a Structured Fully Connected (SFC) layer that learns class prototypes matched against query images using the same EMD logic.

Key Insights and Intuition

The primary advantage of DeepEMD is its shift from global to local reasoning. Local "object parts" tend to be more transferable across categories than holistic image signatures.

Visualization of the optimal matching flows between local patches. The model aligns semantic parts (e.g., heads, paws) even when the subjects are in different poses.

The EMD flow acts as a form of "hard" attention, explicitly showing which parts of two images correspond. The cross-reference mechanism further enhances this by autonomously identifying foreground elements without requiring explicit bounding box labels.

Experimental Results

DeepEMD was evaluated on five major benchmarks: miniImageNet, tieredImageNet, FC100, CIFAR-FS, and CUB.

  • State-of-the-Art Accuracy: On miniImageNet (1-shot), DeepEMD achieved 68.77% accuracy, significantly outperforming previous methods like MetaOptNet (~64%).
  • Cross-Domain Robustness: When trained on miniImageNet and tested on the fine-grained CUB dataset, DeepEMD maintained a strong lead (54.24% vs. 50.01% for Prototypical Networks), demonstrating that local matching generalizes better across domain shifts.

Limitations and Future Work

While powerful, DeepEMD introduces higher computational complexity due to the need to solve a Linear Programming problem for every image pair. Training is resource-intensive, although faster solvers can be used for inference. Additionally, performance is sensitive to the patch extraction strategy (FCN vs. Grid vs. Sampling), with the "Sampling" method yielding the best results at the cost of increased complexity. Future research may explore faster approximate solvers like the Sinkhorn algorithm or extend this structural matching approach to tasks like few-shot object detection.

Summary updated

BibTeX
@inproceedings{zhang2020deepemd,
  author = {Chi Zhang and Yujun Cai and Guosheng Lin and Chunhua Shen},
  title = {{DeepEMD: Few-Shot Image Classification with Differentiable Earth Mover's Distance and Structured Classifiers}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2020},
  doi = {10.1109/cvpr42600.2020.01222},
}
Figure