Code as Pixels pauses an image model mid-render so a coding agent can fix the picture with Python
A training-free method where a vision-language model watches previews of a half-finished image, writes a script to repaint the mistakes, and lets the frozen image model finish.
Image models are bad at counting, layout and text, and the usual fix is to fine-tune them. Code as Pixels, from Hongyang Du, Yunfei Xie and six co-authors, leaves the image model frozen. A vision-language model looks at the picture while it is still being made, writes ordinary Python to paint over what is wrong, and the image model then finishes the job from the corrected version.
How it works
Flow-matching image models build a picture over a few dozen steps. Code as Pixels runs one normal pass and caches the intermediate states. From each cached state it can estimate what the final image would look like, so it lays out a filmstrip of previews taken at steps 15, 25, 34 and 42, plus the final frame.
A vision-language model reads the filmstrip. If it spots a defect, such as the wrong number of objects, a bad layout, a wrong color or a wrong object, it writes a sandboxed edit_image(img) function using normal image libraries. The edited pixels are pushed back into the model’s latent space under a mask, and generation resumes from that earlier step. The README allows up to two rounds of this.
Editing an existing image works along similar lines. The agent picks a region mask, optionally draws a rough draft in code, and chooses one of three ways to render it. One of them, code_only, skips the image model entirely and returns the script’s exact pixels, which the README recommends for typography and charts.
No weights are trained. The method wraps three existing backbones: FLUX.1-dev, Qwen-Image and LongCat-Image.
The numbers
These are the authors’ own results. On eight text-to-image benchmarks, the README reports averages of:
| Backbone | Base | With Code as Pixels |
|---|---|---|
| FLUX.1-dev | 48.67 | 70.96 |
| Qwen-Image | 61.49 | 74.26 |
| LongCat-Image | 59.18 | 73.90 |
The closed GPT-Image-2 is listed at 81.53 for reference, so the gap narrows without closing. The gains are uneven. On DPG, two of the three backbones score slightly lower with the method than without. On BizGenEval the base models score between 0.2 and 2.6, and the wrapped ones reach 34.9 to 43.7, still about half of GPT-Image-2’s 83.2.
For editing, the README includes a baseline where a code-writing model edits with no image model at all. The full method beats it on every benchmark listed, but dedicated fine-tuned editors still score higher on two of the four.
The README gives no figures for how long a run takes or what the vision-language model calls cost. There is a “Paper Coming Soon” badge and no paper yet.
Try it yourself
The code is MIT licensed. The backbones keep their own licenses, and FLUX.1-dev is gated. The README lists about 32 GB of GPU memory for FLUX.1-dev and LongCat-Image and 48 GB or more for Qwen-Image. The agent defaults to OpenAI’s API, with a budget flag, or can run through the Codex CLI. A studio --demo mode is described as needing no GPU.
We have not run it. This is based on the README. The project page would not load from our build machine.