Abstract
Unsupervised image hashing, which maps images into binary codes without manual labels, is a high-ratio compression task where preserving meaningful information is critical. Inspired by the success of Vision Transformers (ViT) in learning visual representations, we propose ViT2Hash (IPHash), a simple yet effective information-preserving framework to finetune ViT models for unsupervised hashing. Our approach consists of two primary components: a feature-preserving module that uses masked image reconstruction to focus on meaningful data structure, and a hashing-preserving module that distills semantic knowledge from a pre-trained classifier using Kullback-Leibler divergence. Experimental results on three benchmark datasets show that our method significantly outperforms existing state-of-the-art unsupervised hashing techniques.
Introduction
In large-scale image retrieval, hashing compresses high-dimensional images into short binary strings (e.g., 64 bits) to enable rapid search and minimal storage. The core challenge in unsupervised hashing is the "information bottleneck": when compressing an image from thousands of pixels to a few dozen bits, the model must distinguish between meaningful semantic information and irrelevant noise without the guidance of labels. ViT2Hash addresses this by leveraging the rich, pre-learned representations of large-scale Vision Transformers to guide the compression process.
Methodology
The IPHash framework operates in two distinct stages to bridge the gap from raw pixels to compact binary codes.
1. Feature-Preserving Module (Pixels to Features)
Inspired by Masked Autoencoders (MAE), this module feeds "corrupted" images—where 25% to 50% of patches are randomly masked—into a ViT feature extractor. The model is trained to reconstruct the feature vector of the original, complete image. This reconstruction task forces the extractor to learn the underlying global structure and semantics of the data rather than simply memorizing pixel values.
2. Hashing-Preserving Module (Features to Bits)
To convert continuous features into binary codes while maintaining semantic integrity, we employ Knowledge Distillation. We use a pre-trained ViT classifier to generate "soft labels" (probability distributions). A simple hashing layer is then trained to produce binary codes that, when passed through a linear classifier, mimic the original model's distribution.
Loss Functions
The model is optimized using a multi-part loss function:
- Reconstruction Loss ($L_{rec}$): Aligns masked features with full-image features.
- KL Divergence Loss ($L_{kl}$): Distills semantic knowledge from the pre-trained classifier.
- Similarity Loss ($L_{sim}$): Ensures images close in feature space remain close in binary space.
- Quantization Loss ($L_{quan}$): Minimizes the error when rounding continuous values to binary bits.
Experimental Results
We evaluated IPHash on three standard benchmarks: CIFAR-10, MSCOCO, and NUS-WIDE. IPHash consistently outperformed previous unsupervised methods like CIBHash and GreedyHash across all bit lengths.
- Superior Accuracy: On CIFAR-10, IPHash achieved a Mean Average Precision (MAP) of 0.942 at 16 bits, a significant improvement over the previous best of 0.903.
- Efficiency at Low Bitrates: The performance gap is most pronounced at lower bitrates, demonstrating the model's exceptional ability to preserve critical information under extreme compression.
Discussion and Conclusion
A key insight of this work is that training on masked images leads to better retrieval performance than training on full images, as it encourages the model to capture more robust global semantics. Furthermore, using soft labels from pre-trained models allows the system to inherit complex semantic relationships (e.g., the similarity between different animal species) without human supervision.
Future work will explore the integration of contrastive vision-language models like CLIP and the use of prompt-tuning to further refine unsupervised hashing performance.
Summary updated