本文档记录 nvidia/segformer-b0-finetuned-ade-512-512 在 Ascend 910B3 NPU 环境下的适配与验证结果。该模型基于 SegFormer-B0 架构,在 ADE20K 数据集上微调,支持 150 类语义分割。
本仓库提供:
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.8.0 |
torch_npu | 2.8.0.post4 |
transformers | 4.57.6 |
Ascend 910B3,1 逻辑卡SegformerForSemanticSegmentation(4 阶段,hidden_sizes=[32,64,160,256])512x512 RGB 图像150 类(ADE20K)pip install torch torch_npu transformers Pillow
export ASCEND_RT_VISIBLE_DEVICES=0python inference.py --image path/to/image.jpgpython inference.py --image-dir path/to/images/{
"model": "nvidia--segformer-b0-finetuned-ade-512-512",
"device": "npu:0",
"num_images": 1,
"results": [
{
"image": "scene.jpg",
"segmentation_shape": [128, 128],
"num_classes_found": 8,
"classes": {
"sky": {"class_id": 2, "pixel_count": 4096, "percentage": 25.0},
"building": {"class_id": 1, "pixel_count": 8192, "percentage": 50.0},
...
}
}
]
}python inference.py --image test_images/outdoor_landscape.jpg| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 2.2497 s | 0.0804 s |
| 吞吐量 | 1.78 img/s | 49.77 img/s |
| 加速比 | - | 27.98x |
精度评测采用逐像素预测一致率作为指标。
| 指标 | 数值 |
|---|---|
| 测试图片数 | 4 |
| 总像素数 | 65,536 |
| 匹配像素数 | 65,470 |
| 像素一致率 | 99.90% |
| 错误率 | 0.10% |
| 精度要求(错误率 < 1%) | 通过 |
结论:NPU 与 CPU 的逐像素分割结果一致率达 99.90%,错误率 0.10% 低于 1% 阈值,精度通过验证。