森林害虫识别模型,基于 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 | 669.63 ms | ActiasDubernardiOberthur | N/A |
| NPU | 176.88 ms | ActiasDubernardiOberthur | N/A |
NPU 加速比约为 3.79x。
python3 compare_cpu_npu.py| 指标 | 值 |
|---|---|
| CPU 推理时间 | 669.63 ms |
| NPU 推理时间 | 176.88 ms |
| NPU 加速比 | 3.79x |
| Top-1 匹配 | 是 |
| Max Logits Absolute Error | 0.0033094584941864014 |
| Mean Logits Absolute Error | 0.001027516438625753 |
| Max Probability Absolute Error | 5.0008296966552734e-05 |
| Mean Probability Absolute Error | 1.8685170743992785e-06 |
| Cosine Similarity (Logits) | 0.9999984502792358 |
| L2 Error (Logits) | 0.0012934280093759298 |
| 最大概率误差 | 0.005% |
结论:NPU 与 CPU 推理结果误差 < 1%(最大概率误差为 0.005%),精度符合要求。
精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。

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