Learning Attribute-Aware Hash Codes for Fine-Grained Image Retrieval via Query Optimization

Peng Wang, Yong Li, Lin Zhao, Xiu-Shen Wei

Fine-grained image retrieval (FGIR) presents a significant challenge in computer vision, requiring the differentiation of highly similar subcategories such as specific bird species or aircraft variants. While hashing methods are commonly used to compress image features into compact binary codes for efficient retrieval, they often suffer from a lack of interpretability and severe optimization difficulties in low-bit settings. This paper introduces Query Optimization (QueryOpt), a framework that treats hash code generation as a set prediction problem to produce discriminative, attribute-aware binary codes.

The QueryOpt Framework

The proposed method moves away from traditional global feature projection. Instead, it employs a set of learnable "attribute queries" that interact with image features to decouple specific visual characteristics. The architecture consists of three core components:

  1. Subtle Feature Extractor: A CNN-based backbone utilizing a top-down architecture and self-attention mechanisms to capture multi-scale, nuanced details essential for fine-grained recognition.
  2. Query Learning Mechanism: Inspired by the DETR (Detection Transformer) architecture, this module uses cross-attention between learnable queries and extracted features. Each query is designed to focus on a specific semantic attribute (e.g., beak shape, wing pattern) and eventually produces exactly one bit of the final hash code.
  3. Auxiliary Branch & Query Transformation: To navigate the rugged optimization landscape of low-bit hashing, an auxiliary branch is used during training. By applying a "circular shift" transformation to the queries, the model effectively boosts the dimensionality of the feature space during the loss calculation without increasing inference-time parameters.
Overview of the QueryOpt framework, illustrating the subtle feature extraction and the query-based attribute decoupling process.

Overcoming the Low-Bit Optimization Trap

A key contribution of this work is the mathematical analysis of why low-bit hashing often fails. The authors utilize the Welch bound to demonstrate that as the number of categories ($C$) significantly exceeds the number of bits ($n$), the minimum possible cosine similarity between different classes rises sharply. This "crowding" effect makes it nearly impossible for standard gradient descent to find a distinguishable global minimum in low-dimensional space.

The QueryOpt framework addresses this through "Dimensionality Boosting." By using the auxiliary branch to calculate loss in a higher-dimensional space during training, the model can find a better global minimum that would be inaccessible in a native low-bit space. This branch is discarded during inference, maintaining the efficiency of the compact hash codes.

Key Results and Interpretability

The QueryOpt method achieves state-of-the-art (SOTA) performance across five standard fine-grained benchmarks, including CUB200-2011 and NABirds. The gains are particularly dramatic in low-bit scenarios. For instance, on the CUB200 dataset with a 12-bit code, the method achieved 72.19% mAP, representing a 15.77% improvement over previous SOTA methods like AGMH.

Comparison of retrieval performance (% mAP) across different bit lengths. The red bars represent the model without the auxiliary branch, highlighting the necessity of dimensionality boosting for low-bit optimization.

Beyond performance, the model offers unprecedented interpretability. Visualization via heatmaps confirms that specific queries consistently activate on the same semantic parts of an object across different images—for example, one bit might consistently represent "blue head" while another represents "orange body." This ensures that the resulting hash codes are not just mathematical abstractions but are grounded in identifiable visual attributes.

Conclusion

By reframing hashing as a set prediction problem and introducing a novel query optimization strategy, this work successfully addresses the long-standing trade-off between interpretability and retrieval performance in FGIR. The QueryOpt framework not only sets new benchmarks for accuracy but also provides a more transparent and robust approach to fine-grained visual search.

Summary updated

BibTeX
@inproceedings{wang2025learning,
  author = {Peng Wang and Yong Li and Lin Zhao and Xiu-Shen Wei},
  title = {{Learning Attribute-Aware Hash Codes for Fine-Grained Image Retrieval via Query Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=rn3thNKvzw},
}
Figure