CountLoop: Training-Free High-Instance Image Generation via Iterative Agent Guidance

Anindya Mondal, Sauradip Nag, Ayan Banerjee, Josep Llados, Xiatian Zhu, Anjan Dutta

TL;DR

CountLoop is a training-free, closed-loop framework that enables text-to-image diffusion models to accurately synthesize scenes with high object counts (up to 200 instances). By combining a Vision-Language Model (VLM) planner-critic loop with a sequential, mask-based attention mechanism, it eliminates common failure modes like attribute leakage and rigid grid layouts without requiring any model retraining.

What Problem Does This Paper Address?

While modern diffusion models like SDXL and FLUX generate stunning photorealistic images, they notoriously struggle with basic arithmetic. Ask for "3 cats," and you might get two or four; ask for "140 oranges and 31 birds," and the model completely saturates, typically capping out at around 10 instances per category or collapsing into an incoherent blob.

Prior attempts to fix this fall into two camps: gradient-guided methods (which inject counting signals during denoising but introduce visual artifacts) and layout-to-image pipelines (which use bounding boxes but often result in unnatural, rigid grid-like arrangements). Furthermore, dense scenes suffer heavily from attribute leakage—a phenomenon where cross-attention layers cause features to bleed between objects, turning a crowd of eggs into stone-like textures, for example.

Common issues in high-instance image generation include unnatural grid layouts and attribute leakage.

Methods

CountLoop introduces a training-free, agent-guided loop that treats image generation as an iterative design process. The pipeline operates in three distinct stages:

  1. VLM-Guided Layout Generation: A Design VLM parses the text prompt into a structured planning graph that encodes object attributes and spatial relationships (e.g., minimum distances to prevent overlap). This graph is converted into a textual template to generate realistic, non-grid layouts.
  2. Layout-Aligned Image Generation: To prevent attribute leakage, CountLoop avoids synthesizing all objects simultaneously. Instead, it uses Cumulative Latent Composition. It processes cross-attention maps at the individual instance level, refines bounding boxes into shape-aware binary masks using $k$-means clustering, and sequentially injects objects into the latent space from background to foreground. Texture consistency across these sequential steps is maintained using an IP-Adapter.
  3. Iterative Layout Refinement: A Critic VLM evaluates the generated image. Because VLMs are notoriously poor at counting dense scenes directly, the critic relies on an off-the-shelf object detector (like GroundingDINO) for count verification and an aesthetic scorer. The critic provides structured textual feedback, which an LLM-based text-editing agent uses to update the planning graph (acting as a "textual gradient") for the next iteration.
The CountLoop pipeline: iterative feedback between a Design VLM, a mask-guided image generator, and a Critic VLM.

Datasets

The authors evaluated CountLoop on two standard benchmarks and two challenging new high-instance datasets introduced in this paper:

  • COCO-Count & T2I-CompBench Count: Standard benchmarks for low-to-moderate instance counting.
  • CountLoop-S (New): 200 single-category prompts featuring dense distributions of 30 to 200 instances (e.g., balloons, watches, oranges).
  • CountLoop-M (New): 200 multi-category prompts featuring dense distributions of 30 to 200 instances.

Key Insights and Ideas

  • The Power of Sequential Generation: Generating objects one by one (far-to-near depth ordering) within tightly bound, shape-aware attention masks completely mitigates attribute bleeding.
  • VLMs Need External Eyes to Count: A key architectural choice was separating the Critic VLM's reasoning from the actual counting task. Delegating the count verification to a specialized object detector prevents the VLM from hallucinating correct counts in dense clusters.
  • Text as a Gradient: Instead of backpropagating numerical gradients through a frozen network, CountLoop uses natural language feedback to modify a discrete spatial planning graph, mirroring how a human designer refines a canvas layout.

Key Results

CountLoop significantly outperforms both standard text-to-image models and specialized layout-conditioned baselines, particularly as object density scales up.

  • Quantitatively: On the high-instance CountLoop-S benchmark, CountLoop achieved a Mean Absolute Error (MAE) of 7.59, cutting the error of the strongest agentic competitor (Qwen-Image at 17.30) and the best layout baseline (3DIS at 14.55) roughly in half.
  • Exact Matches: It achieved a 20% exact-count match on CountLoop-S and 33% on CountLoop-M (rising to 29% and 42% when paired with a stronger critic detector), whereas baseline models hovered near 0% exact matches at high cardinalities.
  • Qualitatively: As shown in comparisons, CountLoop successfully generates high-density scenes with natural spacing, avoiding the spatial collapse and artificial clustering seen in competing methods.
Qualitative comparison showing CountLoop maintaining accurate counts and natural spacing compared to other baselines.

Limitations and Future Work

Despite its strengths, CountLoop inherits the fundamental limitations of its underlying frozen components. Dense occlusions—particularly in complex human crowds—can degrade attention mask quality and spatial consistency. Because the framework lacks explicit 3D geometric priors, it can struggle with complex perspectives and varied object poses. Additionally, the strong layout guidance can sometimes bias the model toward canonical object poses, slightly reducing intra-class visual diversity.

Summary updated

BibTeX
@article{mondal2026countloop,
  author = {Anindya Mondal and Sauradip Nag and Ayan Banerjee and Josep Llados and Xiatian Zhu and Anjan Dutta},
  title = {{CountLoop: Training-Free High-Instance Image Generation via Iterative Agent Guidance}},
  journal = {Accepted by TMLR},
  year = {2026},
  url = {https://openreview.net/forum?id=2JxXGhpCP4},
}
Figure