Table of Contents
Fetching ...

CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation

Haodong Li, Chunmei Qing, Huanyu Zhang, Dongzhi Jiang, Yihang Zou, Hongbo Peng, Dingming Li, Yuhong Dai, ZePeng Lin, Juanxi Tian, Yi Zhou, Siqi Dai, Jingwei Wu

TL;DR

This work proposes CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation and demonstrates that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation.

Abstract

Recent advancements in Unified Multimodal Models (UMMs) have significantly advanced text-to-image (T2I) generation, particularly through the integration of Chain-of-Thought (CoT) reasoning. However, existing CoT-based T2I methods largely rely on abstract natural-language planning, which lacks the precision required for complex spatial layouts, structured visual elements, and dense textual content. In this work, we propose CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation. Given a text prompt, CoCo first generates executable code that specifies the structural layout of the scene, which is then executed in a sandboxed environment to render a deterministic draft image. The model subsequently refines this draft through fine-grained image editing to produce the final high-fidelity result. To support this training paradigm, we construct CoCo-10K, a curated dataset containing structured draft-final image pairs designed to teach both structured draft construction and corrective visual refinement. Empirical evaluations on StructT2IBench, OneIG-Bench, and LongText-Bench show that CoCo achieves improvements of +68.83%, +54.8%, and +41.23% over direct generation, while also outperforming other generation methods empowered by CoT. These results demonstrate that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation. The code is available at: https://github.com/micky-li-hd/CoCo

CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation

TL;DR

This work proposes CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation and demonstrates that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation.

Abstract

Recent advancements in Unified Multimodal Models (UMMs) have significantly advanced text-to-image (T2I) generation, particularly through the integration of Chain-of-Thought (CoT) reasoning. However, existing CoT-based T2I methods largely rely on abstract natural-language planning, which lacks the precision required for complex spatial layouts, structured visual elements, and dense textual content. In this work, we propose CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation. Given a text prompt, CoCo first generates executable code that specifies the structural layout of the scene, which is then executed in a sandboxed environment to render a deterministic draft image. The model subsequently refines this draft through fine-grained image editing to produce the final high-fidelity result. To support this training paradigm, we construct CoCo-10K, a curated dataset containing structured draft-final image pairs designed to teach both structured draft construction and corrective visual refinement. Empirical evaluations on StructT2IBench, OneIG-Bench, and LongText-Bench show that CoCo achieves improvements of +68.83%, +54.8%, and +41.23% over direct generation, while also outperforming other generation methods empowered by CoT. These results demonstrate that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation. The code is available at: https://github.com/micky-li-hd/CoCo
Paper Structure (26 sections, 1 equation, 8 figures, 3 tables)

This paper contains 26 sections, 1 equation, 8 figures, 3 tables.

Figures (8)

  • Figure 1: Comparison of reasoning paradigms for text-to-image generation. (a) Direct generation without explicit reasoning. (b) Text-only Chain-of-Thought (CoT) reasoning prior to image synthesis. (c) Textual CoT with an intermediate visual draft. (d) Multi-turn reasoning with iterative textual and visual drafts. (e) CoCo: our approach generates executable code as a structured visual draft that explicitly specifies object layouts and attributes, which is then rendered and refined to produce the final image.
  • Figure 2: Framework of CoCo.CoCo operates in three stages: (1) generating executable code from the input prompt to explicitly specify structural layouts, (2) executing the code in a sandboxed environment to render a deterministic draft image, and (3) performing draft-guided refinement to produce the final high-quality output.
  • Figure 3: Visual comparison between code-generated drafts and final results. Left: draft image synthesized from code generated by CoCo. Right: final image refined by CoCo based on the draft image and input prompt.
  • Figure 3: Ablation on training mixture ratio.$r_c$ is the proportion of Text--Code supervision.
  • Figure 4: Construction Pipeline and Examples of CoCo-10K. We design specialized data pipelines targeting three atomic correction capabilities: general editing, scientific diagrams, and complex text. Using Gemini-3-Pro gemini and Nano Banana bananapro, we generate code and final images from the collected prompts. The resulting data are organized into two training categories: Text-Code Pairs and Text-Draft Image–Final Image Pairs.
  • ...and 3 more figures