InstructRL4Pix: Training Diffusion for Image Editing by Reinforcement Learning

Tiancheng Li, Jinxiu Liu, Huajun Chen, Qi LiuarXiv 2024 · DOI

Abstract

Instruction-based image editing often suffers from poor localization and reliance on low-quality synthetic datasets. We present InstructRL4Pix, a reinforcement learning (RL) framework that fine-tunes diffusion models by treating the denoising process as a Markov Decision Process. By utilizing cross-attention maps as a reward signal and incorporating a preservation loss, our method achieves superior image fidelity and precise, localized edits without requiring ground-truth target images during training.

Introduction

The field of instruction-based image editing (e.g., "make the cat wear a hat") has grown rapidly, primarily driven by models like InstructPix2Pix. However, these models are often bottlenecked by the quality of their training data—typically synthetic pairs generated by GPT-3 and Prompt-to-Prompt. If the synthetic "ground truth" is flawed, the model inherits these inaccuracies. Furthermore, existing models frequently struggle with localization, often altering the entire image's color grade or failing to isolate specific objects in complex scenes.

Methodology

InstructRL4Pix reformulates image editing as an RL problem to bypass the limitations of static datasets.

Diffusion as a Markov Decision Process

The multi-step denoising process is modeled as an MDP where the "state" consists of the current noisy image and the text instruction. The "action" corresponds to the denoising step, and the "policy" is the U-Net being optimized.

Reward Function Design

The core of our approach is a composite reward function that ensures both instruction following and image preservation:

  • Attention Map Reward: We calculate the cosine similarity between the model's internal cross-attention maps and a reference map. This encourages the model to focus its modifications on the specific pixels associated with the text instruction.
  • Preservation (Clip) Loss: To prevent drastic, irrelevant changes, we apply a Mean Absolute Error (MAE) regularization between the input and output images, ensuring the original identity is maintained.

Optimization

We employ Proximal Policy Optimization (PPO) for stable training. To maintain efficiency, we use LoRA (Low-Rank Adaptation) to fine-tune the U-Net parameters.

Experimental Setup

We utilize the MagicBrush dataset (10,000 triples of source image, instruction, and target). Notably, our training process ignores the target images. By relying solely on the source image and instruction to generate rewards, we avoid the "poisoning" effect of mediocre synthetic targets, effectively performing unsupervised goal optimization.

Results and Discussion

InstructRL4Pix significantly outperforms baselines in both quantitative and qualitative measures.

Quantitative Performance

Our model achieved a PSNR of 24.25 and an SSIM of 0.7978, markedly higher than InstructPix2Pix (19.90 and 0.6840, respectively). L1 and L2 error rates were nearly halved, demonstrating superior preservation of unedited regions.

Qualitative Precision and Localization

The model excels in complex scenarios requiring precise localization. For instance, when tasked with modifying a single subject in a group, InstructRL4Pix successfully isolates the target without affecting surrounding elements.

Figure 1: InstructRL4Pix demonstrates high precision in complex scenes, such as modifying a specific subject's features in a group setting while preserving the background and other individuals.
Figure 2: Example of a color-based edit where the model successfully changes the flower colors while maintaining the integrity of the clock tower and environmental lighting.

Conclusion and Future Work

InstructRL4Pix demonstrates that RL, guided by attention maps, provides a robust path toward high-fidelity image editing. While the model shows a slight trade-off in CLIP-T scores—occasionally being "too conservative" in its edits—it offers unparalleled localization. Future work will explore more sophisticated reward functions and scaling to larger diffusion backbones.

Summary updated

BibTeX
@misc{li2024instructrl,
  author = {Tiancheng Li and Jinxiu Liu and Huajun Chen and Qi Liu},
  title = {{InstructRL4Pix: Training Diffusion for Image Editing by Reinforcement Learning}},
  year = {2024},
  eprint = {2406.09973},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.09973},
}
Figure