Visual Similarity Attention

Meng Zheng, Srikrishna Karanam, Terrence Chen, Richard J. Radke, Ziyan Wu

Abstract

Deep metric learning is fundamental to tasks like image retrieval and person re-identification, yet the underlying decision-making process of these models often remains a "black box." This paper introduces a novel gradient-based attention mechanism that provides visual explanations for why a model considers two images similar. Furthermore, the authors propose "Similarity Mining," a training strategy that leverages these attention maps to force models to discover a more exhaustive set of discriminative features. The resulting framework not only improves transparency but also achieves state-of-the-art performance across multiple domains, including zero-shot semantic segmentation.

Introduction

While deep learning has revolutionized our ability to calculate distances between data points—ensuring similar items are clustered together in feature space—existing explainability tools like Grad-CAM are primarily designed for classification. They struggle to explain similarity because they analyze images in isolation rather than in pairs or triplets. This research addresses this gap by answering a fundamental question: "What specific features make Image A similar to Image B but different from Image C?"

Methodology

Similarity Attention

The core innovation is a Similarity Attention mechanism that works directly with the feature vectors used for metric learning, avoiding the need for auxiliary classification layers. For a given triplet (Anchor, Positive, Negative), the model calculates a weight vector ($w$) that highlights dimensions where the Anchor is proximal to the Positive but distant from the Negative.

Similarity Attention maps provide visual explanations for model decisions, highlighting specific object parts like the cat's face that contribute to similarity scores.

By computing the gradient of the resulting similarity scores with respect to the convolutional feature maps, the system produces an attention map. These maps highlight the physical regions—such as a specific animal's facial features or a car's unique grill—that drove the model's decision.

Similarity Mining

To improve model robustness, the authors introduce "Similarity Mining." This training strategy uses the generated attention maps to identify the most influential regions for a given similarity match. The system then "soft-masks" or erases these primary regions, forcing the model to find alternative reasons why the images are similar.

The Similarity Mining process uses soft-masking (red box) to hide primary features, encouraging the model to identify secondary discriminative attributes.

This iterative process prevents the model from over-relying on a single obvious cue (like a background or a prominent color) and encourages the discovery of a richer, more exhaustive set of local features. This leads to feature embeddings that generalize significantly better to unseen data.

Experimental Results

The framework was evaluated across three distinct domains: image retrieval, person re-identification (Re-ID), and one-shot semantic segmentation.

  • Image Retrieval: On the CUB200 (birds) dataset, the Similarity Attention Module (SAM) improved the baseline Triplet model's Recall@1 from 66.4% to 68.3%.
  • Person Re-ID: The method achieved 74.5% Rank-1 accuracy on the CUHK03-NP dataset, outperforming several specialized architectures.
  • Zero-Shot Semantic Segmentation: Perhaps most impressively, a model trained only for metric learning on birds or cars achieved a mean IOU of 41.6% on the PASCAL-$5^i$ segmentation dataset. This suggests that by learning how to look for similarities generally, the model can identify corresponding parts in entirely unseen object categories without pixel-level supervision.

Discussion and Conclusion

The proposed Similarity Attention mechanism is model-agnostic, functioning as a "plug-and-play" module for Siamese, triplet, and quadruplet architectures. By treating similarity as a more fundamental task than classification, the model learns features that are highly effective for downstream tasks.

While the "Similarity Mining" step introduces some computational overhead due to additional forward and backward passes, the gains in robustness and interpretability are substantial. Future work may involve extending this mechanism to set-to-set matching and video-based similarity, where temporal consistency can further refine the attention maps.

Summary updated

BibTeX
@inproceedings{zheng2022visual,
  author = {Meng Zheng and Srikrishna Karanam and Terrence Chen and Richard J. Radke and Ziyan Wu},
  title = {{Visual Similarity Attention}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2022},
  doi = {10.24963/ijcai.2022/241},
}
Figure