需要自备 HuggingFace 个人访问令牌并通过 --hf_token 传入;environment.yml 中的 pytorch-cuda 版本可能需要按自己的环境调整;显存不足会报 CUDA out of memory,需加 --cpu_offload 但会明显变慢。
stable-flow
snap-research长期未更新Stable Flow 是 CVPR 2025 论文的官方实现,利用扩散模型中的关键层实现免训练的图像编辑,无需微调即可对生成图做可控修改。
Official implementation for "Stable Flow: Vital Layers for Training-Free Image Editing" [CVPR 2025]
conda env create -f environment.yml
conda activate stable-flow论文实验使用单张 80GB 显存的 NVIDIA V100;显存不足时可加 --cpu_offload 用 CPU offloading 降低显存占用,但推理时间显著增加。README 未说明其他 GPU 型号或纯 CPU 运行方式。
基于 DiT 的免训练图像编辑官方实现,用关键层注意力注入做一致编辑
Stable Flow 是 CVPR 2025 论文的官方实现,利用扩散模型中的关键层实现免训练的图像编辑,无需微调即可对生成图做可控修改。
核心能力
- 自动识别 DiT 中决定成像的关键层(vital layers)
- 向关键层选择性注入注意力特征实现一致编辑
- 同一机制支持非刚性编辑、物体增删与全局场景编辑
- 为 flow 模型提供改进的图像反演以编辑真实图片
- 支持增量编辑、风格一致与文字编辑等应用
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Stable Flow: Vital Layers for Training-Free Image Editing [CVPR 2025]
Stable Flow: Vital Layers for Training-Free Image Editing
Omri Avrahami, Or Patashnik, Ohad Fried, Egor Nemchinov, Kfir Aberman, Dani Lischinski, Daniel Cohen-Or
Abstract: Diffusion models have revolutionized the field of content synthesis and editing. Recent models have replaced the traditional UNet architecture with the Diffusion Transformer (DiT), and employed flow-matching for improved training and sampling. However, they exhibit limited generation diversity. In this work, we leverage this limitation to perform consistent image edits via selective injection of attention features. The main challenge is that, unlike the UNet-based models, DiT lacks a coarse-to-fine synthesis structure, making it unclear in which layers to perform the injection. Therefore, we propose an automatic method to identify "vital layers" within DiT, crucial for image formation, and demonstrate how these layers facilitate a range of controlled stable edits, from non-rigid modifications to object addition, using the same mechanism. Next, to enable real-image editing, we introduce an improved image inversion method for flow models. Finally, we evaluate our approach through qualitative and quantitative comparisons, along with a user study, and demonstrate its effectiveness across multiple applications.
Applications
Incremental Editing
Consistent Style
Text Editing
Installation
Install the conda virtual environment:
conda env create -f environment.yml
conda activate stable-flow
You may need to update to your own pytorch-cuda version.
Usage
Generated Images Editing
You need to provide a list of prompts, where the first prompt describes the original scene, and the rest of the prompts describe the edited scene. For example:
[
"A photo of a dog in standing the street",
"A photo of a dog sitting in the street",
"A photo of a dog in standing and wearing a straw hat the street",
"A photo of a mink",
]
Then, you can generate a batch of the image and its edited versions using:
python run_stable_flow.py \
--hf_token YOUR_PERSONAL_HUGGINGFACE_TOKEN \
--prompts "A photo of a dog in standing the street" \
"A photo of a dog sitting in the street" \
"A photo of a dog in standing and wearing a straw hat the street" \
"A photo of a mink"
where YOUR_PERSONAL_HUGGINGFACE_TOKEN is your personal HuggingFace user access token.
Then, the results will be saved to outputs/result.jpg, or any other path you specify under --output_path.
Low GPU VRAM Usage
All the experiments in our paper were conducted using a single NVIDIA V100 GPU of 80GB VRAM. If you are using a GPU with smaller VRAM and getting CUDA out of memory errors, you can use CPU offloading by adding the --cpu_offload flag. It will reduce memory consumption but it will increase the inference time significantly.
Real Images Editing (Optional)
If you want to edit a real image, you still need to provide a list of prompts, where the first prompt describes the input image and the rest of the prompts describe the edited scene. For example:
python run_stable_flow.py \
--hf_token YOUR_PERSONAL_HUGGINGFACE_TOKEN \
--input_img_path inputs/bottle.jpg \
--prompts "A photo of a bottle" \
"A photo of a bottle next to an apple"
where YOUR_PERSONAL_HUGGINGFACE_TOKEN is your personal HuggingFace user access token, and --input_img_path is the path to the input image.
Then, the results will be saved to outputs/result.jpg, or any other path you specify under --output_path.
Citation
If you find this useful for your research, please cite the following:
@InProceedings{Avrahami_2025_CVPR,
author = {Avrahami, Omri and Patashnik, Or and Fried, Ohad and Nemchinov, Egor and Aberman, Kfir and Lischinski, Dani and Cohen-Or, Daniel},
title = {Stable Flow: Vital Layers for Training-Free Image Editing},
booktitle = {Proceedings of the Computer Vision and Pattern Recognition Conference (CVPR)},
month = {June},
year = {2025},
pages = {7877-7888}
}