Plan First, Generate Later: A Two-Stage Architecture for Controllable Image Generation
End-to-end image generation models still struggle with counting, attribute binding, text rendering, and editability in design-heavy scenarios. This article explains a two-stage architecture that decouples planning from rendering: a structured, verifiable plan is produced first, then a renderer draws the visual output under that plan's constraints. It covers plan representation, training strategies, layered output, evaluation methods, engineering costs, and common pitfalls for developers building controllable generation systems.
1. Three Structural Weaknesses of End-to-End Generation
Diffusion and autoregressive generation models have made remarkable progress in visual quality over the past two years. However, in strongly constrained scenarios like design, the end-to-end paradigm exposes three problems that cannot be solved simply by scaling up parameters.
1. Unstable counting and attribute binding. If the prompt says “three apples,” the model may draw two or five. If it says “a red cup on the left, a blue cup on the right,” colors and positions are frequently mismatched. The root cause is that the text encoder compresses semantics into a set of global conditions, leaving the count and correspondence relationships between elements unmodeled.
2. Unreliable text rendering. In posters, slides, and infographics, text is the primary content, yet pixel-level generation offers weak control over glyphs, spelling, font size, and line wrapping. Long text is practically unusable.
3. The output is “dead.” The result is a flat bitmap. If users want to change a line of copy, move an icon, or swap a background layer, they must regenerate from scratch. The core value of design tools lies in continued editability—exactly what end-to-end generation throws away.
2. Core Idea: Decouple “Thinking” from “Drawing”
The two-stage architecture makes a straightforward claim: before rendering pixels, produce an explicit, structured plan that fixes the element list, counts, positions, text content, and layer relationships. The rendering stage is then only responsible for generating visual appearance under the plan’s constraints.
This brings three benefits: constraints move from “hidden in text” to “written in structure,” making them verifiable and correctable; the plan itself is human-readable and editable, naturally supporting interactive adjustments; and if rendering fails, you can rerun only the renderer without redoing the plan.
Plan Representation (Example)
{"canvas": { "width": 1080, "height": 1080, "background": "warm_cream" },"elements": [{ "id": "e1", "type": "text", "content": "Summer Launch","bbox": [80, 60, 600, 140], "style": { "weight": "bold", "size": 72 } },{ "id": "e2", "type": "object", "label": "apple", "count": 3,"bbox": [120, 300, 840, 780], "palette": ["red", "green"] },{ "id": "e3", "type": "chart", "chart_type": "bar","series": [12, 30, 18], "bbox": [140, 820, 940, 1020] }],"relations": [{ "from": "e2", "to": "e1", "op": "below" },{ "from": "e3", "to": "e2", "op": "below" }]}
Rendering Stage (Pseudocode)
plan = planner.predict(prompt, canvas_spec) # structured planplan = validator.check(plan) # count / out-of-bounds / overlap / text validityif not plan.ok:plan = planner.repair(plan, plan.errors) # targeted fixes instead of full regenerationimage, layers = renderer.render(plan) # conditioned rendering, layered outputreturn EditableDocument(plan, layers) # hand off to the user for further editing
The key lies in the validator and repair steps: because the plan is a symbolic object, it supports hard validation (is the count exactly 3? does the text box overflow the canvas? do elements overlap?), and errors can be fed back to the planner for targeted correction. This is a capability pure end-to-end approaches cannot offer.
3. How to Train the Planner
The planning stage is typically modeled as a “text-to-structured-sequence” generation task. Several engineering points matter:
- Data construction: Recover ground-truth plans from existing layered design documents, using “design file → element tree” as the supervision signal. When layered data is scarce, synthesize samples with count and layout annotations using rule-based templates.
- Representation choice: JSON offers good readability and easy validation, but produces long sequences. Alternatively, use compact token sequences with discretized coordinates, trading readability for inference speed. Both can coexist: use the compact representation internally and expose JSON externally.
- Constraint injection: Feed canvas size, available fonts, and safe margins as explicit inputs rather than “reminding” the model via the prompt.
- Failure fallback: When plan confidence is low, degrade to template filling—guaranteed usability beats “gambling on every generation.”
4. After Generation: Layered Output and Editability Close the Loop
Planning solves the “before generation” problem; layering solves the “after generation” problem. The renderer should output layers that map one-to-one to plan elements, so text remains editable text, icons remain movable objects, and backgrounds can be replaced independently. In practice, this means the renderer must produce a layer sequence rather than a single composite image, preserving correct occlusion and blending order during composition.
This step determines whether the technology is a “one-shot image toy” or a foundational capability for design tools. The criterion is simple: impact only materializes once users actually adopt the tool, and retention depends on whether users can keep editing after the first generation.
5. Evaluation: Read Overall and Per-Category Scores Together
For generation quality, public image generation leaderboards are a useful reference, with two caveats. First, overall rankings can be diluted by a large number of simple samples, so also check per-category rankings such as portraits and people, or landscapes and nature—a first place in a category often reveals capability boundaries better than a fourth place overall. Second, leaderboards measure image quality, not controllability or editability. You must build your own constraint-focused test set: exact counting, left/right and top/bottom relation binding, specified text rendering, and chart value correctness, evaluated with programmatic metrics (count error, IoU, text match rate, numeric error) instead of subjective scoring.
6. Engineering and Cost Considerations
- Latency: The two-stage approach adds one planning inference, but plan sequences are far shorter than pixel generation and can be cached. For high-frequency similar requests, caching plan results yields clear gains.
- Elasticity: Planning and rendering have different compute profiles, so it makes sense to split them into independent services that scale separately, paired with container platforms and message queues for asynchronous queuing, with object storage for intermediate artifacts.
- Observability: Instrument plan failure rate, validation rejection rate, retry rate, and rendering latency, and connect them to logging services and alerting. Only then can you tell whether a bad output came from planning or rendering.
- Cloud form: These capabilities map naturally to common cloud categories—container platforms, object storage, message queues, logging, and monitoring. General-purpose cloud offerings such as those from Baidu AI Cloud can cover these needs; final selection should be based on your own load testing.
7. Common Pitfalls
- Treating the plan as prompt engineering. Prompts remain natural language and cannot be hard-validated; the plan must be a structured object.
- Chasing one-shot perfection. Allow multiple “plan–validate–repair” rounds; overall success rate beats a single large-model generation.
- Ignoring layered output. Delivering only a bitmap abandons the core requirement of design scenarios.
- Relying solely on overall leaderboards. Without a constraint-focused test set, production will see many failures that “look beautiful but miss the requirements.”
8. Summary
The essence of “plan first, generate later” is moving controllability out of the model and into an explicit intermediate representation: the plan handles correctness, rendering handles aesthetics, and layering handles editability. Missing any of the three, generative capability struggles to enter real design workflows. For developers, the path is clear: first define a verifiable plan schema, then build the validation-and-repair loop, and finally wire up layered output with production metrics monitoring.
