Segment Anything In-Context via Visual Demonstrations
Abstract
We present the Segment Anything Model via Visual Demonstrations (SAYD), a foundation model for in-context segmentation. Given visual demos comprising prompt images and their segmentation masks, SAYD segments coherent regions (e.g., objects or their parts) in a query image by establishing visual correspondences between the prompts and the query. SAYD generalizes to previously-unseen segmentation tasks, including those requiring tacit visual knowledge or involving concepts that are difficult to articulate unambiguously in language. We train SAYD on 12 public datasets originally curated for panoptic segmentation using our proposed techniques, including a lightweight mask decoder for prompt-agnostic mask generation and a learning mechanism for recognizing novel query classes absent in the prompts. These innovations enhance both computational efficiency and out-of-domain generalization. Consequently, SAYD significantly outperforms existing methods of in-context segmentation and open-vocabulary segmentation across 24 out-of-domain benchmarks, spanning natural, biological, ecological, cosmological, medical, pathological, and satellite imagery.
Figures & tables
| common object categories | uncommon concepts | ||||||||||||||
| Model | GTA | DRAM | CUB | LIP | YouT | NYU | iShape | TigD | Plant | Ant | LDA | JSRT | ODM | Gala | Cell |
| Open-Vocabulary Segmentation | |||||||||||||||
| X-Dec [ 113 ] | 42.87 | 27.90 | o 3.53 | o 4.14 | 32.78 | 33.51 | 25.10 | o 1.43 | o 1.54 | o 1.03 | 28.72 | o 9.86 | o 0.84 | o 0.09 | o 0.66 |
| O-SeeD [ 37 ] | 41.21 | 25.93 | o 0.11 | o 1.82 | o 7.95 | 31.04 | 11.70 | o 0.19 | o 1.09 | o 5.25 | 13.02 | o 4.85 | o 1.23 | o 0.01 | o 1.90 |
| APE [ 86 ] | 24.62 | 53.23 | o 0.00 | 13.05 | 28.24 | 42.33 | 21.01 | o 4.29 | o 1.32 | o 2.01 | 18.17 | o 0.64 | o 0.74 | o 0.03 | o 0.37 |
| G-SAM [ 81 ] | 42.88 | 42.08 | o 0.02 | 16.95 | 14.15 | 29.45 | o 5.45 | o 7.89 | o 0.04 | o 8.78 | 10.84 | 11.34 | o 0.22 | o 3.12 | o 0.43 |
| Instance Segmentation | Panoptic Segmentation | ||||||||
| Model | PhenoBench | Fashionpedia | iSAID | ScanNet | TrashCan | WildDash2 | BSB | PASTIS | Hypersim |
| DINOv [ 55 ] | o 9.26 | 12.45 | o 4.28 | o 1.29 | o 0.55 | o 3.51 | 10.16 | o 0.78 | 26.40 |
| SAM3 [ 11 ] | 18.71 | 34.93 | 11.56 | o 9.75 | 11.72 | 16.53 | 21.60 | 13.61 | 43.25 |
| SAYD (ours) | 16.28 | 27.60 | 15.44 | 13.56 | 14.03 | 16.30 | 22.89 | 19.52 | 53.30 |
| Model | #Params | Memory | FLOPs | Image | Prompt |
| (M) | (GB) | (T) | runs | runs | |
| WeVisOne [ 58 ] | 4100.0 | 22.6 | 14.5 | ||
| SAM3 [ 11 ] | 840.5 | 4.0 | 1.8 | 1 | |
| DINOv [ 55 ] | 224.6 | 3.4 | 1.6 | ||
| INSID3 [ 23 ] | 303.2 | 3.4 | 2.5 | ||
| SAYD | 310.7 | 1.6 | 0.3 | 1 | 1 |
| arch. | Params | FLOPs | DRAM | TigD | Ant | LDA | Gala |
| a (ours) | 6.31M | o 2.20G | 59.20 | 12.69 | 31.76 | 39.85 | 10.54 |
| b-1 | 7.37M | 25.25G | 50.45 | o 5.12 | 22.49 | 30.98 | o 2.80 |
| b-2 | 7.37M | o 2.31G | 52.96 | 11.32 | 25.27 | 33.24 | o 2.51 |
| DINOv3 | PixIO | |||||||
| ft? | DRAM | TigD | ft? | DRAM | TigD | ft? | DRAM | TigD |
| ✗ | 1.83 | 0.46 | ✗ | 14.45 | 7.31 | ✗ | 10.34 | 6.48 |
| 59.20 | 12.69 | 40.83 | 10.08 | 45.02 | 13.83 | |||
| temp. | bias | DRAM | TigD | Ant | LDA | Gala |
| ✗ | ✗ | fail | fail | fail | fail | fail |
| ✗ | 10.79 | 0 7.76 | 0 5.27 | 10.86 | 0 4.37 | |
| ✗ | fail | fail | fail | fail | fail | |
| 59.20 | 12.69 | 31.76 | 39.85 | 10.54 |
| DRAM | TigD | Ant | LDA | Gala | |
| ✗ | 54.25 | 10.72 | 27.60 | 34.06 | 0 3.24 |
| 59.20 | 12.69 | 31.76 | 39.85 | 10.54 |
| loss | ignota | DRAM | TigD | Ant | LDA | Gala |
| CE | ✗ | 31.44 | 0 1.41 | 10.80 | 12.12 | 0 3.41 |
| CE | 37.59 | 0 2.20 | 11.92 | 19.28 | 0 2.72 | |
| BCE | ✗ | 54.25 | 10.72 | 27.60 | 34.06 | 0 3.24 |
| BCE | 59.20 | 12.69 | 31.76 | 39.85 | 10.54 |
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
| dataset & link | description | mask type | #images | #masks |
| Training | ||||
| ADE20K [ 112 ] | Natural scenes; object and stuff annotations | Panoptic | 20.2k | 271.2k |
| COCO [ 60 ] | Everyday scenes; thing and stuff annotations | Panoptic | 118.3k | 1,330.0k |
| COCONut [ 26 ] | high-quality, densely annotated COCO extension | Panoptic | 488.3k | 5,836.0k |
| PASCAL Panoptic [ 67 ] | Natural scenes; object- and part-level annotations | Panoptic | 10.1k | 69.1k |
| Mapillary Vistas [ 72 ] | Street-level scenes from geographically diverse locations | Panoptic | 18.0k | 1234.5k |
| Model | Image encoder | Params (M) | Image size |
| X-Dec [ 113 ] | Focal-L | 341.6 | 512 2 |
| O-SeeD [ 37 ] | Swin-T | 116.2 | 512 2 |
| APE-D [ 86 ] | ViT-L | 1,074.7 | 800 † |
| G-SAM [ 81 ] | Swin-B | 396.8 | 1,024 2 |
| O-SAM [ 104 ] | ViT-H | 902.9 | 1,024 2 |
| R-SAM [ 73 ] | C-RADIOv3-B | 493.1 | 896 2 |
Semantic Segmentation
Semantic segmentation assigns a class label to every image pixel, enabling detailed scene understanding across domains and sensors.
See all 460 papers