本仓库是对 timm 框架中 seresnext101_64x4d.gluon_in1k 模型在昇腾 NPU 上的适配版本。
模型来源:timm/seresnext101_64x4d.gluon_in1k
图像分类(Image Classification)
PyTorch + timm
[batch_size, 3, 224, 224][batch_size, num_classes],其中 num_classes = 1000(ImageNet)torch>=1.8.0
torch-npu
timm>=0.9.0
Pillow
numpy
modelscope
safetensors本模型通过 ModelScope 下载预训练权重,使用 PyTorch + timm 加载,通过 model.to('npu') 将模型迁移至昇腾 NPU 进行推理。无需修改模型结构。
pip install torch torch-npu timm Pillow numpy modelscope safetensors -i https://mirrors.aliyun.com/pypi/simple/python3 inference.py --device cpupython3 inference.py --device npu| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | 851 | 0.176583 |
| 2 | 893 | 0.123308 |
| 3 | 549 | 0.105877 |
| 4 | 411 | 0.071287 |
| 5 | 574 | 0.055254 |
| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | 851 | 0.380647 |
| 2 | 549 | 0.082209 |
| 3 | 893 | 0.050991 |
| 4 | 411 | 0.044770 |
| 5 | 539 | 0.029588 |
使用相同的测试图像分别在 CPU 和 NPU 上进行推理,对比输出 logits 的各项指标。
| 指标 | 值 |
|---|---|
| 参数量 | 88.23M |
| Logits MAE | 1.43866078e-01 |
| Logits Cosine Similarity | 0.98559193 |
| Probability MAE | 4.86917483e-04 |
| Top-1 Agreement | 100.00% |
| CPU 推理耗时 | 1.5955s |
| NPU 推理耗时 | 0.0150s |
| 加速比 | 106.55x |
NPU 与 CPU 推理结果误差 < 1%,精度满足要求。
#+NPU #+CV #+图像分类 #+timm #+昇腾
本仓库仅进行模型适配和推理验证,模型权重归原作者所有。