volo_d2_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 | 64.04% |
| 2 | wig | 1.87% |
| 3 | Dutch oven | 1.40% |
| 4 | stone wall | 1.37% |
| 5 | waffle iron | 0.63% |
CPU 推理耗时: 0.6578s
| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | window screen | 63.45% |
| 2 | wig | 1.88% |
| 3 | Dutch oven | 1.42% |
| 4 | stone wall | 1.39% |
| 5 | waffle iron | 0.64% |
NPU 推理耗时: 0.2281s
| 指标 | CPU | NPU |
|---|---|---|
| 推理耗时 (s) | 0.6578 | 0.2281 |
NPU 推理加速比: 2.88x
运行精度对比脚本:
python3 compare_cpu_npu.py| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.02949262 |
| Logits 平均绝对误差 | 0.00204103 |
| Logits 余弦相似度 | 0.99998444 |
| 概率最大差异 | 0.5914% |
| 概率平均差异 | 1.183e-05 |
| Top-5 一致数 | 5/5 |
| Top-1 匹配 | True |
| 排名 | CPU 类别 | CPU 概率 | NPU 类别 | NPU 概率 | 匹配 |
|---|---|---|---|---|---|
| 1 | window screen | 64.04% | window screen | 63.45% | ✓ |
| 2 | wig | 1.87% | wig | 1.88% | ✓ |
| 3 | Dutch oven | 1.40% | Dutch oven | 1.42% | ✓ |
| 4 | stone wall | 1.37% | stone wall | 1.39% | ✓ |
| 5 | waffle iron | 0.63% | waffle iron | 0.64% | ✓ |
NPU 与 CPU 推理结果误差 < 1%。 具体数值:

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