基于 Vision Transformer (ViT-Small) 的 AI 生成图像检测模型,适配华为 Ascend 910B/910C NPU。
原模型: buildborderless/CommunityForensics-DeepfakeDet-ViT
论文: Community Forensics: Using Thousands of Generators to Train Fake Image Detectors
| 属性 | 说明 |
|---|---|
| 任务 | AI 生成图像检测(深度伪造检测) |
| 架构 | ViT-Small (vit_small_patch16_384) |
| 输入尺寸 | 384 × 384 RGB |
| 输出 | 二分类概率(Sigmoid),≥0.5 为 AI 生成 |
| 精度 | 准确率 97.2%,AUC-ROC 0.992 |
| 训练数据 | 15+ 生成器、4600+ 模型、270 万张图像 |
| 许可证 | MIT |
确保已安装昇腾 NPU 驱动和 CANN 软件包,版本建议 CANN 7.0.RC1 及以上。
# 验证 NPU 可用
npu-smi info# 创建虚拟环境(推荐 Python 3.9+)
python3 -m venv venv
source venv/bin/activate
# 安装依赖
pip install -r requirements.txttorch_npu 需根据 CANN 版本安装,参考 Ascend PyTorch:
pip install torch-npu==2.1.0.post8
import torch
import torch_npu # noqa: F401
print(torch.npu.is_available()) # 应输出 True
print(torch.npu.device_count()) # NPU 卡数量python inference.py --image_path /path/to/test_image.jpg默认从 HuggingFace 镜像 ai.gitcode.com/hf_mirrors/buildborderless/CommunityForensics-DeepfakeDet-ViT 自动下载模型。
# 从 HuggingFace Hub
python inference.py --image_path test.jpg --model_path buildborderless/CommunityForensics-DeepfakeDet-ViT
# 从本地目录
python inference.py --image_path test.jpg --model_path ./model_weights
# 强制 CPU 推理
python inference.py --image_path test.jpg --cpu[INFO] 推理设备: npu:0
[INFO] 加载模型: ai.gitcode.com/hf_mirrors/buildborderless/CommunityForensics-DeepfakeDet-ViT
[INFO] 模型加载完成,参数量: 22,078,465
[INFO] 输入图像: test.jpg (1024×1024)
============================================================
结果: AI-Generated (Deepfake)
伪造概率 (AI-Generated): 98.73%
置信度: 98.73%
推理耗时: 45.23 ms
============================================================CommunityForensics-DeepfakeDet-ViT/
├── inference.py # 推理脚本(Ascend NPU 适配)
├── README.md # 本部署说明文档
├── requirements.txt # 环境依赖清单
└── assets/ # 截图素材
├── agent_workflow.png # 部署/推理流程截图
├── npu_device_call.png# NPU 设备调用截图
└── model_result.png # 推理结果截图输入图像 ──→ 预处理 (Resize 384 + CenterCrop + Normalize) ──→ ViT 编码器 ──→ 分类头 ──→ Sigmoid ──→ 概率
↑
Ascend NPU (torch_npu)本仓库已集成至 AtomGit 模型仓,支持一键拉取:
git clone https://atomgit.com/liuhongwei-2026/CommunityForensics-DeepfakeDet-ViT.git
cd CommunityForensics-DeepfakeDet-ViT
pip install -r requirements.txt
python inference.py --image_path example.jpg@misc{park2024communityforensics,
title={Community Forensics: Using Thousands of Generators to Train Fake Image Detectors},
author={Jeongsoo Park and Andrew Owens},
year={2024},
eprint={2411.04125},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2411.04125},
}