Abstract
SAMIC (Segment Anything with In-Context Spatial Prompt Engineering) is a lightweight, 2.6-million-parameter model designed to adapt the Segment Anything Model (SAM) to new objects using only a few examples. By learning to generate precise spatial point prompts rather than full masks, SAMIC outperforms much larger specialist models and training-free methods across diverse tasks, including aerial, medical, and video segmentation.
Introduction
The Segment Anything Model (SAM) has established a new baseline for promptable segmentation. However, SAM often falters in "few-shot" scenarios where a specific object type (e.g., a specific medical anomaly) must be segmented based on a single reference image. Current solutions typically involve either massive, resource-heavy specialist models or training-free methods that rely on raw feature embeddings, which are often brittle and sensitive to environmental changes. SAMIC addresses this by learning to "teach" SAM task-specific context through spatial prompt engineering.
Methodology
SAMIC treats segmentation as an in-context spatial prompt engineering problem. Instead of predicting a pixel-wise mask, it predicts a saliency heatmap that guides SAM.
Architecture
The model utilizes the Hypercorrelation Squeeze Network (HSNet) architecture with a frozen ResNet-50 backbone. It constructs a 4D hypercorrelation pyramid to capture both semantic and geometric similarities between reference "in-context" images and target images.
Heatmap-to-Prompt Pipeline
The core of SAMIC is its ability to translate feature correlations into a 2D Gaussian heatmap. A peak-detection algorithm identifies the most relevant points, which are then converted into point prompts for SAM’s prompt encoder. SAM then generates the final high-quality mask.
SAMBOX Tool
To facilitate rapid data preparation, the authors introduced SAMBOX, an interactive tool that allows users to provide unambiguous prompts significantly faster than traditional pixel-wise labeling.
Experimental Results
SAMIC was evaluated across nine benchmark datasets, including COCO-20i, PerSeg, and domain-specific sets like Kvasir-SEG (medical) and NWPU VHR-10 (aerial).
Performance and Efficiency
- Model Size: At only 2.6M parameters, SAMIC is 94% smaller than many specialist models.
- Accuracy: It achieved a 97.5% mIoU on the PerSeg dataset, a 10% improvement over previous state-of-the-art methods.
- Domain Adaptation: In specialized tasks like landslide detection, SAMIC demonstrated a +35.3% gain over existing prompt-engineering methods.
- Inference Speed: The model maintains a fast inference time of ~25ms.
Discussion and Limitations
SAMIC's primary innovation is learning "where" an object is rather than "what" it looks like, leveraging SAM's existing mask-generation capabilities. This approach resolves common "part-whole" ambiguities by providing multiple point prompts across an object's embedding clusters.
However, limitations remain. In low-contrast medical environments, SAM may still struggle with boundary definition even with accurate prompts. Additionally, the current version lacks temporal memory for video object segmentation (VOS), processing frames independently.
Conclusion
SAMIC demonstrates that small, efficient models can effectively steer large foundation models like SAM for complex, few-shot tasks. By focusing on spatial prompt engineering, it achieves superior robustness and accuracy across diverse domains with minimal training data.
Summary updated