Image Translation as Diffusion Visual Programmers

Cheng Han, James Chenhao Liang, Qifan Wang, Majid Rabbani, Sohail Dianat, Raghuveer Rao, Ying Nian Wu, Dongfang Liu

TL;DR

The Diffusion Visual Programmer (DVP) is a novel neuro-symbolic framework that combines the reasoning power of Large Language Models (like GPT-4) with the generative capabilities of diffusion models to perform complex image editing. By breaking down user instructions into a sequence of interpretable visual programs and introducing a parameter-free "instance normalization guidance" for diffusion, DVP achieves highly accurate, controllable, and explainable image translation.

The Problem: Black-Box Image Editing

Current state-of-the-art image translation tools (like Prompt-to-Prompt or InstructPix2Pix) treat image editing as a black-box "connectionist" problem: you provide an image and a prompt, and the model attempts to output the final result in one go. This approach has three major flaws:

  1. Condition-rigid learning: They rely heavily on "classifier-free guidance," requiring users to manually tweak a highly sensitive guidance scale parameter for every single image to get good results.
  2. Context-free incompetence: They struggle with precise, localized edits (e.g., "change the left dog to a sheep") while maintaining the integrity of the background and other objects.
  3. System opacity: Because they are black boxes, users have no control over the intermediate steps. If the model misunderstands the prompt, the user cannot easily correct its reasoning.

To address this, the authors propose shifting from a "what" paradigm to a "where-then-what" paradigm, identifying the exact region to edit before applying generative changes.

The "where-then-what" paradigm breaks down complex instructions into localized, step-by-step edits.

Methods: The DVP Framework

DVP tackles these challenges using a two-pronged approach that marries symbolic planning with flexible generative models.

The DVP framework architecture, showcasing the GPT-driven planner and modular visual programs.

1. Condition-Flexible Diffusion Model (Instance Normalization Guidance)

Instead of using standard classifier-free guidance—which linearly combines conditional and unconditional noise predictions using a finicky, hand-tuned weight parameter—the authors use instance normalization. By calculating the mean and standard deviation of the unconditional embedding and shifting it to match the conditional embedding, the model automatically aligns with the text prompt. This entirely eliminates the need for manual parameter tuning.

2. In-Context Visual Programming

DVP uses GPT-4 as an AI agent to act as a "Planner." When given an instruction (e.g., "Change the left woman to an astronaut"), GPT-4 writes a Python-like program that calls off-the-shelf computer vision models as functions. The pipeline typically involves:

  • Prompter: Generates detailed descriptions of the input image (using BLIP).
  • RoI Segmenter: Finds and masks the exact object to be edited (using Mask2Former or Segment Anything).
  • Inpainter: Fills in the background behind the object (using Repaint).
  • Position Manipulator: Translates the object using the diffusion model and places it back into the scene, handling spatial logic (enlarge, move left, etc.).

Datasets and Evaluation

  • Evaluation Benchmark: The authors curated a benchmark of 100 diverse text-image pairs using images from the web, ImageNet-R, ImageNet, and MS COCO to test various stylistic and object translations.
  • General-Context Dataset: Introduced in the appendix, this dataset contains 500 image-text pairs across 20 classes. It is specifically designed to test a model's ability to understand complex spatial relationships (e.g., "Two foxes are standing to the right of a wolf...").

Key Insights and Results

  • Math can replace manual tuning: Treating the conditional and unconditional noise predictions in diffusion models as distributions that can be normalized is a brilliant way to bypass the brittle guidance scale used in almost all modern diffusion models.
  • Neuro-symbolic systems fix the black box: By decoupling high-dimensional image features into low-dimensional "symbols" (like a segmentation mask or a text string), the system becomes transparent. If DVP segments the wrong dog, the user can see that intermediate step and correct it before the diffusion model wastes compute generating the final image.
  • Modularity is a superpower: Because DVP is a sequence of programs, upgrading it is trivial. Swapping out the default segmenter (Mask2Former) for a better one (Segment Anything) immediately improved the system's ability to handle occluded objects without requiring any retraining.

Performance: DVP outperformed six state-of-the-art baselines (including Prompt2Prompt, VISPROG, and InstructPix2Pix). It achieved the highest CLIP-Score (0.839) and DINO-Score (0.697), indicating better alignment with the text prompt and better preservation of image structure. In a 50-person user study, DVP scored highest in Quality (3.95/5) and Fidelity (4.28/5). Users also rated DVP as vastly more controllable (74.9%) and user-friendly (60.3%) compared to the closest visual programming baseline, VISPROG. Qualitatively, DVP successfully executed complex, multi-step instructions that completely broke other models.

Limitations and Future Work

  • Occlusions: The segmentation module only captures the visible parts of an object. If an object is partially hidden, the diffusion model will only generate the visible slice, leading to unnatural results. Integrating amodal segmentation (which predicts hidden parts) is a key future direction.
  • Poor Lighting: Like many computer vision models, DVP struggles in poor photometric conditions, sometimes mistaking shadows for objects.
  • Broader Applications: The authors suggest their instance normalization technique could be expanded beyond image editing to improve general text-to-image generation pipelines, allowing for parameter-free fine-tuning of existing generated images.

Summary updated

BibTeX
@inproceedings{han2024image,
  author = {Cheng Han and James Chenhao Liang and Qifan Wang and MAJID RABBANI and Sohail Dianat and Raghuveer Rao and Ying Nian Wu and Dongfang Liu},
  title = {{Image Translation as Diffusion Visual Programmers}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=yozwqhIHXj},
}
Figure