Contrastive Quantization with Code Memory for Unsupervised Image Retrieval

Jinpeng Wang, Ziyun Zeng, Bin Chen, Tao Dai, Shu-Tao Xia

Abstract

MeCoQ is a novel unsupervised image retrieval framework that combines contrastive learning with deep quantization. By introducing a "Code Memory" module and codeword diversity regularization, it achieves state-of-the-art performance while solving common issues of model degeneration and feature drift in memory-based training.

Introduction

In large-scale image retrieval, high-dimensional images must be transformed into compact binary codes (hashing or quantization) to ensure search efficiency and storage optimization. While supervised methods are effective, they rely on massive labeled datasets. Unsupervised methods offer better scalability but often struggle to capture discriminative features—the subtle differences between categories—without explicit labels.

Contrastive Learning (CL) has significantly advanced unsupervised representation learning by pulling similar views of an image together and pushing different images apart. However, applying CL to quantization (mapping features to discrete "codewords") presents three major challenges:

  1. Sampling Bias: Random batches of unlabeled data may contain "false negatives" (different images of the same category), which can degrade model performance.
  2. Model Degeneration: Without regularization, codewords tend to collapse toward each other, losing their discriminative power.
  3. The Efficiency Gap: CL requires large batches of negative samples. Standard memory banks used to cache features suffer from "feature drift," where cached features become stale as the model updates.

Methods

The proposed MeCoQ (Contrastive Quantization with Code Memory) framework introduces several innovations to address these challenges.

Overview of the MeCoQ framework, illustrating the two-step process of contrastive quantization learning and code memory update.
  • Debiased Contrastive Learning: The framework mathematically corrects for potential false negatives in training batches, resulting in a cleaner contrastive signal.
  • Codeword Diversity Regularization: A specific loss term encourages codewords within the same codebook to remain spread out, preventing the collapse that leads to model degeneration.
  • Quantization Code Memory: Instead of caching raw image embeddings, MeCoQ caches soft quantization codes. This is the paper's primary contribution to stabilizing memory-based training.
  • Soft Assignment via $\alpha$-softmax: To maintain differentiability during the discrete quantization process, the model uses a "soft" version of codeword assignment that sharpens as training progresses.

Key Insights and Ideas

A central finding of the paper is the "Feature Drift" Paradox. While quantization error is typically viewed as a negative outcome, the authors discovered that moderate quantization error actually helps stabilize memory banks.

Analysis of feature drift and quantization error during training, highlighting how soft quantization stabilizes the memory bank.

Because soft quantized features are essentially "blurred" versions of the original features, they are less sensitive to incremental parameter updates in the encoder. This allows cached negative samples to remain valid for longer periods than raw feature embeddings. Additionally, the authors demonstrated that without diversity regularization, contrastive loss aggressively pulls positive pairs until codewords overlap, causing a significant drop in Mean Average Precision (MAP). MeCoQ achieves this stability efficiently without requiring a separate "momentum encoder," reducing computational overhead.

Experimental Results

MeCoQ was evaluated on standard benchmarks, including Flickr25K, CIFAR-10, and NUS-WIDE, significantly outperforming 24 existing unsupervised hashing and quantization baselines.

  • Performance Gains: MeCoQ improved MAP by 6.92% on CIFAR-10 and 3.52% on Flickr25K compared to the previous state-of-the-art (CIBHash).
  • Robustness: The model consistently outperformed both shallow methods (e.g., ITQ) and deep binary hashing methods (e.g., GreedyHash) across various bit lengths (16, 32, and 64 bits).
  • Efficiency: Profiling indicates that MeCoQ achieves high accuracy with lower GPU memory requirements than large-batch training, validating the effectiveness of the Code Memory module.

Limitations and Future Work

Despite its success, MeCoQ has areas for further exploration. The model introduces new hyperparameters, such as the "positive prior" ($\rho^+$) and the memory module's starting epoch, which may require tuning for new domains. Furthermore, while the current work uses a VGG16 backbone for fair comparison, scaling the framework with modern Vision Transformers (ViTs) or larger self-supervised models remains an open research path. Finally, streamlining the initial "warm-up" phase required for feature stabilization could further simplify the training pipeline.

Summary updated

BibTeX
@inproceedings{wang2022contrastive,
  author = {Jinpeng Wang and Ziyun Zeng and Bin Chen and Tao Dai and Shu-Tao Xia},
  title = {{Contrastive Quantization with Code Memory for Unsupervised Image Retrieval}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2022},
  doi = {10.1609/aaai.v36i3.20147},
}
Figure