How iSeg Refines Stable Diffusion Attention for Segmentation

Analysis by the aitrendblend editorial team  |  Generative AI and diffusion models  |  14 minute read
training free segmentation Stable Diffusion iterative refinement entropy reduced self attention open vocabulary
Diagram of iSeg refining Stable Diffusion cross attention and self attention maps into a clean training free segmentation mask
How iSeg turns raw Stable Diffusion attention maps into stable object masks without any segmentation training.
A model that was built to paint pictures already knows, in some rough sense, where the dog ends and the grass begins. Stable Diffusion learned that boundary from billions of captioned images, never once being told to draw an outline. The tempting move is to read the object shapes straight out of its attention maps and skip segmentation training entirely. It almost works. The catch is that the obvious way of sharpening those maps tends to smear objects together, and iSeg is a careful study of why that happens and how to stop it.

Key points

  • iSeg performs image segmentation with a frozen Stable Diffusion model and no training on any segmentation dataset.
  • The authors show that naively refining a cross attention map with a self attention map many times makes results worse, not better, because global noise accumulates.
  • An entropy reduced self attention module, called Ent-Self, suppresses those weak far away responses so refinement stays stable across many iterations.
  • A category enhanced cross attention module, called Cat-Cross, gives the loop a cleaner starting point by weighting the text of the requested classes.
  • On unsupervised segmentation for Cityscapes iSeg reports an absolute gain of 3.8 percent mIoU over the best prior training free method.
  • The whole method runs at roughly 0.16 seconds per image and works as a drop in post processing step for other approaches.

The problem runs deeper than a missing label

Semantic segmentation, the task of deciding which class every pixel belongs to, has always carried an awkward cost. To train a supervised model you need someone to color in every pixel of every training image across a fixed list of classes. That is slow, expensive, and it locks the model into the categories it was shown. Ask a Cityscapes trained network about an animal it never saw and it has nothing useful to say.

So researchers keep chasing a training free path. If a large pre trained model already carries a strong sense of what objects are, maybe you can extract masks from it directly and pay no annotation cost at all. CLIP opened this door by linking text and images, and a wave of work leaned on it. The newer idea, and the one this paper builds on, is that text to image diffusion models carry an even richer spatial signal. Stable Diffusion was trained on the enormous LAION-5B collection of captioned images purely to synthesize pictures, and to do that well it has to keep an internal map of where each described thing sits in the frame.

That internal map lives in two attention mechanisms inside the denoising network. Self attention relates one spatial position in the image to every other position, which captures how pixels group into coherent regions. Cross attention relates image positions to the words in the prompt, which is what tells you where the cat is versus the dog. The natural recipe writes itself. Take the cross attention map for the word cat, sharpen it using the self attention map so that pixels which behave alike get pulled together, and read off a mask. Prior work such as DiffSegmenter and Dataset Diffusion did exactly this kind of single refinement.

Here is where it gets interesting. If refining once helps, refining again should help more. iSeg tests that assumption and finds it false.

Why more refinement quietly breaks

The team, Lin Sun, Jiale Cao, Jin Xie, Fahad Shahbaz Khan, and Yanwei Pang from Tianjin University, Shanghai Artificial Intelligence Laboratory, Chongqing University, and the Mohamed bin Zayed University of Artificial Intelligence, start with what they call naive iterative refinement. You multiply the cross attention map by the self attention map, normalize, and repeat. Formally the map at step n is built from the map at step n minus one.

$$A^{n}_{ca} = A_{sa} \times A^{n-1}_{ca}, \qquad n = 1, \dots, N$$

Watch what happens across iterations and three patterns appear. Sometimes the map for an object gets cleaner, which is the hoped for case. Sometimes it bloats and swallows nearby regions. And sometimes it drifts away entirely, so the map for a dog lights up strongly on a person standing beside it. Averaged over a real dataset the quality climbs for a step or two and then falls. The paper shows this clearly on pseudo mask generation for PASCAL VOC, where accuracy peaks early and then declines as iterations pile up.

The diagnosis is elegant. A predicted self attention map is not clean. Every pixel has a small amount of response spread across the whole image, a kind of low level global hum from irrelevant regions. Multiply by it once and that hum barely matters. Multiply by it again and again and the faint global connections compound, so each refinement drags in a little more far away context until the object boundary dissolves. To prove the noise is the culprit the authors ran a control using a ground truth self attention map, one built from real masks so that it is exactly binary and responds only inside the true object. With that clean map, a single iteration already gives a stable accurate result and further iterations do no harm. The lesson is blunt. Stability was never about the number of iterations. It was about how much irrelevant global information the self attention map smuggles in.

Key takeaway

The failure of repeated refinement is not a diffusion quirk. It is an accumulation problem. Weak global responses in the self attention map are almost harmless once and increasingly harmful when compounded, so the fix has to attack those weak responses rather than the loop itself.

The entropy reduced self attention module

iSeg does not change the refinement loop. It cleans the map that the loop multiplies by. The tool it reaches for is entropy. If you treat each row of a normalized self attention map as a probability distribution over positions, a sharp confident row that points at one region has low entropy, while a diffuse row that spreads thin attention everywhere has high entropy. High entropy is exactly the global smearing the authors want gone.

So they compute the entropy of the self attention map and then nudge the map to reduce it. After a max min normalization that puts every element between zero and one, the entropy is a straightforward sum over all positions.

$$E = -\sum_{i=1}^{HW}\sum_{j=1}^{HW} A_{sa}[i,j]\,\log\!\big(A_{sa}[i,j]\big)$$

The gradient of that entropy with respect to any single element has a clean closed form.

$$\frac{dE}{dA_{sa}[i,j]} = -\big(1 + \log(A_{sa}[i,j])\big)$$

One gradient step along the direction that lowers entropy, followed by a clamp that throws away anything negative, produces the entropy reduced map. The update factor lambda controls how hard the step pushes.

$$A_{ent}[i,j] = \mathrm{ReLU}\!\left(A_{sa}[i,j] – \lambda\,\frac{dE}{dA_{sa}[i,j]}\right)$$

The effect is intuitive once you see it. Values already near one grow a little, values already near zero shrink toward nothing, and the weak middling responses that carried the global hum get pushed below zero and clamped out. A final renormalization restores a valid distribution. The refinement loop then multiplies by this cleaned map instead of the raw one, and the compounding problem largely disappears. The paper offers a second reading of the same idea. Multiplying by the entropy reduced map many times is roughly like building a better and better self attention map, one that keeps getting closer to the binary ground truth version, and then using it to sharpen the cross attention. Either way you look at it, the loop stays stable as iterations grow instead of collapsing.

Stability was never about how many times you refine. It was about how much of the world beyond the object you let each refinement pull in. A plain reading of the iSeg analysis

A cleaner starting point with Cat-Cross

A good loop still needs a good input. If the very first cross attention map is muddy, refinement has more work to do and more chance to wander. The second module, category enhanced cross attention or Cat-Cross, tackles that. When you feed Stable Diffusion a prompt naming several categories, the words for the class you care about compete with every other token, including background words. Cat-Cross simply amplifies the text embeddings of the requested categories by a weighting factor before the cross attention is computed.

$$W[j] = \begin{cases}\gamma, & \text{if } j \in C\\ 1, & \text{if } j \notin C\end{cases}\qquad A_{ca} = \mathrm{Softmax}\!\left(\frac{Q\,(W * K)^{T}}{\sqrt{d}}\right)$$

Here gamma is larger than one and the star is elementwise multiplication on the key, which carries the text. Turning up the requested class words and leaving the rest at their normal strength yields a cross attention map with stronger response on the real object and less clutter on background or competing classes. It is a small change and the authors present it as such, but it gives the iterative loop a noticeably better place to begin.

Put together, the full pipeline reads cleanly. Extract latent features with the VAE encoder, build category enhanced text embeddings with Cat-Cross, pull the cross attention and self attention maps out of the denoising network at a fixed timestep of 100, clean the self attention map with Ent-Self, then run the refinement loop for N steps and binarize the result. Everything downstream of the pre trained weights is parameter free arithmetic. There is no training on any segmentation data at any point.

What the numbers actually show

iSeg is tested across four fairly different jobs. Weakly supervised segmentation, where only image level class labels are available and you must invent pixel masks. Open vocabulary segmentation, where the class list is arbitrary and unseen. Unsupervised segmentation, where no labels exist at all and you only group pixels. And mask generation for synthetic images produced by diffusion. That spread matters, because a training free trick that only helps on one benchmark is usually overfitting to that benchmark’s quirks.

Task and datasetMetriciSeg resultReference point from the paper
Weakly supervised, PASCAL VOC trainmIoU75.22.5 above diffusion based T2M, 4.4 above CLIP-ES
Weakly supervised, MS COCO trainmIoU45.51.8 above T2M
Open vocabulary, VOC valmIoU68.28.1 above DiffSegmenter
Open vocabulary, PASCAL-Context valmIoU30.93.4 above DiffSegmenter
Open vocabulary, COCO Object valmIoU38.40.5 above DiffSegmenter, 3.6 above OVDiff
Unsupervised, Cityscapes valmIoU+3.8absolute gain over best prior training free method
Unsupervised, Cityscapes valACC+2.7gain over DiffSeg baseline

A few of these deserve a comment. On weakly supervised VOC the training free iSeg does not merely beat other training free methods. It edges past several methods that were actually trained, coming in 3.0 points above ToCo and 9.0 above WeakTr, and lands comparable to the SAM based S2C. That is a strange and welcome result, a model with zero segmentation training matching ones that had it. On open vocabulary VOC the margin over the earlier ViewCo reaches 15.8 points, which is less about iSeg being magic and more about how much signal the older CLIP only methods left on the table.

The unsupervised numbers are the cleanest demonstration of the core idea, because there iSeg is bolted onto DiffSeg purely as a post processing refinement. The 3.8 point mIoU jump on Cityscapes comes from nothing but running the entropy reduced loop on top of an existing method’s output. When the same trick lifts an unrelated pipeline, the mechanism is doing the work rather than the surrounding engineering.

Key takeaway

The strongest evidence is not any single leaderboard row. It is that one small, parameter free module improves four different tasks and also improves other people’s methods when dropped in as a post processing step.

The ablations that hold the story together

Two modules, so the obvious question is which one earns its keep. On weakly supervised VOC the baseline that refines just once sits at the bottom. Adding Ent-Self alone lifts it by 3.8 points. Adding Cat-Cross alone helps too. Using both together improves the baseline by 7.0 points on VOC and by 4.5 points on both VOC and COCO for open vocabulary. The two modules are addressing different weaknesses, a noisy loop and a muddy starting map, so their gains stack rather than overlap.

The hyper parameter sweeps are reassuringly boring, which is what you want from a method that claims to generalize. Performance climbs with the iteration count N and settles at its best around ten iterations, exactly the regime where the naive baseline would have fallen apart. The update factor lambda works best near 0.01 and the class weighting gamma peaks around 1.6, both with gentle falloff on either side rather than a knife edge. The authors also confirm the modules help across Stable Diffusion V1.4, V1.5, and V2.1, improving each by 5.2, 4.0, and 7.0 points, so the idea is not wedded to one checkpoint.

The honest cost, and where it fails

None of this comes for free. The largest asterisk is compute. Stable Diffusion is a heavy backbone next to a plain vision transformer or a CLIP encoder. The paper is candid with the numbers. A ViT based MCTFormer needs about 69.5 GFLOPs and CLIP-ES about 35.3, while diffusion based methods live in another world entirely. DiffSegmenter costs roughly 2610.6 GFLOPs. iSeg is far lighter than that at 902.6 GFLOPs, a real improvement over its diffusion peers, but still an order of magnitude above the CLIP based options. Inference lands around 0.16 seconds per image with half precision and about 5 gigabytes of memory, which is practical, though the underlying arithmetic is far from cheap.

The method also inherits every weakness of the model it rides on. When Stable Diffusion produces a genuinely noisy attention map, the refinement has nothing clean to sharpen. The authors show honest failure cases on camouflage imagery from the CAMO dataset, where an occluded lion, a camouflaged sheep, a tiny bird, and a camouflaged spider all defeat it. In those scenes neither the cross attention nor the self attention map starts out accurate enough for the loop to rescue. The paper also flags that the ideal number of iterations really depends on the image, and that a single fixed count is a compromise. They point to image aware refinement and adapter based cleanup of the initial maps as future directions.

There is a broader limitation worth stating plainly. Every result here is measured against benchmark validation sets under controlled conditions. A method that segments PASCAL VOC and Cityscapes cleanly has not been shown to hold up on medical scans, satellite imagery, or any domain far from the natural photos and captions Stable Diffusion was trained on. The cross domain sketch and painting results are encouraging on that front, but they are still visual object categories close to the training distribution.

Why this direction matters beyond one paper

Step back and the appeal is the reuse. A generative model trained only to make images turns out to hold a segmentation model inside it, and iSeg extracts that capability with arithmetic rather than data collection. That reframes what a foundation model is for. The same weights serve synthesis and dense prediction, and the marginal cost of the second task is a bit of clever normalization.

The entropy argument is also more general than segmentation. Any time you refine one attention derived signal by repeatedly multiplying it against another, you risk this same slow accumulation of noise. The idea of measuring the entropy of an attention distribution and pushing it down before you compound it could travel to other training free extraction problems, from keypoints to depth cues to grounding. That is the part practitioners in adjacent areas should watch, because the modules are small enough to try in an afternoon.

Conclusion

iSeg is a good example of a paper that wins by taking a failure seriously instead of papering over it. The field had settled into refining diffusion attention maps once and calling it done, and the unspoken assumption was that refining more would only help. By actually running that experiment and watching quality collapse, the authors found a concrete, fixable cause, the compounding of weak global responses in a noisy self attention map.

The fix is proportionate to the diagnosis. Rather than redesigning the loop or bolting on another trained network, they clean the input to the loop with an entropy step that has a closed form gradient and no learned parameters, and they warm start the loop with a lightly reweighted cross attention map. Two small ideas, both cheap, both explainable in a sentence.

What gives the work weight is breadth. The same pair of modules lifts weakly supervised, open vocabulary, and unsupervised segmentation, improves synthetic mask generation, and works as a post processing layer on other methods including non diffusion ones built on DINO and CLIP. A trick that helps everywhere it is tried is usually touching something real about the problem rather than exploiting one dataset.

The remaining honesty is welcome too. The compute bill is high, camouflage and noisy prompts still break it, and the right iteration count is image dependent. Those are the seams a follow up should pull at, and the authors say as much. For now iSeg stands as a clear demonstration that a painter of images already knows a great deal about where objects are, if you are careful about how you ask.

The larger message is quieter and more durable. As generative models keep absorbing the visual world, a growing share of the tasks we used to train separately may already be latent in their weights, waiting for the right readout. iSeg is one careful readout. It will not be the last.

Reference implementation in PyTorch

The listing below is a compact, runnable reconstruction of the iSeg refinement pipeline based on the equations and algorithm in the paper. It uses stand in attention maps so it runs on any machine without downloading Stable Diffusion, and it ends with a smoke test on dummy data. Swap the placeholder extractor for real Stable Diffusion attention maps to reproduce the full method.

# iseg_refine.py
# Minimal, runnable reconstruction of the iSeg training free
# refinement pipeline. Attention maps are stand ins so the file
# runs without Stable Diffusion. Replace extract_maps() with a real
# Stable Diffusion hook to reproduce the paper.

import torch
import torch.nn.functional as F


def minmax_norm_lastdim(x, eps=1e-6):
    """Max min normalization along the last dimension, maps to [0, 1]."""
    x_min = x.min(dim=-1, keepdim=True).values
    x_max = x.max(dim=-1, keepdim=True).values
    return (x - x_min) / (x_max - x_min + eps)


def sum_to_one_lastdim(x, eps=1e-6):
    """Renormalize so each row sums to one, a valid distribution."""
    return x / (x.sum(dim=-1, keepdim=True) + eps)


def entropy_reduced_self_attention(a_sa, lam=0.01, eps=1e-6):
    """Ent-Self module.

    Take one gradient step that lowers the entropy of each row of the
    self attention map, clamp the negatives to zero, then renormalize.
    Entropy E = - sum a * log(a), so dE/da = -(1 + log(a)).
    Update a_ent = ReLU(a - lam * dE/da).
    """
    a = minmax_norm_lastdim(a_sa).clamp(min=eps)
    grad = -(1.0 + torch.log(a))              # dE/da
    a_ent = F.relu(a - lam * grad)            # step then clamp
    a_ent = sum_to_one_lastdim(a_ent)         # restore distribution
    return a_ent


def category_enhanced_cross_attention(q, k, cat_mask, gamma=1.6):
    """Cat-Cross module.

    Weight the text keys of the requested categories by gamma before
    the softmax so the cross attention focuses on those classes.
    q is [HW, d], k is [T, d], cat_mask is [T] with 1 for requested
    categories and 0 otherwise.
    """
    d = q.shape[-1]
    weight = torch.where(cat_mask.bool(),
                         torch.full_like(cat_mask, gamma, dtype=q.dtype),
                         torch.ones_like(cat_mask, dtype=q.dtype))
    k_weighted = k * weight.unsqueeze(-1)     # elementwise on keys
    logits = (q @ k_weighted.t()) / (d ** 0.5)
    return F.softmax(logits, dim=-1)          # [HW, T]


def iterative_refinement(a_ca_col, a_ent, n_iters=10, eps=1e-6):
    """Refine one category column of the cross attention map.

    a_ca_col is [HW], a_ent is [HW, HW]. Repeats a_ca = a_ent @ a_ca
    with a renormalization after each step, as in the paper.
    """
    a = a_ca_col.clone()
    for _ in range(n_iters):
        a = a / (a.sum() + eps)               # normalize
        a = a_ent @ a                         # A_ca = A_ent x A_ca
    return a / (a.sum() + eps)


def binarize(mask_vec, thresh=None):
    """Turn a refined attention vector into a 0 or 1 mask."""
    m = minmax_norm_lastdim(mask_vec.unsqueeze(0)).squeeze(0)
    if thresh is None:
        thresh = m.mean()
    return (m > thresh).float()


class ISeg(torch.nn.Module):
    """End to end iSeg refinement over stand in attention maps."""

    def __init__(self, gamma=1.6, lam=0.01, n_iters=10):
        super().__init__()
        self.gamma = gamma
        self.lam = lam
        self.n_iters = n_iters

    def forward(self, q, k, a_sa, cat_index):
        # 1. cleaner cross attention with Cat-Cross
        cat_mask = torch.zeros(k.shape[0], device=k.device)
        cat_mask[cat_index] = 1.0
        a_ca = category_enhanced_cross_attention(q, k, cat_mask, self.gamma)
        a_ca_col = a_ca[:, cat_index]         # [HW] for this class

        # 2. clean the self attention with Ent-Self
        a_ent = entropy_reduced_self_attention(a_sa, self.lam)

        # 3. stable iterative refinement
        refined = iterative_refinement(a_ca_col, a_ent, self.n_iters)
        return binarize(refined), refined


def smoke_test():
    """Runs on dummy data, no Stable Diffusion needed."""
    torch.manual_seed(0)
    hw, d, t = 256, 64, 5      # 16 x 16 grid, 64 dim, 5 text tokens
    q = torch.randn(hw, d)     # visual queries
    k = torch.randn(t, d)      # text keys
    # build a rough self attention map from visual similarity
    a_sa = F.softmax((q @ q.t()) / (d ** 0.5), dim=-1)

    model = ISeg(gamma=1.6, lam=0.01, n_iters=10)
    mask, refined = model(q, k, a_sa, cat_index=2)

    assert mask.shape == (hw,)
    assert torch.isfinite(refined).all()
    print("mask pixels on:", int(mask.sum().item()), "of", hw)
    print("refined range:",
          round(refined.min().item(), 4),
          round(refined.max().item(), 4))
    print("smoke test passed")


if __name__ == "__main__":
    smoke_test()

Frequently asked questions

What does training free segmentation actually mean here?

It means iSeg never updates any weights on a segmentation dataset. It takes a Stable Diffusion model that was pre trained only to generate images, reads its attention maps, and turns them into masks with fixed arithmetic. No pixel labels are used to fit the method.

Why does refining the cross attention map many times make results worse?

A predicted self attention map carries faint responses from irrelevant far away regions. Multiplying by it once barely matters, but multiplying repeatedly compounds that global noise, so object boundaries spread or drift onto other objects. The problem is accumulation, not the loop itself.

What is the entropy reduced self attention module doing?

It treats each row of the self attention map as a probability distribution and takes one gradient step that lowers its entropy, then clamps negatives to zero and renormalizes. Sharp confident responses grow and weak diffuse ones vanish, so the refinement loop stays stable across many iterations.

How well does iSeg perform against other methods?

On unsupervised Cityscapes it reports an absolute gain of 3.8 percent mIoU over the best prior training free method. On weakly supervised PASCAL VOC it reaches 75.2 percent mIoU and even edges past several trained methods. It also improves open vocabulary and synthetic mask generation benchmarks.

Is it fast enough to be practical?

Inference runs at roughly 0.16 seconds per image with half precision and about 5 gigabytes of memory. It costs around 902.6 GFLOPs, much lighter than other diffusion based methods, though still heavier than CLIP based approaches that use far smaller backbones.

Where does iSeg break down?

It fails when Stable Diffusion itself produces noisy attention, for example on camouflage scenes from the CAMO dataset where objects blend into the background. Since the method sharpens existing maps rather than creating them, it cannot recover a mask the base model never located.

Read the full study and explore the authors’ code and project page.

Read the paper Project and code

You can also read the source article directly through its IEEE TPAMI listing, which links the official version and supplementary material.

Sun, L., Cao, J., Xie, J., Khan, F. S., and Pang, Y. iSeg. An Iterative Refinement Based Framework for Training Free Segmentation. IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 48, no. 8, pp. 9765 to 9779, August 2026. DOI 10.1109/TPAMI.2026.3681368.

This analysis is based on the published paper and an independent evaluation of its claims.

Leave a Comment

Your email address will not be published. Required fields are marked *