ICCV 2025 论文官方代码
📄 针对未经授权个人图像生成的防篡改保护
conda create --name ATP --file requirements.txt
conda activate ATP
下载数据集 CelebA-HQ 和 VGGFace2。数据集链接可在 CelebA-HQ、VGGFace2 中找到。对于授权模型训练,还应下载 FFHQ
在 configs/authorization.yaml 中设置 weights 路径,并在 configs/protection.yaml 中设置 mask 路径
运行
python perturb.py --device cuda:0 --input_dir path_to_cleanData --output_dir path_to_perturbedData --method CAAT --input-mask path_to_mask
我们建议将 CAAT 与 ATP 集成,这能在生成效率和保护性能之间取得良好平衡。但我们也提供了集成 MetaCloak、Anti-DreamBooth 和 AdvDM 的代码。
output_dir/
├── Authorized/ # Authorized images
| ├ {id}/ # Authorized images separated by id
| ├ Authorization_messages/ # Authorization messages for each image
└── ATP_{method}/ # Protected Images by ATP+{method}
├ {id}/ # ATP Perturbed images separated by id
在 configs/verification.yaml 中设置 weights 路径
✅ 无净化:运行
cd authorization
python verify.py --message_dir path_to_authorization_messages --input_dir path_to_atp_protected_image --method CAAT
cd authorization
python verify.py --message_dir path_to_authorization_messages --input_dir path_to_atp_protected_image --method CAAT --noise-args 2 --noise-type Resize
cd authorization
python verify.py --message_dir path_to_authorization_messages --input_dir path_to_atp_protected_image --method CAAT --noise-args 70 --noise-type JPEG
cd authorization
python verify.py --message_dir path_to_authorization_messages --input_dir path_to_atp_protected_image --method GridPure
示例输出:
Average Bit-Error: 0.44984375 Unauthorized image Ratio: 1.0 Pass Verification Identity Num: 0
"Pass Verification Identity Num" 可用于计算保护成功率(PSR)。一旦发生净化且身份无法通过验证,我们便将其视为一次成功的保护。
如果图像通过验证,它们便可被用于生成。
cd generation
python generate.py --input_dir path_to_image_for_generation --method CAAT --device cuda:0
结果保存在 "DREAMBOOTH" 目录中。
尽管在我们的实验中,净化后的图像因完全无法通过验证而未用于生成,我们仍然提供了基线算法的代码以方便比较。
对于 JPEG 和 Resize,运行:
cd generation
python generate.py --input_dir path_to_image_for_generation --method CAAT --device cuda:0 --purification naive
对于 Gridpure,您需要先运行 GridPure,然后使用净化后的图像运行:
cd generation
python generate.py --input_dir path_to_image_for_generation --method CAAT --device cuda:0 --purification gridpure
修改 ./configs/metrics.yaml 中定义的设置。您需要定义待评估图像的路径(instance_dir)、用于存储评估结果记录文件的目录路径(output_dir)、用于生成的提示词以及 ID 嵌入路径(id_emb_path)。
cd metrics
python eval_dir.py --dataset CelebA-HQ --method CAAT
评估结果将保存在您在 metrics.yaml 中定义的 output_dir 中
python show.py --path evaluation_results
示例输出:
CLIP-IQAC LIQE ISM FDFR PSR
-0.176525 1.033371 0.489084 0.406250 0.859375
(通过修改 eval_dir.py 代码中第 67 行到第 68 行(已注释),您还可以评估来自朴素变换的净化生成结果。)
您也可以训练自己的授权模型。
修改 ./configs/authorization.yaml 中的设置
cd authorization
bash scripts/train.sh
在构建此项目时,我们借鉴了以下项目的代码:LIQE、GridPure、ANTIDB、METACLOAK、CAAT、HiDDeN、BasicSR。
感谢他们的出色工作!
📌 如果您觉得此项目对您的研究有用,请考虑引用我们的论文。
© 2025 伊利诺伊大学董事会。保留所有权利。
| Argument | Description | Example |
|---|
--device | 决定在哪个 GPU 上运行模型 | cuda:0, cuda:1 |
--input_dir | 干净输入图像的路径 | ./data/clean/ |
--output_dir | 保存扰动图像的路径 | ./data/perturbed/ |
--method | 保护扰动方法 | CAAT, ANTIDB, ADVDM,METACLOAK |
--input-mask | 掩码的路径 | ./mask/050_mask.pt |
| Argument | Description | Example |
|---|
--message_dir_dir | 授权消息目录的路径 | ./data/Authorization_messages |
--input_dir | 待验证图像的路径 | ./data/perturbed/ |
--method | 保护扰动方法 | CAAT, ANTIDB, ADVDM,METACLOAK |
--noise-args | 保护扰动方法 | 2, 50 |
--noise-type | 保护扰动方法 | JPEG, Resize |
| Argument | Description | Example |
|---|
--dataset | 用于评估的数据集 | CelebA-HQ, VGGFace2 |
--method | 保护扰动方法 | CAAT, ANTIDB, ADVDM,METACLOAK |