Skip to content

guillermogotre/sage

Repository files navigation

title emoji colorFrom colorTo sdk sdk_version app_file pinned license
Sage
😻
blue
red
gradio
4.7.1
app.py
false
mit

SAGE: Don't Forget your Inverse DDIM for Image Editing

Source code for the paper "Don't Forget your Inverse DDIM for Image Editing".

Guillermo Gomez-Trenado1*, Pablo Mesejo1, Óscar Cordón1, Stéphane Lathuilière2
1DaSCI research institute, DECSAI, University of Granada, Granada, Spain
2LTCI, Telécom-Paris, Intitute Polytechnique de Paris, Palaiseau, France
*Corresponding Author

Open In Colab

Teser

The field of text-to-image generation has undergone significant advancements with the introduction of diffusion models. However, the challenge of editing real images has persisted, with most methods being too computationally intensive or resulting in poor reconstruction. In this paper, we introduce SAGE, a novel technique utilizing pre-trained diffusion models for image editing. The superior performance of SAGE compared to existing approaches is evidenced through both quantitative and qualitative evaluations, complemented by a detailed user study.

Table of Contents

Method Overview

SAGE, standing for Self-Attention Guidance for image Editing, builds upon the DDIM algorithm. It incorporates a novel guidance mechanism leveraging the self-attention layers of the diffusion U-Net. This mechanism computes a reconstruction objective by utilizing attention maps generated during the inverse DDIM process. This allows for the efficient reconstruction of unedited regions, eliminating the need for precise reconstruction of the entire input image, thereby addressing the key challenges in image editing.

Method overview

Getting started

There are several ways of use SAGE.

  • HuggingFace Demo: There is an available HF demo. The user should fork it and run it on a GPU environment. We strongly advise the user against running it on CPU.
  • Google Colab: Right after the links section, there is a Google Colab button that allows you to run SAGE on GPU.
  • You own PC: Keep reading for instruction on how to run this code in your own PC.

Environment requirements

The required packages are described both in requirements.txt and python_versions.txt. There is an additional file conda_environment.yml as a testimony of every package version used for the experimentation, many packages are not used in this code and the user should not try to install the .yml file with conda.

Follow PyTorch installation instructions and Diffusers' to install both packages. The rest can be intalled with pip.

There are two system environment variables that can be set on the running computer:

  • GRADIO_PORT=PORT To select the specific port PORT the Gradio should run on.
  • SAGE_MEMORY_INTENSIVE=1 To enable the generation of Cross-Attention maps history.

Running Scripts

The main files for running SAGE are in the root path of this repository:

  • app.py: Runs the Gradio app on your system.
  • app_colab.ipynb: Used only as the source for the Google Colab environment. Can be ignored.
  • custom_inversion_functional.py: The function run(...) runs SAGE method attending to the function's parameters.
  • run_piebench.py: Contains the functions to evaluate SAGE on PieBench for a given configuration.
  • run_piebench_ablation.sh: Repeat every experiment used in the paper's ablation.

Examples

Examples 1 Examples 2 Examples 3

Citation

@ARTICLE{11079418,
  author={Gomez-Trenado, Guillermo and Mesejo, Pablo and Cordón, Oscar and Lathuilière, Stéphane},
  journal={IEEE Computational Intelligence Magazine}, 
  title={Don’t Forget Your Inverse DDIM for Image Editing}, 
  year={2025},
  volume={20},
  number={3},
  pages={10-18},
  keywords={Adaptation models;Statistical analysis;Computational modeling;Noise reduction;Text to image;Streaming media;Diffusion models;Robustness;Image reconstruction;Standards},
  doi={10.1109/MCI.2025.3563859}}

About

Official code for SAGE: Don't Forget your Inverse DDIM for Image Editing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published