标签:
#model-agent-tagged·#NPU·#Ascend·#Ascend-910·#image-classification·#deepfake·#deepfake-detection本模型卡片已标注
#NPU、#Ascend、#Ascend-910与#model-agent-tagged标签,符合昇腾模型适配比赛提交要求。
buildborderless/CommunityForensics-DeepfakeDet-ViT
是 Deepfake(AI 生成图像)检测模型:ViT-Small 视觉 Transformer,在 270 万样本 /
4803 个生成器上训练(论文 "Community Forensics: Using Thousands of Generators to Train
Fake Image Detectors",CVPR 2025)。输入图像经 sigmoid 单类输出 fake 概率
(fake_prob > 0.5 判定为 AI 生成),用于社区开源深伪检测框架 OpenSight。
Linear(384 → 1),logits → sigmoidmodel.safetensors(87,270,764 B)+ config.json +
preprocessor_config.json,ViTForImageClassification.from_pretrained 直接加载transformers>=5.4.0(旧版 ViTImageProcessor 不支持
shortest_edge size 键,调用会 ValueError);本脚本内置手动预处理 fallback
(PIL resize/crop + torch 归一化,与契约数值一致),transformers 4.57.x 亦可完整运行torch.npu.is_available() 检测 + torch.npu.set_device,模型与输入
tensor 均 to("npu:0");全部算子为纯 PyTorch,在昇腾 NPU 上原生执行,无 CUDA 内核、
无 CPU fallback(图像解码/缩放属输入前处理,在 CPU 完成,非模型算子)logits -> sigmoid -> fake_prob,verdict = fake if fake_prob>0.5 else real| 组件 | 版本(实测) |
|---|---|
| Python | 3.11(aarch64) |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1(CANN 25.5.5) |
| transformers | 4.57.6(官方要求 >=5.4.0,本脚本含手动预处理 fallback) |
| pillow | 12.2.0 |
| numpy | 1.26.4 |
git clone https://gitcode.com/stella4528/CommunityForensics-DeepfakeDet-ViT-npu
cd CommunityForensics-DeepfakeDet-ViT-npu
pip install -r requirements.txtpython3 inference.pypython3 inference.py --device npu
python3 inference.py --device cpu --image my_image.jpg
python3 inference.py --device npu --image deepfake_sample.pngpixel_values (1,3,384,384) -> logits (1,1) -> fake_prob,
打印 verdict: fake/real 与 NPU_INFERENCE_PASS=True,结果落盘到 results/。实测结果见下方;适配脚本与输出截图见
assets/。
| 文件 | 说明 |
|---|---|
inference.py | 昇腾 NPU 推理脚本(ViT 分类前向 + 手动预处理 fallback) |
weights/model.safetensors | 原始权重(87,270,764 B,fp32) |
weights/config.json | 模型配置(ViT-Small 384/16,num_labels=1) |
weights/preprocessor_config.json | 预处理契约(440 resize / 384 crop / CLIP normalize) |
requirements.txt | 环境依赖清单 |