This repository contains the implementation for the ICML paper "AdvI2I: Adversarial Image Attack on Image-to-Image Diffusion Models".
This work presents AdvI2I, a novel adversarial attack method targeting image-to-image diffusion models. Our approach generates adversarial perturbations that can manipulate the output of diffusion models while maintaining visual quality and semantic coherence.
conda env create -f environment.yml
conda activate advi2i
pip install -r requirements.txt
The nudenet could be installed by:
pip install nudenet
Download and extract the dataset.tar.gz file, which contains:
Place the extracted data in the following structure:
your_path/adv_diffusion/
├── dataset/
│ ├── naked_imgs/ # Training and testing images
│ ├── prompts/ # Prompts for constructing NSFW concept and dataset
│ └── img_clothes_masks/ # Mask images for inpainting
└── hf_results/ # Output directory
work_path in the scripts to point to your data directory.First, generate the NSFW concept for your target concept:
python vec_gen.py --concept nudity --version 1-5-inpaint --dtype float16
python opt_generator_inpaint.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--mask_dir img_clothes_masks \
--version 1-5-inpaint \
--dtype float16 \
--epoch 100 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix ""
python opt_generator_p2p.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--version p2p \
--dtype float16 \
--epoch 100 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix ""
python eval_generator_inpaint.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--mask_dir img_clothes_masks \
--version 1-5-inpaint \
--dtype float16 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix "eval_gen_time" \
--ckpt your_checkpoint
--concept: Target concept for attack (nudity, violence)--version: Model version (1-5-inpaint, 2-1-inpaint, p2p, ...)--vec_scale: Steering vector scale factor--eps: Perturbation budget (e.g., 64/255)--lr: Learning rate for optimization--epoch: Number of training epochs--bs: Batch size--dtype: Data type (float16, float32)--noise_gen: Noise generation method (adv_noise, vae, etc.)--attack: Attack type (vae in default)--defense: Defense mechanism (sc, noise, ng, diffpure)├── eval_generator_inpaint.py # Evaluation script for inpainting models
├── eval_generator_p2p.py # Evaluation script for P2P models
├── opt_generator_inpaint.py # Training script for inpainting models
├── opt_generator_p2p.py # Training script for P2P models
├── vec_gen.py # NSFW concept generation
├── run.sh # Example run script
├── environment.yml # Conda environment file
If you use this code in your research, please cite our paper:
@inproceedings{zengadvi2i,
title={AdvI2I: Adversarial Image Attack on Image-to-Image Diffusion Models},
author={Zeng, Yaopei and Cao, Yuanpu and Cao, Bochuan and Chang, Yurui and Chen, Jinghui and Lin, Lu},
booktitle={Forty-second International Conference on Machine Learning}
}
work_path variable in all scripts to point to your data directoryyour_wandb_account entity in wandb.init() should be replaced with your Weights & Biases account3 commits
Python
99.7%
This repository contains the implementation for the ICML paper "AdvI2I: Adversarial Image Attack on Image-to-Image Diffusion Models".
This work presents AdvI2I, a novel adversarial attack method targeting image-to-image diffusion models. Our approach generates adversarial perturbations that can manipulate the output of diffusion models while maintaining visual quality and semantic coherence.
conda env create -f environment.yml
conda activate advi2i
pip install -r requirements.txt
The nudenet could be installed by:
pip install nudenet
Download and extract the dataset.tar.gz file, which contains:
Place the extracted data in the following structure:
your_path/adv_diffusion/
├── dataset/
│ ├── naked_imgs/ # Training and testing images
│ ├── prompts/ # Prompts for constructing NSFW concept and dataset
│ └── img_clothes_masks/ # Mask images for inpainting
└── hf_results/ # Output directory
work_path in the scripts to point to your data directory.First, generate the NSFW concept for your target concept:
python vec_gen.py --concept nudity --version 1-5-inpaint --dtype float16
python opt_generator_inpaint.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--mask_dir img_clothes_masks \
--version 1-5-inpaint \
--dtype float16 \
--epoch 100 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix ""
python opt_generator_p2p.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--version p2p \
--dtype float16 \
--epoch 100 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix ""
python eval_generator_inpaint.py \
--ddim_steps 8 \
--tar_steps 8 \
--strength 1 \
--vec_scale 2.5 \
--concept nudity \
--mask_dir img_clothes_masks \
--version 1-5-inpaint \
--dtype float16 \
--lr 1e-5 \
--eps 64/255 \
--loss_type mse \
--prefix "eval_gen_time" \
--ckpt your_checkpoint
--concept: Target concept for attack (nudity, violence)--version: Model version (1-5-inpaint, 2-1-inpaint, p2p, ...)--vec_scale: Steering vector scale factor--eps: Perturbation budget (e.g., 64/255)--lr: Learning rate for optimization--epoch: Number of training epochs--bs: Batch size--dtype: Data type (float16, float32)--noise_gen: Noise generation method (adv_noise, vae, etc.)--attack: Attack type (vae in default)--defense: Defense mechanism (sc, noise, ng, diffpure)├── eval_generator_inpaint.py # Evaluation script for inpainting models
├── eval_generator_p2p.py # Evaluation script for P2P models
├── opt_generator_inpaint.py # Training script for inpainting models
├── opt_generator_p2p.py # Training script for P2P models
├── vec_gen.py # NSFW concept generation
├── run.sh # Example run script
├── environment.yml # Conda environment file
If you use this code in your research, please cite our paper:
@inproceedings{zengadvi2i,
title={AdvI2I: Adversarial Image Attack on Image-to-Image Diffusion Models},
author={Zeng, Yaopei and Cao, Yuanpu and Cao, Bochuan and Chang, Yurui and Chen, Jinghui and Lin, Lu},
booktitle={Forty-second International Conference on Machine Learning}
}
work_path variable in all scripts to point to your data directoryyour_wandb_account entity in wandb.init() should be replaced with your Weights & Biases account3 commits
Python
99.7%