DeepEMD: Differentiable Earth Mover's Distance for Few-Shot Learning

Chi Zhang, Yujun Cai, Guosheng Lin, Chunhua Shen

TL;DR

This paper introduces DeepEMD, a novel approach to few-shot image classification that treats images as sets of local regions and uses the Earth Mover's Distance (EMD) to measure their structural similarity. By making EMD differentiable and incorporating a cross-reference mechanism for region weighting, DeepEMD achieves state-of-the-art performance on several benchmarks, offering a more robust way to compare images by focusing on semantic correspondences.

What Problem Does This Paper Address?

Deep learning models typically require vast amounts of labeled data to achieve high accuracy. However, in many real-world scenarios, obtaining such large datasets is infeasible. Few-shot learning aims to address this by enabling models to learn new categories from only a handful of examples. Traditional metric-based methods in few-shot learning often represent entire images as single feature vectors and use simple distance metrics (like Euclidean or cosine distance). This approach struggles with cluttered backgrounds and significant variations within a class, as it can lead to image-level embeddings from the same category being far apart. The challenge is to develop a metric that can effectively capture the nuanced structural similarities between images, even with limited data, by leveraging local, discriminative information.

Methods

The core of DeepEMD lies in reframing few-shot classification as an optimal matching problem between sets of local image representations.

  • Earth Mover's Distance (EMD): Instead of comparing global image embeddings, DeepEMD extracts dense local feature representations from images. These representations form sets of "elements" (e.g., feature vectors from image patches). The EMD is then used to compute the minimum cost to transform one set of elements into another, effectively measuring the structural distance between the images. This is a more sophisticated metric than simple point-wise distances, as it considers the optimal matching between all pairs of local features.
  • Differentiable EMD Layer: To enable end-to-end training of neural networks with EMD, the authors leverage the implicit function theorem. This allows the gradients of the EMD's optimal solution to be backpropagated through the network, making the entire system trainable via standard gradient descent.
  • Cross-Reference Mechanism for Weights: A crucial aspect of EMD is assigning weights to the elements. The authors propose a "cross-reference mechanism" where the weight of a local region in one image is determined by its similarity to the global statistics of the other image. This helps to down-weight irrelevant background regions and highlight semantically important foreground regions that are likely to correspond between images.
  • Structured Fully Connected (FC) Layer: For the $k$-shot setting (where multiple support images are available), a novel "structured FC layer" is introduced. This layer learns a set of prototype vectors for each class, and the EMD is used to compare the query image's local representations against these class prototypes for classification. This extends the EMD-based comparison to a classification scenario.
  • Local Feature Extraction Strategies: The paper explores three methods for extracting local representations:
  • Fully Convolutional Networks (FCN): Generates dense feature maps.
  • Grid-based Cropping: Divides the image into a grid and extracts features from each patch.
  • Random Sampling: Randomly samples image patches, which proved to be the most effective. Pyramid structures (both feature-level and image-level) are also explored to capture multi-scale information.

Datasets

The authors evaluate their method on five widely used few-shot classification benchmarks:

  • miniImageNet: A popular benchmark derived from ImageNet, containing 100 classes.
  • tieredImageNet: Another ImageNet subset with more classes and a hierarchical structure.
  • Fewshot-CIFAR100 (FC100): Based on CIFAR100, with a specific split for few-shot learning.
  • Caltech-UCSD Birds-200-2011 (CUB): A fine-grained classification dataset.
  • CIFAR-FewShot (CIFAR-FS): Also based on CIFAR100.

Key Insights and Ideas

  • Images as Structured Sets: The fundamental shift in perspective is treating images not as single points in a feature space, but as structured sets of local regions. This allows for a more nuanced comparison that can capture semantic correspondences.
  • EMD as a Powerful Metric for Structure: EMD is well-suited for comparing structured data and can handle varying numbers of elements, making it a natural fit for comparing sets of local image features.
  • Weighting is Crucial for Robustness: Simply using EMD with equal weights for all local features is insufficient. The cross-reference mechanism for weight generation is key to filtering out noise from background regions and focusing on relevant object parts.
  • Differentiability Unlocks End-to-End Training: Making the EMD layer differentiable is a significant technical contribution, enabling seamless integration into deep learning pipelines and allowing for end-to-end optimization.
  • Random Sampling Outperforms Structured Grids: Surprisingly, random sampling of image patches for local feature extraction yielded better results than structured grid-based approaches, suggesting that a more diverse set of local views, even if noisy, can be beneficial when properly weighted.

Key Results

  • State-of-the-Art Performance: DeepEMD significantly outperforms existing state-of-the-art methods on all five tested benchmarks for both 1-shot and 5-shot classification tasks. For instance, on miniImageNet, it achieves 65.91% accuracy in the 1-shot 5-way setting, a notable improvement over previous methods.
  • Cross-Domain Transfer: The method demonstrates strong performance in cross-domain experiments (e.g., training on miniImageNet and testing on CUB), indicating its ability to generalize across datasets with significant domain gaps.
  • Image Retrieval Improvement: DeepEMD effectively enhances the performance of existing deep metric learning algorithms on image retrieval tasks when used as a replacement for standard distance metrics.
  • Effectiveness of Components: Ablation studies validate the importance of the cross-reference mechanism and the structured FC layer. The cross-reference mechanism alone, without EMD, leads to a performance drop, highlighting the synergy between the two.

Limitations and Future Work

  • Computational Cost: While the authors employ efficient solvers (QPTH for training, OpenCV for inference), EMD computation, especially for large feature maps, can still be computationally intensive compared to simpler distance metrics. Table 6 shows computation times that, while manageable, are higher than basic dot products.
  • Hyperparameter Sensitivity: The performance of grid-based and sampling-based methods can be sensitive to parameters like grid size or the number of sampled patches, although the cross-reference mechanism helps mitigate issues with noisy patches.
  • Future Work: The paper suggests exploring more advanced methods for generating local representations and investigating the application of DeepEMD to other computer vision tasks beyond classification and retrieval, such as segmentation and object detection. Further research into more efficient EMD solvers for real-time applications could also be a direction.

Summary updated

Abstract

In this work, we develop methods for few-shot image classification from a new perspective of optimal matching between image regions. We employ the Earth Mover's Distance (EMD) as a metric to compute a structural distance between dense image representations to determine image relevance. The EMD generates the optimal matching flows between structural elements that have the minimum matching cost, which is used to calculate the image distance for classification. To generate the important weights of elements in the EMD formulation, we design a cross-reference mechanism, which can effectively alleviate the adverse impact caused by the cluttered background and large intra-class appearance variations. To implement $k$ -shot classification, we propose to learn a structured fully connected layer that can directly classify dense image representations with the EMD. Based on the implicit function theorem, the EMD can be inserted as a layer into the network for end-to-end training. Our extensive experiments validate the effectiveness of our algorithm which outperforms state-of-the-art methods by a significant margin on five widely used few-shot classification benchmarks, namely, miniImageNet, tieredImageNet, Fewshot-CIFAR100 (FC100), Caltech-UCSD Birds-200-2011 (CUB), and CIFAR-FewShot (CIFAR-FS). We also demonstrate the effectiveness of our method on the image retrieval task in our experiments.
BibTeX
@inproceedings{zhang2020deepemd,
  author = {Chi Zhang and Yujun Cai and Guosheng Lin and Chunhua Shen},
  title = {{DeepEMD: Differentiable Earth Mover's Distance for Few-Shot Learning}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2020},
  doi = {10.1109/cvpr42600.2020.01222},
}
Figure