Introduction
Diffusion-based models have significantly advanced the field of image editing, yet they frequently struggle with generalization. When faced with editing tasks that fall outside their specific training data, these models often fail to execute instructions accurately. While "visual in-context learning"—providing the model with an example pair (Image A → Image B) alongside the query image—offers a potential solution, existing architectures struggle to process these multi-image prompts globally. This often results in poor image quality and the distortion of fine details, such as human faces. Furthermore, the inherent brittleness of natural language instructions means that minor variations in phrasing can lead to unpredictable outputs.
To address these challenges, we present InstructGIE, a novel framework designed to enhance the generalizability of image editing by combining visual in-context learning with unified language instructions. By integrating a VMamba-based vision encoder, an editing-shift matching strategy, and selective area matching, InstructGIE preserves fine details while accurately following complex, unseen editing commands.
Methodology
InstructGIE introduces four primary components to improve how diffusion models interpret and execute image edits:
1. Reformed Conditioned Latent Diffusion Model (RCLDM)
Traditional Vision Transformers (ViTs) and CNNs often lack the global Effective Receptive Field (ERF) necessary to process a 2x2 grid of images (example input, example output, query input, and target) effectively. InstructGIE utilizes a Zero-VMamba vision encoder. Based on State Space Models, VMamba provides a superior global receptive field, allowing the model to better understand the spatial and semantic relationships between the example pair and the query image.
2. Editing-Shift Matching (ESM)
Rather than simply memorizing pixel-level changes, InstructGIE employs an Editing-Shift Matching strategy. The model calculates an implicit "shift" vector in CLIP space between the input and output images. By optimizing for this shift during training, the model learns the underlying transformation logic, which significantly improves its ability to generalize to new contexts.
3. Language Instruction Unification (LIU)
To mitigate the variance caused by inconsistent text prompts, the framework incorporates a frozen, lightweight Large Language Model (Open Llama 3b). This LLM acts as a pre-processor, rewriting and standardizing user instructions into a unified format before they are passed to the diffusion model. This standardization ensures that the model's knowledge distribution remains stable, regardless of how a user phrases a request.
4. Selective Area Matching (SAM)
Preserving the integrity of sensitive features, such as human faces or animals, is a common pain point in image editing. InstructGIE automates this preservation using a frozen Mask2Former to segment these areas during training. A targeted loss function is applied to these specific regions, ensuring they remain undistorted. This approach removes the need for users to provide complex negative prompts to protect image quality.
Dataset Generation
Because visual in-context learning requires multiple image pairs demonstrating the same edit, existing datasets were insufficient for training. The authors developed a new synthetic dataset consisting of approximately 12,000 images covering 2,000 distinct editing instructions. This dataset was created using a fine-tuned GPT-3 for instruction generation and the Prompt-to-Prompt algorithm for image generation, ensuring at least two image pairs per instruction to facilitate in-context learning.
Experimental Results
InstructGIE was evaluated against state-of-the-art baselines, including SDEdit, InstructPix2Pix, and PromptDiffusion. The results demonstrate significant improvements across both quantitative and qualitative metrics:
- Image Quality: InstructGIE achieved a Fréchet Inception Distance (FID) score of 7.57, substantially lower than PromptDiffusion (13.75) and InstructPix2Pix (17.87), indicating higher visual fidelity.
- Instruction Adherence: In terms of CLIP Directional Similarity (CLIP DirSim), InstructGIE scored 0.27, outperforming PromptDiffusion (0.21) and InstructPix2Pix (0.17).
- Qualitative Performance: InstructGIE successfully handles complex, out-of-domain edits—such as structural changes or object additions—that typically cause baseline models to fail. Ablation studies further confirmed that the SAM module is critical for maintaining the realism of human features.
Limitations and Future Work
Despite its performance, InstructGIE has certain constraints. The reliance on multiple auxiliary models (Open Llama 3b, Mask2Former, CLIP, and VMamba) increases the computational footprint and memory requirements compared to simpler end-to-end architectures. Additionally, as the training data is entirely synthetic, the model's capabilities are inherently influenced by the biases of the teacher models used in data generation. Future research will focus on incorporating real-world, human-annotated editing pairs to further bridge the gap between synthetic benchmarks and diverse, real-world applications.
Summary updated