本项目将 timm/tf_efficientnet_b7.ns_jft_in1k 图像分类模型适配到单卡昇腾 NPU (Ascend910) 上运行。
模型类型:图像分类 (ImageNet-1k, 1000 classes) 架构:EfficientNet-B7 (by timm)
| 项目 | 版本 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 与 CANN 8.5.1 配套 |
| timm | latest |
环境检查日志:logs/env_check.log
pip install -r requirements.txt
python inference.py推理结果 (NPU):
=== NPU Inference Result ===
Model: timm/tf_efficientnet_b7.ns_jft_in1k
Input shape: [1, 3, 600, 600]
Output shape: [1, 1000]
Output dtype: torch.float32
Top-5 predictions:
1. class_idx=90, prob=0.154358
2. class_idx=323, prob=0.146251
3. class_idx=94, prob=0.065332
4. class_idx=990, prob=0.052615
5. class_idx=325, prob=0.043770
Raw logits (first 10):
[-0.4266427159309387, 0.1474224179983139, -0.7499443292617798, -0.05899123474955559, -0.8420599699020386, -0.3052010238170624, -0.6180973052978516, -0.7152126431465149, -0.682157576084137, -0.3898557722568512]日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.006737 |
| mean_abs_error | 0.000486 |
| relative_error | 0.0927% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency | 34.001 ms |
| min_latency | 32.924 ms |
| max_latency | 35.354 ms |
| p50_latency | 33.798 ms |
| p90_latency | 35.300 ms |
| p95_latency | 35.327 ms |
| throughput | 29.41 samples/s |
注:性能数据在单卡 Ascend910 上测得,实际数值可能因负载、温度、驱动版本而波动。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
screenshots/self_verification.txtscreenshots/self_verification.png| 文件 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | NPU 推理输出 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | NPU 性能基准测试 |
ModelScope snapshot_download 自动下载到本地缓存,首次运行需要联网。pretrained=False + 本地 safetensors 权重加载,不依赖 HuggingFace 自动下载。#NPU #Ascend #Ascend910 #ImageClassification #timm