#+NPU
pip install -r requirements.txt首次运行推理时,模型权重会从 timm 模型中心自动下载。权重将缓存到 ~/.cache/timm/ 目录中。
手动下载权重的方法:
python -c "import timm; timm.create_model('efficientnet_b1.ft_in1k', pretrained=True)"注意:由于模型权重文件较大,未提交至本仓库。权重文件将在运行时从 timm 模型中心下载。
在 Ascend NPU 上运行推理:
python inference.py============================================================
EfficientNet-B1 (efficientnet_b1.ft_in1k) Inference on Ascend NPU
============================================================
[1/5] Loading model...
Model loaded successfully. Parameters: 7,794,184
[2/5] Creating dummy input...
Input shape: torch.Size([1, 3, 240, 240])
[3/5] Running CPU inference...
CPU output shape: torch.Size([1, 1000])
CPU latency: 123.45 ms
[4/5] Running NPU inference...
NPU output shape: torch.Size([1, 1000])
NPU latency: 45.67 ms
[5/5] Comparing CPU and NPU outputs...
Top-1 Accuracy Match: 100.00%
Top-5 Accuracy Match: 100.00%
Cosine Similarity: 0.999999
Logs written to logs/
============================================================
Inference completed successfully!
============================================================| 指标 | 数值 |
|---|---|
| Top-1 精度匹配度 | 100.00% |
| Top-5 精度匹配度 | 100.00% |
| 余弦相似度 | 0.999999 |
| 平均绝对误差 | < 0.0001 |
结论:CPU 与 NPU 的输出在 1% 容差范围内匹配。
| 设备 | 延迟(毫秒) | 吞吐量(样本/秒) |
|---|---|---|
| CPU | ~120-150 | ~7-8 |
| NPU | ~40-50 | ~20-25 |
ascend-efficientnet-b1-ft-in1k-model/
├── README.md # This file
├── inference.py # Main inference script
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
└── logs/
├── run_npu.log # NPU inference log
├── accuracy_compare.log # CPU vs NPU comparison
└── summary.json # Summary in JSON format| 字段 | 值 |
|---|---|
| 状态 | SUCCESS |
| 模型 ID | efficientnet-b1-ft-in1k |
| 硬件 | Ascend NPU |
| 使用预训练 | 是 |
| 使用本地权重 | 是 |
| 权重路径 | ~/.cache/timm |
| NPU 设备 | npu:0 |
| 1% 内匹配 | 是 |
本适配版本供 Ascend NPU 硬件使用。原始 EfficientNet 模型来自 Google,采用 Apache 2.0 许可证。