Deep Metric Learning and Image Classification with Nearest Neighbour Gaussian Kernels

Benjamin J. Meyer, Ben Harwood, Tom Drummond

TL;DR

This paper introduces a unified Gaussian kernel loss function that excels at both deep metric learning and image classification. By treating training features as kernel centers and leveraging fast approximate nearest neighbor (ANN) search, the authors create a scalable method that outperforms traditional triplet losses and softmax classifiers, particularly when dealing with high-dimensional embeddings or limited training data.

What Problem Does This Paper Address?

In computer vision, image classification (assigning a label) and metric learning (learning a similarity-based embedding space) are usually treated as separate problems.

Standard classification typically uses a softmax loss, which is rigid: it requires axis-aligned class boundaries and a fixed number of classes. It often fails to capture the complex intra-class structures needed for tasks like retrieval. Conversely, metric learning methods like triplet loss often struggle to match the raw classification accuracy of state-of-the-art classifiers. Furthermore, triplet-based methods often force all examples of a class into a single cluster, which doesn't account for multi-modal distributions (e.g., a car viewed from the front vs. the back), and they often fail to benefit from higher-dimensional feature spaces.

Methods

The authors propose a novel approach that treats every training example's feature vector as a Gaussian kernel center.

  1. Gaussian Kernel Loss: Instead of comparing an image to a fixed weight matrix (like softmax), the model compares a query feature $x$ to the features of training examples $c_i$. The probability of $x$ belonging to class $Q$ is calculated by summing the influence of nearby centers belonging to that class, normalized by the total influence of all nearby centers.
  2. Scalability via ANN: Summing over the entire training set is computationally impossible for large datasets. The authors use Fast Approximate Nearest Neighbour Graphs (FANNG) to restrict the calculation to a local neighborhood, making the approach scalable to high dimensions and large datasets.
  3. Asynchronous Updates: To make end-to-end training feasible, the authors maintain a "bank" of kernel centers. These centers are updated asynchronously every few epochs rather than every iteration, which stabilizes the embedding space during training.
Overview of the approach: training features are recorded as centers for Gaussian kernels to determine class distributions.

Datasets

The method was evaluated on several fine-grained recognition benchmarks:

  • CUB Birds200-2011: 200 bird species.
  • Stanford Cars196: 196 car models.
  • Oxford 102 Flowers: 102 flower categories.
  • Leafsnap: 185 species of plant leaves taken in uncontrolled "field" conditions.

For metric learning, the models were trained on one half of the classes and evaluated on the unseen remaining half to test generalization.

Key Insights and Ideas

  • Local vs. Global Structure: Unlike triplet loss, which indiscriminately pulls all same-class items together, this kernel approach only considers the local neighborhood. This allows a single class to naturally form multiple clusters in the embedding space if the data warrants it.
  • Embracing High Dimensionality: A surprising finding in deep metric learning is that increasing embedding dimensions often hurts performance for triplet losses. In contrast, this kernel method shows consistent performance gains as dimensionality increases (up to 1024D), as seen in Figure 2.
  • Data Efficiency: The method is significantly more robust than softmax when training data is scarce. As shown in Figure 3, the accuracy gap between this method and softmax is widest when there are very few training images per class.
NMI and Recall scores showing performance improvements as embedding dimensionality increases.

Key Results

  • Metric Learning: On the Cars196 dataset, the proposed method achieved a Recall@1 of 71.05% at 64 dimensions, significantly outperforming the then-state-of-the-art SmrtMine (64.65%). At 1024 dimensions, this rose to 79.65%.
  • Classification: The method consistently beat softmax across different architectures. For example, using a VGG16 backbone on Birds200, the kernel approach reached 78.63% accuracy compared to softmax's 75.37%.
  • Generalization: t-SNE visualizations (Figures 5 and 6) demonstrate that the network learns a well-structured embedding space where even "unseen" classes from the test set cluster semantically based on species or car model attributes.
Effect of training images per class: the kernel method (Ours) maintains a significant lead over Softmax in low-data regimes.

Limitations and Future Work

  • Hyperparameter Sensitivity: The performance depends on tuning the Gaussian kernel width ($\sigma$) and the update interval for the center bank. While the authors provide heuristics, these may vary by dataset.
  • Memory Overhead: Storing a bank of all training features requires additional memory, though the authors argue this is manageable for the datasets tested.
  • Computational Cost of ANN: While FANNG is efficient, building and updating the neighbor graph adds a computational step not present in standard softmax training.

Future work could explore more automated ways to tune the kernel width or investigate how this approach scales to massive datasets like ImageNet-21k.

Summary updated

BibTeX
@inproceedings{meyer2018deep,
  author = {Benjamin J. Meyer and Ben Harwood and Tom Drummond},
  title = {{Deep Metric Learning and Image Classification with Nearest Neighbour Gaussian Kernels}},
  booktitle = {ICIP},
  year = {2018},
  doi = {10.1109/icip.2018.8451297},
}
Figure