Deep Metric Learning by Online Soft Mining and Class-Aware Attention

Xinshao Wang, Yang Hua, Elyor Kodirov, Guosheng Hu, Neil Martin Robertson

Abstract

Deep metric learning (DML) aims to learn an embedding space where semantically similar images are clustered together. Traditional sample mining techniques often suffer from information loss due to binary "hard mining" and sensitivity to noisy outliers. This paper proposes a novel framework incorporating Online Soft Mining (OSM) and Class-Aware Attention (CAA). OSM utilizes continuous weighting to preserve intraclass variance and efficiently mine hard negatives, while CAA leverages a classification branch to identify and down-weight outliers. Experimental results on image retrieval and person re-identification benchmarks demonstrate that the proposed method achieves state-of-the-art performance.

Introduction

Deep Metric Learning (DML) is fundamental to tasks like image retrieval and person re-identification. The goal is to train a neural network to map input images into a feature space where Euclidean distances reflect semantic similarity. A critical challenge in DML is the selection of informative training pairs from a mini-batch. Most pairs are "trivial" and contribute little to learning.

Existing "hard mining" strategies address this by selecting only the most difficult pairs. However, these methods typically use a binary selection process that discards "semi-hard" samples, leading to slow convergence and information loss. Furthermore, hard mining is highly sensitive to outliers—mislabeled or poor-quality images—which naturally produce high loss and are mistakenly prioritized, degrading model performance.

Proposed Methodology: Weighted Contrastive Loss

To address these limitations, we introduce a Weighted Contrastive Loss (WCL) framework that replaces binary mining with continuous weighting and incorporates semantic consistency checks.

Architecture comparison between traditional contrastive loss (a) and the proposed weighted contrastive loss with OSM and CAA (b).

Online Soft Mining (OSM)

OSM assigns a continuous weight to every possible pair within a mini-batch based on their distance in the embedding space. For positive pairs, OSM focuses on "local positives"—samples that are already relatively close. This approach, inspired by manifold learning, allows the model to preserve complex intraclass variations (e.g., different poses or lighting) rather than forcing all samples into a single point. For negative pairs, OSM smoothly increases the weight for harder negatives that violate the margin, providing a more stable gradient than hard-thresholding.

Class-Aware Attention (CAA)

CAA is designed to mitigate the impact of outliers. By adding a classification branch, the network learns a representative "context vector" for each class. The CAA score measures the compatibility between an image's features and its class label. If an image is an outlier (e.g., mislabeled or extremely noisy), its CAA score will be low. This score is then used to down-weight the image's contribution to the overall loss, effectively filtering out "garbage" data during training.

Visualization of the mining process for positive and negative pairs using OSM and CAA weights. Red boxes indicate potential outliers with low compatibility scores.

Experimental Results

The proposed method was evaluated on standard DML benchmarks, including CUB-200-2011 (birds) and CARS196 (cars), as well as video-based person re-identification datasets like MARS and LPW.

  • Image Retrieval: On CUB-200-2011 and CARS196, the method outperformed previous state-of-the-art models (e.g., HDC, LiftedStruct) by approximately 1.5% in Recall@1.
  • Person Re-identification: The gains were particularly pronounced on the MARS dataset, where the Mean Average Precision (mAP) improved by 4.9% over the previous best-performing model (CAE).
  • Ablation Study: Results confirmed that OSM and CAA are complementary. Integrating CAA into a model already utilizing OSM consistently provided an additional 1-2% boost in accuracy, validating the effectiveness of the outlier rejection mechanism.

Conclusion

By shifting from binary hard mining to continuous soft weighting and incorporating class-aware semantic filtering, the proposed framework significantly improves the robustness and efficiency of deep metric learning. The combination of Online Soft Mining and Class-Aware Attention allows the model to better handle complex intraclass manifolds while remaining resilient to noisy data.

Summary updated

BibTeX
@inproceedings{wang2019deep,
  author = {Xinshao Wang and Yang Hua and Elyor Kodirov and Guosheng Hu and Neil Martin Robertson},
  title = {{Deep Metric Learning by Online Soft Mining and Class-Aware Attention}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2019},
  doi = {10.1609/aaai.v33i01.33015361},
}
Figure