Towards flexible perception with visual memory

Robert Geirhos, Priyank Jaini, Austin Stone, Sourabh Medapati, Xi Yi, George Toderici, Abhijit Ogale, Jonathon Shlens

This paper from Google DeepMind proposes a shift in how we think about "knowledge" in computer vision. Instead of baking everything into the static weights of a monolithic neural network—a process the authors liken to "carving knowledge into stone"—they suggest a more flexible approach: marrying powerful deep learning representations with the modularity of a database.

TL;DR

The authors introduce a "visual memory" system that performs image classification by retrieving the $k$-nearest neighbors from a massive database of embeddings. This approach allows for "perfect" machine unlearning, seamless addition of new classes without retraining, and highly interpretable decisions, all while achieving state-of-the-art accuracy (88.5% on ImageNet-1K) when paired with a large language model re-ranker.

What Problem Does This Paper Address?

Standard deep learning models are notoriously rigid. Once trained, their knowledge is "entangled" across millions or billions of parameters. If you want to add a new category of objects, remove biased data (machine unlearning), or understand why a model made a specific mistake, you usually face an uphill battle involving expensive retraining or opaque "black-box" behavior.

In the real world, data requirements change constantly. New concepts emerge, and old ones become deprecated. This paper addresses the need for flexible perception: a system where knowledge can be edited, added, or deleted as easily as updating a row in a SQL database, without sacrificing the representational power of modern vision backbones like DinoV2 or CLIP.

Methods

The core architecture is a retrieval-based classifier. It consists of two main parts:

  1. A Fixed Encoder: A pre-trained model (like DinoV2) that turns images into feature embeddings. No training happens here during the "memory" phase.
  2. A Visual Memory: A database storing these embeddings alongside their labels.

To classify a new image, the system finds the $k$ most similar images in the database. The key technical innovation is RankVoting. Traditional $k$-nearest neighbor ($k$NN) methods often degrade as you increase $k$ because distant, less-reliable neighbors drown out the signal. RankVoting solves this by weighting neighbors based on their rank ($1/(\alpha + \text{rank})$), ensuring that more information leads to better (or at least stable) performance.

RankVoting (right) maintains stable performance as $k$ increases, unlike traditional methods (left).

For maximum performance, the authors also experiment with Gemini re-ranking, where the top 50 retrieved neighbors and their labels are fed into a Vision-Language Model (Gemini 1.5 Flash) to make the final prediction.

Datasets

The authors demonstrate the scalability of this approach across several orders of magnitude:

  • ImageNet-1K: The primary benchmark for million-scale retrieval.
  • JFT-3B: Used to scale the visual memory to one billion images using pseudo-labels.
  • NINCO: An out-of-distribution (OOD) dataset used to test the model's ability to handle entirely new classes.
  • iNaturalist21: A large-scale dataset of plants and animals used to test hierarchical classification and fine-grained granularity.
  • ImageNet-A, -R, -Sketch, -V2, and -ReaL: Used for robust OOD evaluation.

Key Insights and Ideas

  • The Compute-Memory Trade-off: One of the most striking findings is that a smaller, more efficient model with a massive memory can match the performance of a much larger model with a small memory. This suggests a new path for deploying high-performance models on edge devices.
  • The "Rising Tide" Effect: In hierarchical tasks (like iNaturalist), adding just a few samples of a new species doesn't just help identify that species; it improves the model's accuracy across the entire taxonomic branch (genus, family, etc.).
  • Perfect Unlearning: Because the memory is explicit, "forgetting" a specific image or an entire class is mathematically guaranteed—you simply delete the entry from the database. This is a major advantage over weight-based models where "unlearning" is an imprecise research challenge.
  • Robustness to Noise: The system is surprisingly resilient. Performance on ImageNet remains almost unchanged even if 60% of the labels in the memory database are randomly corrupted.

Key Results

The visual memory approach isn't just flexible; it's competitive.

  • Accuracy: Using DinoV2-L/14 with Gemini re-ranking, the system hits 88.5% top-1 accuracy on ImageNet, outperforming standard linear probing (86.3%).
  • Scaling: The authors show that error rates follow a predictable logarithmic decline as the memory size increases, holding true all the way up to a billion images.
Top-1 error rate decreases systematically as memory size increases across different model scales.
  • Interpretability: Decisions are fully attributable. If the model misclassifies a "teddy bear" as a "fence," you can look at the retrieved neighbors and see exactly which training images led to that conclusion (often revealing label errors in the original dataset).

Limitations and Future Work

  • Encoder Dependency: The system is only as good as its fixed encoder. If the underlying embedding space has inherent biases or "blind spots," simply adding more memory may not fix them.
  • Retrieval Cost: While tools like ScaNN make billion-scale search fast (milliseconds), it still requires more infrastructure than a single forward pass through a standard classifier.
  • Distribution Shift: If the "style" of incoming queries changes significantly from the data in memory, the fixed encoder might struggle to produce useful embeddings.

The authors suggest that future work could explore "active" memory management—automatically pruning redundant samples or identifying which new data points would most improve the memory's coverage.

Summary updated

BibTeX
@inproceedings{geirhos2025towards,
  author = {Robert Geirhos and Priyank Jaini and Austin Stone and Sourabh Medapati and Xi Yi and George Toderici and Abhijit Ogale and Jonathon Shlens},
  title = {{Towards flexible perception with visual memory}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=dMYL47aQwb},
}
Figure