本项目将 timm/edgenext_small.usi_in1k 图片分类模型适配到单卡昇腾 NPU (Ascend910) 运行。
timm/edgenext_small.usi_in1ktimm.create_model(pretrained=False) 创建模型结构,通过 ModelScope snapshot_download 下载本地权重并加载,不使用 HuggingFace 自动下载。| 项目 | 版本/信息 |
|---|---|
| NPU | Ascend910 |
| npu-smi | 25.5.2 |
| PyTorch NPU | torch_npu available, device=Ascend910_9362 |
| 驱动/固件 | Healthy |
完整环境信息见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理脚本使用 model_utils.py 统一加载模型,通过 timm.data.resolve_model_data_config 自动解析预处理配置,在 npu:0 上执行真实推理。
推理结果示例:
Input shape: torch.Size([1, 3, 256, 256])
Output shape: torch.Size([1, 1000])
Top-5 predictions:
class_590: 0.4976
class_681: 0.1616
class_620: 0.0531
class_810: 0.0272
class_673: 0.0250python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.010764 |
| mean_abs_error | 0.002031 |
| relative_error | 0.2005% |
| cosine_similarity | 0.999998 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 结果 |
|---|---|
| Warmup | 2 次 |
| 正式测试 | 10 次 |
| 平均延迟 | 6.88 ms |
| P50 延迟 | 6.89 ms |
| P95 延迟 | 7.08 ms |
| 吞吐 | 145.34 images/sec |
本项目未在完整 ImageNet-1k 验证集上运行,仅提供 CPU-NPU 一致性 smoke 测试。如需完整精度,请使用 ImageNet-1k val 集配合 timm 官方验证流程。
关键验证内容已整理至 screenshots/self_verification.txt 与 screenshots/self_verification.png。
| 文件 | 内容 |
|---|---|
logs/env_check.log | NPU 环境信息 |
logs/inference.log | 推理结果 |
logs/accuracy.log | CPU-NPU 精度对比 |
logs/benchmark.log | 性能基准测试 |
logs/paths.txt | 模型与权重路径 |
timm.create_model(..., pretrained=False),再通过 modelscope.snapshot_download 获取本地权重路径并手动加载。严禁使用 pretrained=True 触发 HuggingFace 自动下载。.gitignore 已排除 .bin, .safetensors, .pth, .pt, .ckpt, .onnx 等权重文件,请勿将权重提交到 Git 仓库。npu:0,请确保该设备可用。#NPU