All You Need to Know About Training Image Retrieval Models
Gabriele Berton, Kevin Musgrave, Carlo Masone
TL;DR
This work systematically analyzes how training-time factors such as loss functions, optimizers, sampling, learning rates, batch sizes, and labeling strategies affect image retrieval performance across multiple datasets, addressing a gap in understanding component interactions. Through tens of thousands of training runs, it reveals practical guidelines: use CLS features from DINO-v2 with full fine-tuning and a model LR of $1e-6$, apply large batches for contrastive losses with online miners, and tune the classifier LR separately (around $1$); in constrained settings, CosFace/ArcFace with 1 image per class can be preferable. The study finds that metric-learning losses tolerate some label noise, but more classes and larger datasets generally boost accuracy, suggesting data quantity over meticulous labeling; feature dimensionality and sampling choices also impact performance and memory use. Together, these insights offer actionable strategies for building efficient, scalable image retrieval systems under diverse compute budgets, balancing accuracy, resources, and data collection strategies.
Abstract
Image retrieval is the task of finding images in a database that are most similar to a given query image. The performance of an image retrieval pipeline depends on many training-time factors, including the embedding model architecture, loss function, data sampler, mining function, learning rate(s), and batch size. In this work, we run tens of thousands of training runs to understand the effect each of these factors has on retrieval accuracy. We also discover best practices that hold across multiple datasets. The code is available at https://github.com/gmberton/image-retrieval
