Retrieval-Augmented Visual Prompting: Guiding Foundation Models in Two-Photon Imaging
Organizations: PeRCeiVe Lab Department of Electrical, Electronic and Computer Engineering University of Catania, Catania, Italy
Abstract
Two-photon calcium imaging presents a challenging setting for foundation models: image appearance varies substantially across recordings and experimental conditions, annotations are scarce, and rapid adaptation is often needed. Rather than adapting model weights through fine-tuning, we ask whether a foundation model can be guided at inference time by injecting external visual memory directly into its input. We implement this idea with SAM 3 and introduce Retrieval-Augmented Visual Prompting (RAVP), a framework in which each target tile is augmented with a retrieved annotated exemplar whose bounding box is used as a concept prompt. RAVP turns retrieval into a form of visual prompting and enables adaptation through input design alone. We study multiple exemplar selection strategies, including fluorescence-guided heuristics and a lightweight recall predictor trained to estimate which exemplar is most informative for a target tile. Experiments on the Allen Brain Observatory show that exemplar-augmented inference consistently strengthens zero-shot neuron detection and instance segmentation. Ablation studies further show that a single carefully selected exemplar is more effective than prompting with multiple retrieved examples. These results position inference-time visual memory injection as a simple and effective alternative to parameter adaptation for foundation models in specialized biomedical imaging.
Figures & tables
| ABO in-domain | OOD | STNeuroNet subset | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| SAM 3 (zero-shot) | 0.277 | 0.767 | 0.407 | 0.117 | 0.802 | 0.204 | 0.405 | 0.736 | 0.523 |
| SAM 3 + Enc. FT | 0.687 | 0.862 | 0.764 | 0.630 | 0.894 | 0.739 | 0.737 | 0.828 | 0.780 |
| SAM 3 + LoRA | 0.676 | 0.850 | 0.730 | 0.646 | 0.870 | 0.741 | 0.751 | 0.844 | 0.795 |
| SAM 3 + Full FT | 0.630 | 0.818 | 0.712 | 0.594 | 0.880 | 0.709 | 0.685 | 0.796 | 0.737 |
| SAM 3 + Lib. (Recall Predictor) | 0.528 | 0.736 | 0.615 | 0.468 | 0.786 | 0.587 | 0.609 | 0.732 | 0.665 |
| ABO in-domain | OOD | STNeuroNet subset | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| SAM 3 (zero-shot) | 0.279 | 0.750 | 0.407 | 0.117 | 0.789 | 0.200 | 0.403 | 0.735 | 0.521 |
| SAM 3 + Enc. FT | 0.704 | 0.866 | 0.777 | 0.606 | 0.868 | 0.713 | 0.744 | 0.825 | 0.782 |
| SAM 3 + LoRA | 0.703 | 0.865 | 0.776 | 0.644 | 0.858 | 0.736 | 0.764 | 0.844 | 0.802 |
| SAM 3 + Full FT | 0.657 | 0.834 | 0.735 | 0.583 | 0.850 | 0.692 | 0.697 | 0.793 | 0.742 |
| SAM 3 + Lib. (Recall Predictor) | 0.541 | 0.712 | 0.615 | 0.468 | 0.732 | 0.571 | 0.613 | 0.714 | 0.660 |
| ABO in-domain | OOD | STNeuroNet subset | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| SAM 3 (zero-shot) | 0.277 | 0.767 | 0.407 | 0.117 | 0.802 | 0.204 | 0.405 | 0.736 | 0.523 |
| + Lib. ( Random ) | 0.446 | 0.669 | 0.535 | 0.500 | 0.752 | 0.601 | 0.473 | 0.641 | 0.544 |
| + Lib. ( Image-adaptive ) | 0.453 | 0.678 | 0.543 | 0.476 | 0.736 | 0.578 | 0.499 | 0.657 | 0.567 |
| + Lib. ( Fixed fluor. , ) | 0.469 | 0.673 | 0.553 | 0.483 | 0.751 | 0.588 | 0.565 | 0.694 | 0.623 |
| + Lib. ( Recall Predictor ) | 0.528 | 0.736 | 0.615 | 0.468 | 0.786 | 0.587 | 0.609 | 0.732 | 0.665 |
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
| ABO in-domain | OOD | STNeuroNet subset | |||||||
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| MedSAM 3 (zero-shot) | 0.470 | 0.651 | 0.546 | 0.483 | 0.726 | 0.580 | 0.502 | 0.620 | 0.554 |
| MedSAM 3 + Enc. FT | 0.691 | 0.836 | 0.756 | 0.641 | 0.853 | 0.732 | 0.734 | 0.815 | 0.773 |
| MedSAM 3 + LoRA | 0.651 | 0.816 | 0.724 | 0.607 | 0.833 | 0.702 | 0.727 | 0.809 | 0.766 |
| MedSAM 3 + Full FT | 0.628 | 0.806 | 0.706 | 0.585 | 0.840 | 0.690 | 0.689 | 0.784 | 0.733 |
| MedSAM 3 + Lib. (Random) | 0.481 | 0.630 | 0.546 | 0.506 | 0.690 | 0.584 | 0.501 | 0.600 | 0.546 |
| ABO in-domain | OOD | STNeuroNet subset | |||||||
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| MedSAM 3 (zero-shot) | 0.495 | 0.661 | 0.566 | 0.480 | 0.691 | 0.566 | 0.523 | 0.636 | 0.574 |
| MedSAM 3 + Enc. FT | 0.703 | 0.837 | 0.764 | 0.628 | 0.834 | 0.716 | 0.728 | 0.799 | 0.762 |
| MedSAM 3 + LoRA | 0.672 | 0.828 | 0.742 | 0.606 | 0.827 | 0.699 | 0.736 | 0.805 | 0.769 |
| MedSAM 3 + Full FT | 0.650 | 0.818 | 0.724 | 0.591 | 0.833 | 0.692 | 0.691 | 0.774 | 0.730 |
| MedSAM 3 + Lib. (Random) | 0.525 | 0.660 | 0.585 | 0.508 | 0.676 | 0.580 | 0.543 | 0.636 | 0.586 |
| ABO in-domain | OOD | STNeuroNet subset | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Method | AP 50 | AR 50 | H | AP 50 | AR 50 | H | AP 50 | AR 50 | H |
| SAM 3 (zero-shot) | 0.277 | 0.767 | 0.407 | 0.117 | 0.802 | 0.204 | 0.405 | 0.736 | 0.523 |
| + Lib. ( Black no bbox ) | 0.295 | 0.730 | 0.420 | 0.169 | 0.766 | 0.276 | 0.355 | 0.699 | 0.471 |
| + Lib. ( Black keep bbox ) | 0.227 | 0.673 | 0.339 | 0.267 | 0.751 | 0.393 | 0.321 | 0.662 | 0.433 |
| + Lib. ( Random bbox ) | 0.162 | 0.461 | 0.239 | 0.245 | 0.622 | 0.352 | 0.129 | 0.445 | 0.200 |
| + Lib. ( Recall Predictor ) | 0.528 | 0.736 | 0.615 | 0.468 | 0.786 | 0.587 | 0.609 | 0.732 | 0.665 |
Vision Foundation Model Adaptation
Vision foundation model adaptation tailors pretrained image and video models to new tasks and domains while balancing accuracy, efficiency, and generalization.
See all 326 papers