本项目将 DINOv2 ViT-g/14 图像分类模型 适配到单卡昇腾 NPU(Ascend910)上运行。
模型由 DINOv2 ViT-g/14 主干网络和线性分类头组成,在 ImageNet-1k 上达到 86.5% 的 top-1 准确率。适配过程使用 ModelScope 本地权重加载,不依赖 HuggingFace 自动下载。
| 项目 | 版本 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.x |
| torch_npu | 已安装 |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
| 排名 | 类别 | 概率 |
|---|---|---|
| Top-1 | house finch, linnet, Carpodacus mexicanus | 0.9803 |
| Top-2 | brambling, Fringilla montifringilla | 0.0148 |
| Top-3 | goldfinch, Carduelis carduelis | 0.0017 |
| Top-4 | jay | 0.0006 |
| Top-5 | indigo bunting, indigo finch, indigo bird, Passerina cyanea | 0.0003 |
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.002928 |
| mean_abs_error | 0.000613 |
| relative_error | 0.0534% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
CPU Top-1: house finch, linnet, Carpodacus mexicanus NPU Top-1: house finch, linnet, Carpodacus mexicanus Top-1 match: True
| 指标 | 数值 |
|---|---|
| avg_time_ms | 23.78 |
| min_time_ms | 23.59 |
| max_time_ms | 25.00 |
| p50_time_ms | 23.63 |
| p90_time_ms | 23.86 |
| p95_time_ms | 24.43 |
| throughput_images_per_sec | 42.05 |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.txt 和 screenshots/self_verification.png。
logs/inference.log — 推理输出logs/accuracy.log — 精度验证结果logs/benchmark.log — 性能基准测试结果logs/env_check.log — NPU 环境检查*.pth)不提交到 Git,通过 .gitignore 排除#NPU #Ascend #DINOv2 #ImageClassification