This project implements the DiffEdit algorithm for image editing. It's based on the paper "DiffEdit: Diffusion-based semantic image editing with mask guidance" by Mostafa Dehghani, Yair Galron, Hila Chefer, Lior Wolf, and Oran Lang.
For more details about the algorithm, please refer to the original paper:
DiffEdit: Diffusion-based semantic image editing with mask guidance
To install the required libraries, run the following command:
pip install -r requirements.txtThis project uses Gradio to create an interactive web application. To run the app, use the following command:
python gradio_app.py- Upload an image you want to edit.
- Click on "Generate Mask" to create an initial mask for the image.
- Use the threshold slider to adjust the mask. The goal is to find the optimal threshold where:
- The mask covers the boundaries of the object you want to change.
- The mask doesn't include too many other objects in the image.
- Once you've found the optimal threshold, click on "Generate Edited Image" to produce the edited version of your image.
- You can adjust the "Seed" and "Strength" values to create different variations of the edited image.
Note: The quality of the edit depends on finding the right balance in the mask. Take your time to adjust the threshold for the best results. The best results would be achieved when mask is a little bigger than reference object but not contains much pixels from other objects or background of the image as mentioned in the paper.
Feel free to experiment with different settings to achieve your desired outcome!
Code is available without gradio in "diffedit.ipnb" file.
The objects in reference and query prompts should be similar since it edits only mask.
You can see both interface of gradio app and results of the model.
You can experiment with different pretrained models or schedulers. It can effect quality of results. Also, the binarized mask can be used as the input mask of a Inpainting pipeline(StableDiffusionInpaintPipeline) from diffusers library.
- The app uses a Gradio interface for easy interaction.
- Make sure to adjust the mask carefully for the best editing results.
- Experiment with different seed and strength values for various outcomes.
- It is designed to work with 512x512 input image size.
