NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Diffuse, Attend, and Segment: Unsupervised Zero-Shot Segmentation using Stable Diffusion

Junjiao Tian, Lavisha Aggarwal, Andrea Colaco, Zsolt Kira, Mar González-Franco

Abstract

We present DiffSeg, a novel unsupervised, zero-shot segmentation algorithm that extracts high-quality image masks directly from a pre-trained Stable Diffusion model. Unlike traditional methods that require extensive manual annotations or dataset-specific training, DiffSeg leverages the internal self-attention mechanisms of generative models. By aggregating multi-resolution attention maps and employing an iterative merging strategy based on KL divergence, the algorithm identifies object boundaries and semantic regions with high precision. DiffSeg achieves a 26% boost in pixel accuracy over previous state-of-the-art unsupervised methods on the COCO-Stuff-27 benchmark and demonstrates robust generalization across diverse domains, including sketches and synthetic art.

Introduction

Semantic segmentation—the task of partitioning an image into meaningful regions—is a cornerstone of computer vision. However, it typically relies on massive datasets of pixel-perfect human annotations, which are expensive and slow to produce. While recent foundation models like the Segment Anything Model (SAM) have shown remarkable zero-shot capabilities, they still require billions of training masks. This paper explores an alternative: can we extract segmentation knowledge "for free" from generative models not explicitly trained for the task? Stable Diffusion, a model trained to generate images by denoising, must inherently understand object boundaries to maintain coherence. DiffSeg taps into this latent knowledge to perform segmentation without any additional training or manual labels.

Methodology

The DiffSeg pipeline consists of three primary stages: Attention Aggregation, Iterative Attention Merging, and Non-Maximum Suppression (NMS).

The DiffSeg pipeline: from Stable Diffusion attention maps to final segmentation masks.

1. Attention Aggregation

Stable Diffusion generates self-attention maps at various resolutions (e.g., $8 \times 8$ to $64 \times 64$). DiffSeg upsamples these maps and combines them using a proportional aggregation scheme. This approach balances fine details from high-resolution maps with the global consistency provided by lower resolutions, ensuring that both small objects and large semantic regions are captured.

2. Iterative Attention Merging

To avoid the limitations of standard clustering techniques like K-Means, which require a predefined number of clusters, DiffSeg employs an iterative merging strategy. Starting from a grid of anchor points, the algorithm calculates the KL divergence (a measure of difference between probability distributions) between attention maps. Maps with similarity below a specific threshold $\tau$ are merged iteratively until only distinct object proposals remain. This process allows the model to be deterministic and adaptive to the number of objects present in an image.

Detailed view of the upsampling, merging, and final prediction process.

3. Non-Maximum Suppression (NMS)

Finally, overlapping object proposals are refined through Non-Maximum Suppression. Each pixel is assigned to the mask where it exhibits the highest probability, resulting in a clean, final segmentation map.

Experiments and Results

DiffSeg was evaluated on several challenging benchmarks, including COCO-Stuff-27, Cityscapes, DomainNet (Sketch & Painting), and SUN-RGBD.

  • Performance: On COCO-Stuff-27, DiffSeg significantly outperformed the previous state-of-the-art (ReCo), achieving a 26% absolute increase in pixel accuracy and a 17% increase in mean Intersection over Union (mIoU).
  • Generalization: The method's reliance on Stable Diffusion's massive pre-training (LAION-5B) allows it to generalize effectively to non-photorealistic styles, such as sketches and oil paintings, without any domain-specific fine-tuning.
  • Consistency: Qualitative results demonstrate impressive performance on diverse imagery, including satellite data and brain CT scans, using the same set of hyper-parameters.

Discussion and Limitations

The success of DiffSeg suggests that generative knowledge is inherently linked to segmenting knowledge; a model that can create a chair must implicitly know where that chair ends. By moving beyond standard clustering, DiffSeg provides a more flexible approach to zero-shot segmentation. However, limitations remain, including the resolution bottleneck of internal attention maps (capped at $64 \times 64$) and the computational overhead of the iterative merging process compared to feed-forward CNNs. Future improvements in diffusion model architectures are expected to further enhance the precision of this "free" segmentation capability.

Summary updated

BibTeX
@inproceedings{tian2023diffuse,
  author = {Junjiao Tian and Lavisha Aggarwal and Andrea Colaco and Zsolt Kira and Mar González-Franco},
  title = {{Diffuse, Attend, and Segment: Unsupervised Zero-Shot Segmentation using Stable Diffusion}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
}
Figure