Introduction
Interactive segmentation is a critical task in computer vision, allowing users to extract specific objects from images through simple prompts like foreground and background clicks. While supervised models like Segment Anything (SAM) have set high benchmarks, they rely on massive labeled datasets. Conversely, unsupervised methods often require complex training on pseudo-labels generated from pre-trained backbones.
This paper, presented at CVPR 2024, introduces M2N2 (Markov-Map Nearest Neighbor), a training-free framework that repurposes the internal self-attention mechanisms of Stable Diffusion for high-quality interactive segmentation. By treating attention as a mathematical process of diffusion—specifically a Markov chain—the authors achieve state-of-the-art results without any additional training or fine-tuning.
The M2N2 Framework
The core innovation of M2N2 lies in interpreting the self-attention tensor of a pre-trained Stable Diffusion model as a Markov transition operator. The pipeline consists of four primary stages:
- Attention Aggregation: The system performs a single denoising step using Stable Diffusion 2 (SD2) to extract self-attention tensors from the U-Net layers.
- Markov-maps: Instead of using raw, noisy attention maps, the framework treats the attention tensor as a Markov transition matrix. Starting from a user-provided "seed" click, the matrix is applied iteratively. The "Markov-map" is generated by recording the number of iterations required for each pixel to reach a specific probability threshold. This process effectively propagates semantic information while sharpening boundaries.
- Modified Flood Fill: To ensure instance-awareness and prevent the segment from bleeding into similar nearby objects, a modified flood fill is applied to the Markov-map, suppressing local minima.
- Truncated Nearest Neighbor: Multiple user clicks are integrated using a distance function. Pixels with a high semantic distance to the nearest foreground click are classified as background.
Experimental Setup
The authors evaluated M2N2 across four standard interactive segmentation benchmarks: GrabCut, Berkeley, SBD (Semantic Boundaries Dataset), and DAVIS. These datasets provide a range of challenges, from simple object extraction to complex scenes with high-quality masks. Performance was measured using the NoC85/90 metric (Number of Clicks required to reach 85% or 90% Intersection over Union), where a lower score indicates higher efficiency.
Results and Discussion
M2N2 demonstrates that the latent knowledge within Stable Diffusion is remarkably rich and can be extracted effectively without training.
Performance and Efficiency
On the challenging DAVIS dataset, M2N2 achieved an NoC85 of 4.60, significantly outperforming previous unsupervised state-of-the-art methods like MIS (6.33). The system is also computationally efficient, processing each user click in approximately 0.6 seconds on an RTX 4090 GPU, making it suitable for real-time interactive applications.
Qualitative Advantages
A key benefit of the Markov-map approach is the reduction of noise inherent in raw attention maps. By measuring the "time to reach a threshold," the resulting segments are more uniform and adhere better to object edges.
Limitations
Despite its strengths, M2N2 faces challenges in specialized domains like medical imaging, where Stable Diffusion's natural-image priors (from LAION-5B) do not apply. Additionally, the 128x128 resolution of the U-Net's attention layers can make it difficult to capture extremely fine structures, such as thin wires or bicycle spokes.
Conclusion
M2N2 represents a significant step forward in unsupervised interactive segmentation. By elegantly repurposing the internal mechanics of generative foundation models, it eliminates the need for costly training phases while delivering performance that rivals supervised alternatives. This work highlights the potential of "repurposing" large-scale models for tasks they were not explicitly designed for, opening new avenues for training-free computer vision.
Summary updated