本项目将 HuggingFace 模型 facebook/regnet-x-120 适配到昇腾 NPU (Ascend910),使用 ModelScope 进行权重下载,通过 transformers 的 AutoModelForImageClassification 本地加载并完成单卡推理验证、精度一致性检查和性能基准测试。
模型类型:RegNetForImageClassification(ImageNet-1k 图像分类,1000 类)。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| torch | 2.x |
| torch_npu | 可用 |
| transformers | 最新 |
| modelscope | 最新 |
环境详情见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU, 输入为占位测试图):
=== NPU Inference Result ===
Model: facebook/regnet-x-120
Input shape: torch.Size([1, 3, 224, 224])
Output logits shape: torch.Size([1, 1000])
Top-5 predictions:
1. nematode, nematode worm, roundworm 0.0311
2. letter opener, paper knife, paperknife 0.0219
3. cleaver, meat cleaver, chopper 0.0196
4. corkscrew, bottle screw 0.0192
5. hook, claw 0.0161日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.002359 |
| mean_abs_error | 0.000626 |
| relative_error | 0.0568% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
NPU 单卡 batch=1 推理性能(10 次正式运行):
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 6.342 |
| min_latency_ms | 6.292 |
| max_latency_ms | 6.459 |
| p50_latency_ms | 6.316 |
| p90_latency_ms | 6.459 |
| p95_latency_ms | 6.459 |
| throughput_img/s | 157.68 |
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
logs/env_check.log — 环境检查logs/inference.log — 推理结果logs/accuracy.log — 精度验证logs/benchmark.log — 性能基准logs/stage0.log — 阶段 0 可用性验证logs/paths.txt — 模型路径记录snapshot_download 下载,不提交到本仓库(已在 .gitignore 中排除)。pytorch_model.bin。assets/test.jpg),实际使用时替换为真实图像即可。#NPU #Ascend #Ascend910 #RegNet #ImageClassification