Rectified flows for image inversion and editing. Our approach efficiently inverts reference style images in (a) and (b) without requiring text descriptions of the images and applies desired edits based on new prompts (e.g. “a girl” or “a dwarf”). For a reference content image (e.g. a cat in (c) or a face in (d)), it performs semantic image editing e.g. “ sleeping cat”) and stylization (e.g. “a photo of a cat in origmai style”) based on prompts, without leaking unwanted content from the reference image (input images have orange borders).
- [2024.12.23] RF-Inversion gradio demo, thanks Linoy!
- [2024.12.17] RF-Inversion now supported in diffusers, thanks Linoy!
- [2024.10.15] Code reimplemented by open-source ComfyUI community, thanks logtd!
- [2024.10.14] Paper is published on arXiv!
We support a Gradio demo for better user experience: Web demonstration🔥
Try RF-Inversion using diffusers implementation! Load hyper Flux LoRA to enable 8 step inversion and editing🔥
import torch
from diffusers import FluxPipeline
import requests
import PIL
from io import BytesIO
import os
# torch.manual_seed(999)
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
torch_dtype=torch.bfloat16,
custom_pipeline="pipeline_flux_rf_inversion")
pipe.to("cuda")
def download_image(url):
response = requests.get(url)
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
img_url = "https://www.aiml.informatik.tu-darmstadt.de/people/mbrack/tennis.jpg"
image = download_image(img_url)
inverted_latents, image_latents, latent_image_ids = pipe.invert(
image=image,
num_inversion_steps=28,
gamma=0.5
)
edited_image = pipe(
prompt="a tomato",
inverted_latents=inverted_latents,
image_latents=image_latents,
latent_image_ids=latent_image_ids,
start_timestep=0,
stop_timestep=7/28,
num_inference_steps=28,
eta=0.9,
).images[0]
save_dir = "./results/"
if not os.path.exists(save_dir):
os.makedirs(save_dir)
image_save_path = os.path.join(save_dir, f"rf_inversion.png")
edited_image.save(image_save_path)
print('Results saved here: ', image_save_path)
Try ComfyUI for better experience: ComfyUI Node🔥. Follow the guidelines below to setup locally.
Install ComfyUI to run flux
-
cd ComfyUI
-
python main.py
Install ComfyUI-Manager.
-
cd ComfyUI/custom_nodes
-
-
cd ..
-
python main.py
Install RF-Inversion ComfyUI Node
- Click on "Manager"
- Install via Git URL: https://github.com/logtd/ComfyUI-Fluxtapoz
- If you see error, change security level in ComfyUI/custom_nodes/ComfyUI-Manager/config.ini from "normal" to "weak"
-
cd ComfyUI
-
python main.py
- Copy RF-Inversion workflow and paste on the ComfyUI window.
- Install missing custom nodes in Manager
- Click on "Queue Prompt" to see the result
- Tune hyper-parameters (such as eta, start_step, stop_step) to get the desired outcome
@article{rout2024rfinversion,
title={Semantic Image Inversion and Editing using Rectified Stochastic Differential Equations},
author={Litu Rout and Yujia Chen and Nataniel Ruiz and Constantine Caramanis and Sanjay Shakkottai and Wen-Sheng Chu},
journal={arXiv preprint arXiv:2410.10792},
year={2024}
}
Copyright © 2024, Google LLC. All rights reserved.