This repository is the official implementation of MAG-Edit.
Qi Mao, [Lan Chen](), Yuchao Gu, [Zhen Fang](), Mike Zheng Shou
(a) Blended latent diffusion (b) DiffEdit (c) Prompt2Prompt
(d) Plug-and-play (e) P2P+Blend (f) PnP+Blend
TL; DR: MAG-Edit is the first method specifically designed to address localized image editing in complex scenarios without training.
Our method is tested using cuda12.0 on a single A100 or V100. The preparation work mainly includes downloading the pre-trained model and configuring the environment.
conda create -n mag python=3.8
conda activate mag
pip install -r requirements.txt
We use Stable Diffusion v1-4 as backbone, please download from Hugging Face and change the file path in line26 in code_tr/network.py
.
To run MAG-Edit, single GPU with at least 32 GB VRAM is required.
The code_tr/edit.sh
provide the edit sample.
CUDA_VISIBLE_DEVICES=0 python edit.py --source_prompt="there is a set of sofas on the red carpet in the living room"\
--target_prompt="there is a set of sofas on the yellow carpet in the living room" \
--target_word="yellow" \
--img_path="examples/1/1.jpg"\
--mask_path="examples/1/mask.png"\
--result_dir="result"\
--max_iteration=15\
--scale=2.5
The result is saved at code_tr/result
.
Simplified Prompt |
Source Image |
Ours | Blended LD | DiffEdit | P2P | PnP |
Green pillow |
||||||
Denim pants |
||||||
White bird |
||||||
Slices of steak |
Simplified Prompt |
Source Image |
Ours |
Instruct -Pix2Pix |
Magic -Brush |
SINE |
Yellow car |
|||||
Plaid Sofa |
|||||
Tropical fish |
|||||
Straw -berry |
Simplified Prompt |
Source Image |
Ours |
Style -Diffusion |
ProxNPI | DirectInversion |
Jeep | |||||
Floral sofa |
|||||
Yellow shirt |