G4Seg: Generation for Inexact Segmentation Refinement with Diffusion Models

Tianjiao Zhang, Fei Zhang, Jiangchao Yao, Ya Zhang, Yanfeng Wang

Introduction

Segmentation—the process of assigning a semantic label to every pixel in an image—is a cornerstone of computer vision. However, obtaining high-quality, pixel-perfect annotations is notoriously expensive and time-consuming. To mitigate this "labeling tax," researchers have turned to Inexact Segmentation (IS), which seeks to generate segmentation masks from high-level supervision such as text prompts or image-level labels.

While recent advances have attempted to extract segmentation maps from the internal attention layers of pretrained Diffusion Models, these methods often treat the model as a passive feature extractor. This frequently results in coarse or noisy masks that struggle with fine-grained boundaries. G4Seg (Generation for Inexact Segmentation) introduces a paradigm shift: instead of just "looking" at the model's features, it utilizes the model's core strength—generation—as a diagnostic tool to refine existing masks in a training-free, plug-and-play manner.

The G4Seg Framework

G4Seg operates on a simple yet powerful intuition: if a segmentation mask is accurate, a diffusion model conditioned on that mask should be able to reconstruct an image that is semantically consistent with the original. Discrepancies between the original and the reconstructed image serve as a signal to identify and correct errors in the mask.

The framework consists of three primary stages:

1. Explicit Mask Injection (EMI)

Rather than a full multi-step generation process, G4Seg uses a highly efficient one-step denoising approach. The original image is perturbed with noise at a specific timestep (typically $t=400$). During the denoising step, the coarse (inexact) mask is injected into the model’s self-attention and cross-attention layers. This forces the Stable Diffusion model to generate a "reconstructed" version of the image that adheres to the layout provided by the coarse mask.

2. Semantic Correspondence Alignment (SCA)

Because the initial mask is imperfect, the generated image will inevitably exhibit "pattern discrepancies" compared to the original. For instance, an object might be slightly shifted or its shape altered. G4Seg employs a CLIP image encoder to establish pixel-level correspondences between the original image and the generated reconstruction, allowing the system to map where the generative model deviated from the source.

3. Probability Updating

The final stage involves a feedback loop where the semantic gap between paired pixels is calculated. The system evaluates whether a pixel in the generated image aligns with the foreground object in the original. Using a linear mixing strategy, the foreground probabilities are updated to produce a Refined Map with significantly improved boundary accuracy.

Theoretical Grounding

The authors provide a Bayesian interpretation of this process, demonstrating that maximizing the probability of a mask given an image is mathematically equivalent to minimizing the distance between the original image and a mask-conditioned generated version. This provides a formal justification for using generative feedback as a refinement signal.

Experimental Results

G4Seg was evaluated across three major benchmarks: PASCAL VOC12, PASCAL Context, and MS COCO Object 2014. The method was tested in both Text-Supervised (TSSS) and Weakly-Supervised (WSSS) settings, demonstrating broad compatibility with various baseline models.

Key Findings:

  • Performance Gains: When integrated with baselines like SCLIP or DiffSegmenter, G4Seg achieved new State-of-the-Art (SOTA) results, with mean Intersection over Union (mIoU) improvements ranging from 0.7% to 1.0%.
  • Weakly Supervised Success: In the WSSS setting using CLIP-ES, G4Seg improved seed mask accuracy by 1.2% on PASCAL VOC12.
  • Qualitative Superiority: Visual analysis confirms that G4Seg excels at "cleaning up" complex boundaries, such as the thin legs of an animal or the intricate masts of a ship, which are often lost in coarse baseline masks.
  • Model Agnostic: The framework proved robust across different versions of Stable Diffusion (1.5, 2.1, SDXL) and even distilled models like the Latent Consistency Model (LCM).

Limitations and Future Work

While effective, G4Seg does introduce some computational overhead. Even with one-step denoising, processing an image takes approximately 1.1 to 1.2 seconds on an RTX 3090, which is slower than purely discriminative approaches. Additionally, the method relies on the generative priors of the underlying model; if the initial mask is extremely poor (IoU < 40%) or the image falls into a specialized domain (e.g., medical imaging) not well-represented in the training data, the refinement gains may be limited.

Future research directions include optimizing the sampling speed and exploring the application of G4Seg to the latest generation of large-scale generative models like SD3 or Flux.

Summary updated

BibTeX
@inproceedings{zhang2025g,
  author = {Tianjiao Zhang and Fei Zhang and Jiangchao Yao and Ya Zhang and Yanfeng Wang},
  title = {{G4Seg: Generation for Inexact Segmentation Refinement with Diffusion Models}},
  booktitle = {ICME},
  year = {2025},
  doi = {10.1109/icme59968.2025.11209439},
}
Figure