Optimizing CLIP Models for Image Retrieval with Maintained Joint-Embedding Alignment
Konstantin Schall, Kai Uwe Barthel, Nico Hezel, Klaus Jung
TL;DR
CLIP's joint embeddings excel at text-to-image tasks but struggle with instance-level image retrieval due to semantic-visual gaps. The authors propose two retrieval-focused strategies: a two-stage fine-tuning (2SFT) that first improves image retrieval and then realigns the text encoder, and MCIP, which incorporates pseudo-captions via a Multi-Caption-ArcMargin loss to directly align image and multiple captions in the retrieval phase. Across multiple models and benchmarks, MCIP (often with a subsequent re-alignment) yields strong gains in image retrieval, k-NN, and zero-shot classification while preserving text-to-image retrieval, enabling a single embedding per image for large-scale search systems. The work formalizes the training objectives with $L_{InfoNCE}$, $L_{ArcMargin}$, and $L_{MCArcMargin}$ and provides code and optimized weights for reproducibility.
Abstract
Contrastive Language and Image Pairing (CLIP), a transformative method in multimedia retrieval, typically trains two neural networks concurrently to generate joint embeddings for text and image pairs. However, when applied directly, these models often struggle to differentiate between visually distinct images that have similar captions, resulting in suboptimal performance for image-based similarity searches. This paper addresses the challenge of optimizing CLIP models for various image-based similarity search scenarios, while maintaining their effectiveness in text-based search tasks such as text-to-image retrieval and zero-shot classification. We propose and evaluate two novel methods aimed at refining the retrieval capabilities of CLIP without compromising the alignment between text and image embeddings. The first method involves a sequential fine-tuning process: initially optimizing the image encoder for more precise image retrieval and subsequently realigning the text encoder to these optimized image embeddings. The second approach integrates pseudo-captions during the retrieval-optimization phase to foster direct alignment within the embedding space. Through comprehensive experiments, we demonstrate that these methods enhance CLIP's performance on various benchmarks, including image retrieval, k-NN classification, and zero-shot text-based classification, while maintaining robustness in text-to-image retrieval. Our optimized models permit maintaining a single embedding per image, significantly simplifying the infrastructure needed for large-scale multi-modal similarity search systems.
