volo_d5_224 是基于 VOLO (Vision Outlooker) 架构的图像分类模型,在 ImageNet-1K 数据集上预训练。VOLO 通过引入 Outlooker 注意力机制,有效提升了视觉 Transformer 在细粒度分类任务上的性能。
图像分类 (Image Classification)
torch>=2.0.0
torch-npu>=2.1.0
timm>=0.9.0
Pillow>=9.0.0
scipy>=1.7.0
numpy>=1.20.0本模型已在华为昇腾 Ascend 910 NPU 上完成适配和测试。适配基于 PyTorch + torch_npu 框架,利用 timm 模型库加载预训练权重,通过 model.to("npu") 将模型迁移至 NPU 进行推理。
主要适配步骤:
model.to(torch.npu.current_device()))resolve_data_config + create_transform)# 设置 huggingface 镜像(如果无法访问 huggingface.co)
export HF_ENDPOINT=https://hf-mirror.com
# 安装依赖
pip install -r requirements.txtpython3 inference.py --device cpu --output cpu_result.jsonpython3 inference.py --device npu --output npu_result.json| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | window screen | 88.29% |
| 2 | throne | 1.06% |
| 3 | wig | 0.62% |
| 4 | racket | 0.11% |
| 5 | Dutch oven | 0.07% |
CPU 推理耗时: 2.8087s
| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | window screen | 88.11% |
| 2 | throne | 1.11% |
| 3 | wig | 0.61% |
| 4 | racket | 0.11% |
| 5 | Dutch oven | 0.07% |
NPU 推理耗时: 0.026s
| 指标 | CPU | NPU |
|---|---|---|
| 推理耗时 (s) | 2.8087 | 0.026 |
NPU 推理加速比: 108.03x
运行精度对比脚本:
python3 compare_cpu_npu.py| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.06125617 |
| Logits 平均绝对误差 | 0.00228704 |
| Logits 余弦相似度 | 0.99996203 |
| 概率最大差异 | 0.1815% |
| 概率平均差异 | 3.8e-06 |
| Top-5 一致数 | 5/5 |
| Top-1 匹配 | True |
| 排名 | CPU 类别 | CPU 概率 | NPU 类别 | NPU 概率 | 匹配 |
|---|---|---|---|---|---|
| 1 | window screen | 88.29% | window screen | 88.11% | ✓ |
| 2 | throne | 1.06% | throne | 1.11% | ✓ |
| 3 | wig | 0.62% | wig | 0.61% | ✓ |
| 4 | racket | 0.11% | racket | 0.11% | ✓ |
| 5 | Dutch oven | 0.07% | Dutch oven | 0.07% | ✓ |
NPU 与 CPU 推理结果误差 < 1%。 具体数值:

本模型适用于图像分类任务,可直接在华为昇腾 NPU 上部署推理:
对于批量推理需求,可将多个图像依次送入模型,并收集分类结果。