Update (May 19, 2025): We have added a link to the full dataset in the Dataset section below.
This is the official repo of the paper "DiffusionGuard: A Robust Defense Against Malicious Diffusion-based Image Editing" (ICLR 2025).

conda create -n diffusionguard python=3.10
conda activate diffusionguard
pip install -r requirements.txt # We recommend using torch version 2.1.1 and CUDA version 12.2 for best compatibility.
You can protect images from diffusion-based image inpainting by generating adversarial perturbations using main.py. All images must be placed in the assets folder.
To run DiffusionGuard on image keanu.png for mask image keanu_mask.png in assets folder, please run the following code:
python main.py --config-name diffusionguard orig_image_name='keanu.png' mask_image_names='["keanu_mask.png"]'
In this example, orig_image_name refers to the original image you wish to protect, and mask_image_names contains the list of masks applied for protection.
If multiple mask images are given, the code will automatically merge them by taking the union of all masks.
method: Protection method. Defaults todiffusionguard.orig_image_name: Filename of the image to be protected. Should be placed inassetsfolder.mask_image_names: List of filenames for the masks to be used. Should be placed inassetsfolder.model: Specifies the models used.inpainting: Inpainting model. Defaults torunwayml/stable-diffusion-inpainting.
training:size: Image resolution of the image to be protected. Image should be square. Defaults to512.iters: Number of PGD optimization iterations.grad_reps: Number of reps to accumulate gradients.batch_size: Batch size for PGD iteration.eps: Linf threshold value for the adversarial noise. Defaults to 16/255.step_size: PGD step size. Defaults to 1/255.num_inference_steps: Number of inference steps for the inpainting pipeline.mask: Mask-related settings.generation_method: Mask generation method. Choose fromsingle,global, andcontour_shrink.contour_strength: Shrink strength forcontour_shrinkmethod. Defaults to1.0.contour_iters: Shrink iterations forcontour_shrinkmethod. Defaults to15.contour_smoothness: Contour smoothing parameter forcontour_shrinkmethod. Defaults to0.1.
Our dataset is available at this Google Drive link.