本项目将 timm/tf_efficientnet_cc_b1_8e.in1k 图像分类模型适配到昇腾 NPU (Ascend910) 上运行。模型基于 EfficientNet-CC-B1 (8e) 架构,在 ImageNet-1k 上训练,支持 1000 类图像分类。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 已安装 |
| timm | 最新版 |
环境检查日志见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU):
=== NPU Inference Result ===
Model: timm/tf_efficientnet_cc_b1_8e.in1k
Input: assets/test.jpg
Output shape: torch.Size([1, 1000])
Top-5 Predictions:
1. class_idx=437, prob=0.2115
2. class_idx=975, prob=0.1197
3. class_idx=978, prob=0.0831
4. class_idx=417, prob=0.0752
5. class_idx=972, prob=0.0311日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.005554 |
| mean_abs_error | 0.000848 |
| relative_error | 0.1151% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
在 Ascend910 单卡 NPU 上,输入尺寸 [1, 3, 240, 240]:
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 13.095 |
| min_latency_ms | 12.640 |
| max_latency_ms | 13.315 |
| p50_latency_ms | 13.199 |
| p90_latency_ms | 13.315 |
| p95_latency_ms | 13.315 |
| throughput_ips | 76.36 |
日志保存在 logs/benchmark.log。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.txt 和 screenshots/self_verification.png。
| 文件 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | 推理输出 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | 性能基准测试 |
modelscope.snapshot_download 下载,本地加载,禁止 HuggingFace 自动下载pretrained=False + 本地 safetensors 权重resolve_model_data_config + create_transform#NPU #Ascend #Ascend910 #ImageClassification