脑瘤图像检测模型,基于 ViT (Vision Transformer) 架构,适配 Ascend NPU (Ascend910) 进行推理。
| 文件 | 说明 |
|---|---|
inference.py | CPU/NPU 推理脚本,支持 --device cpu 或 --device npu |
compare_cpu_npu.py | CPU vs NPU 精度对比脚本 |
requirements.txt | Python 依赖 |
terminal_screenshot.png | 推理结果终端截图 |
pip install -r requirements.txtCPU 推理:
python3 inference.py --device cpuNPU 推理:
python3 inference.py --device npu| 设备 | 推理耗时 | Top-1 类别 | Top-1 置信度 |
|---|---|---|---|
| CPU | 647.7 ms | glioma_tumor | N/A |
| NPU | 180.45 ms | glioma_tumor | N/A |
NPU 加速比约为 3.59x。
python3 compare_cpu_npu.py| 指标 | 值 |
|---|---|
| CPU 推理时间 | 647.7 ms |
| NPU 推理时间 | 180.45 ms |
| NPU 加速比 | 3.59x |
| Top-1 匹配 | 是 |
| Max Logits Absolute Error | 0.0015469789505004883 |
| Mean Logits Absolute Error | 0.0010141273960471153 |
| Max Probability Absolute Error | 0.00035347044467926025 |
| Mean Probability Absolute Error | 0.00022509321570396423 |
| Cosine Similarity (Logits) | 0.9999924898147583 |
| L2 Error (Logits) | 0.0011680604657158256 |
| 最大概率误差 | 0.0353% |
结论:NPU 与 CPU 推理结果误差 < 1%(最大概率误差为 0.0353%),精度符合要求。
精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。

基于现有评测数据,CPU 与 NPU 的 余弦相似度 精度误差为 0.0008%,小于 1% 的精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpu推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。