Lightweight Contrastive Distilled Hashing for Online Cross-modal Retrieval

Jiaxing Li, Lin Jiang, Zeqi Ma, Kaihang Jiang, Xiaozhao Fang, Jie Wen

TL;DR

Lightweight Contrastive Distilled Hashing (LCDH) enables high-performance, real-time cross-modal retrieval (like searching images with text) on resource-constrained devices. By using a knowledge distillation framework, it transfers the deep semantic understanding of a heavy, pre-trained model (CLIP) into a lightweight student network that can handle streaming data with minimal computational overhead.

What Problem Does This Paper Address?

Cross-modal retrieval—the ability to search for content in one modality (e.g., text) using a query from another (e.g., an image)—is essential for modern AI applications. However, two major hurdles remain:

  1. The Heterogeneous Gap: Images and text are fundamentally different data types. Finding "coexistent semantic relevance" (shared meaning) between them is difficult.
  2. Resource Constraints: Powerful models like CLIP are too large for mobile or edge devices. While "hashing" (compressing data into binary codes) helps with speed and storage, traditional hashing methods struggle to maintain accuracy when trained "online" (processing data in real-time streams rather than all at once).

The authors aim to bridge the gap between heavy, high-performance offline models and efficient, real-time online models.

Methods

The authors propose a Teacher-Student distillation framework designed to "distill" complex semantic relationships into simple binary hash codes.

Figure 1: The framework of the lightweight contrastive distilled hashing (LCDH) for online cross-modal retrieval.
  • The Teacher (Offline): This component uses CLIP to extract high-quality features from a static dataset. These features are fused and passed through an attention module to highlight the most relevant shared semantics. It generates a "similarity matrix" that serves as the ground truth for what data points are semantically related.
  • The Student (Online): This is a lightweight network using VGG16 for images and Bag-of-Words (BoW) for text. It processes new data chunks in real-time.
  • Knowledge Distillation: The core innovation is similarity matrix approximation. The student doesn't just learn to categorize data; it learns to approximate the similarity matrix produced by the teacher. This allows the student to inherit the teacher's sophisticated understanding of cross-modal relationships while remaining computationally "thin."
  • Objective Function: The model is optimized using a combination of log-likelihood similarity preservation (to keep the hash codes meaningful) and a distillation loss (to keep the student aligned with the teacher).

Datasets

The researchers evaluated LCDH on three standard benchmarks for cross-modal retrieval:

  • MIRFlickr-25K: 25,000 image-text pairs from Flickr across 24 categories.
  • IAPR TC-12: 20,000 pairs annotated with 255 categories, using GIST descriptors for images.
  • NUS-WIDE: A large-scale dataset; the authors used a subset of ~186,000 pairs across the 10 most frequent categories.

Key Insights and Ideas

  • CLIP as a Semantic Anchor: Using CLIP in the teacher phase provides a much stronger semantic foundation than the standard CNNs used in previous hashing methods.
  • Attention Matters: The attention module in the teacher network helps narrow the "heterogeneous gap" by focusing on features that are present and relevant in both modalities simultaneously.
  • Online Hashing can Rival Offline: Traditionally, offline methods (which see all data at once) outperform online methods. However, LCDH shows that with proper distillation, an online student can actually outperform many state-of-the-art offline baselines.
  • Fast Convergence: The model reaches stability very quickly—usually within ten iterations—making it highly practical for real-world deployment.

Key Results

LCDH consistently outperformed both offline and online state-of-the-art (SOTA) methods (like DCMH, SSAH, and ROH) across all datasets.

  • Mean Average Precision (mAP): LCDH achieved the highest mAP scores for both Image-to-Text (I→T) and Text-to-Image (T→I) tasks. For example, on MIRFlickr-25K with 128-bit hash codes, it reached an mAP of 0.8041 (I→T) and 0.8574 (T→I).
  • Precision-Recall Curves: The precision-recall curves show a significant gap between LCDH and the next-best methods, indicating superior retrieval accuracy at all levels of recall.
Figure 2: Precision-recall and Top-N precision curves of LCDH and baselines on MIRFlickr-25K with 128 bits hash codes.
  • Top-N Precision: The model maintains high precision even as the number of retrieved results (N) increases, proving its stability in large-scale search scenarios.

Limitations and Future Work

While the paper demonstrates impressive results, a few areas remain open for exploration:

  • Teacher Dependency: The student's performance is inherently capped by the quality of the teacher (CLIP). If the teacher has biases or lacks domain-specific knowledge, the student will inherit those flaws.
  • Fixed Modalities: The current framework is designed for image-text pairs. Extending this to video or audio modalities would require significant changes to the feature extraction layers.
  • Lightweight vs. Ultra-lightweight: While VGG16 is "lightweight" compared to CLIP, modern mobile-first architectures like MobileNetV3 or EfficientNet might offer even better efficiency for the student network.

The authors suggest that future research could focus on even more efficient ways to bridge the connection between offline teacher networks and online student networks in the distillation process.

Summary updated

Abstract

Deep online cross-modal hashing has gained much attention from researchers recently, as its promising applications with low storage requirement, fast retrieval efficiency and cross modality adaptive, etc. However, there still exists some technical hurdles that hinder its applications, e.g., 1) how to extract the coexistent semantic relevance of cross-modal data, 2) how to achieve competitive performance when handling the real time data streams, 3) how to transfer the knowledge learned from offline to online training in a lightweight manner. To address these problems, this paper proposes a lightweight contrastive distilled hashing (LCDH) for cross-modal retrieval, by innovatively bridging the offline and online cross-modal hashing by similarity matrix approximation in a knowledge distillation framework. Specifically, in the teacher network, LCDH first extracts the cross-modal features by the contrastive language-image pre-training (CLIP), which are further fed into an attention module for representation enhancement after feature fusion. Then, the output of the attention module is fed into a FC layer to obtain hash codes for aligning the sizes of similarity matrices for online and offline training. In the student network, LCDH extracts the visual and textual features by lightweight models, and then the features are fed into a FC layer to generate binary codes. Finally, by approximating the similarity matrices, the performance of online hashing in the lightweight student network can be enhanced by the supervision of coexistent semantic relevance that is distilled from the teacher network. Experimental results on three widely used datasets demonstrate that LCDH outperforms some state-of-the-art methods.
BibTeX
@inproceedings{li2025lightweight,
  author = {Jiaxing Li and Lin Jiang and Zeqi Ma and Kaihang Jiang and Xiaozhao Fang and Jie Wen},
  title = {{Lightweight Contrastive Distilled Hashing for Online Cross-modal Retrieval}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i5.32505},
}
Figure