Link to this sectionHuawei Ascend Export for Ultralytics YOLO Models#
在 Huawei Ascend AI 处理器上部署计算机视觉模型需要将其编译为由 Ascend AI Core 执行的 .om 离线模型格式。将 Ultralytics YOLO 模型导出到 Ascend 可以让你在 Atlas 开发者板和 OrangePi AIPro 设备上运行快速、低功耗的推理,这些设备广泛应用于机器人、工业检测和智能相机部署。
Link to this section什么是 Huawei Ascend?#
Huawei Ascend 是一系列 AI 处理器,搭配了华为的异构计算堆栈 CANN(Compute Architecture for Neural Networks,神经网络计算架构)。CANN 搭载了 ATC(Ascend Tensor Compiler,昇腾张量编译器),这是一个主机端工具,可将标准的 ONNX 图转换为针对 Ascend AI Core 的硬件专用 .om 离线模型。
由于 ATC 完全在主机上运行,你可以在未连接任何 Ascend 硬件的普通 x86-64 或 ARM64 Linux 机器上编译模型,然后将生成的 .om 复制到目标设备上进行推理。
Link to this sectionAscend 导出格式#
Ultralytics 导出器首先写入一个中间 ONNX graph,然后调用 ATC 将其编译为你通过 name 参数定位的 SoC。结果是一个自包含的模型目录,其中包含 .om 二进制文件及其 Ultralytics 元数据。
Link to this sectionAscend 模型的主要特点#
- 专用 AI Core:编译后的模型在 Ascend AI Core 上执行,而不是在主机 CPU 上,这为实时相机管道提供了显著更高的吞吐量。
- 主机端编译:ATC 不需要连接 NPU,因此导出可以在 CI、容器或笔记本电脑中运行。
- 以 ONNX 为先:标准的 Ultralytics ONNX 导出直接馈送到 CANN 工具链中,无需专有的中间格式。
- 静态形状:输入形状在编译时被固化到
.om中,消除了运行时形状协商开销。 - 多设备定位:通过更改
name,相同的 ONNX graph 可以为任何受支持的 SoC 进行编译。
Link to this section支持的任务#
Ascend 导出支持所有七个 Ultralytics 任务。检测、实例分割、姿态估计、OBB 和分类涵盖了 YOLO26、YOLO11 和 YOLOv8 系列;语义分割和深度估计仅适用于 YOLO26。
Link to this section支持的设备#
Pass the target SoC with name; ATC bakes it into the .om as --soc_version, so it must match the board you deploy to. Locally you can compile for any SoC your CANN installation provides kernels for. On Ultralytics Platform, the 310B targets are listed as coming soon while their operator kernels are added to the build image.
name | 设备 | 本地导出 | 平台 |
|---|---|---|---|
Ascend310P3 | Atlas 300I Pro, Atlas 300V Pro | ✅ | ✅ |
Ascend310P1 | Atlas 300I | ✅ | ✅ |
Ascend310B4 | OrangePi AIPro 20T, Atlas 200I A2 | ✅ | 即将推出 |
Ascend310B1 | OrangePi AIPro 8T | ✅ | 即将推出 |
Link to this section导出到 Ascend:转换你的 YOLO 模型#
Ascend 导出需要 CANN 工具包,该工具包仅支持 Linux。atc 编译器必须在你的 PATH 中——在导出之前加载 CANN 环境变量脚本,例如 source /usr/local/Ascend/ascend-toolkit/set_env.sh。
Link to this section安装#
安装 Ultralytics,然后从华为单独安装 CANN。
# Install the required package for YOLO
pip install ultralyticsCANN 工具包由华为分发,不会自动安装。请从 Ascend 社区下载页面下载,或者使用官方的 ascendai/cann 容器镜像,其中捆绑了 ATC 及其依赖项。
ATC can only compile for SoC families whose operator kernels are installed. A toolkit carrying only ascend310p kernels fails with No supported Ops kernel and engine are found for ... Conv2D when asked for an Ascend310B4 target. Install the matching Ascend-cann-kernels-<soc> package for the device you deploy to.
Link to this section用法#
Ascend 格式支持 Export、Predict 和 Validate 模式。推理和验证在 Ascend 硬件上运行。导出你的模型,然后加载导出的模型以运行推理或验证其准确性。
from ultralytics import YOLO
# Load a YOLO26 model
model = YOLO("yolo26n.pt")
# Export the model to Ascend format for an Atlas 200I / OrangePi AIPro board
model.export(format="ascend", name="Ascend310B4")
# Load the exported Ascend model and run inference on the device
ascend_model = YOLO("yolo26n_ascend_model")
results = ascend_model("https://ultralytics.com/images/bus.jpg")Link to this section导出参数#
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
format | str | 'ascend' | 导出模型的的目标格式,定义了与 Ascend AI 处理器的兼容性。 |
name | str | 'Ascend310B4' | 作为 --soc_version 传递给 ATC 的目标 SoC,例如 Ascend310P3。你的 CANN 安装为其拥有内核的任何 SoC 都是有效的;参见支持的设备。必须与你的部署设备相匹配。 |
imgsz | int 或 tuple | 640 | 模型输入的期望图像大小,作为静态形状固化到 .om 中。 |
batch | int | 1 | 编译到离线模型中的静态 batch 大小。 |
quantize | int | 16 | 量化精度。Ascend 导出仅支持 FP16,如果未指定,则自动启用 16。替换了已弃用的 half/int8 标志。 |
opset | int | 17 | 中间 graph 的 ONNX opset。上限为 17,即 CANN ONNX 解析器接受的最高版本。 |
simplify | bool | True | 使用 onnxslim 简化中间的 ONNX 图。 |
nms | bool | False | 向受支持的检测、分割、姿态和 OBB 模型添加非极大值抑制(NMS)。 |
Ascend AI Core 卷积仅接受 DT_FLOAT16 和 DT_INT8 输入,因此 FP32 离线模型无法在硬件上执行。请求 quantize=32 会引发错误,而不是默默生成一个无法运行的模型。
有关导出过程的更多详细信息,请访问 Ultralytics 导出文档页面。
Link to this section输出结构#
成功导出后,将创建一个具有以下布局的模型目录:
yolo26n_ascend_model/
├── yolo26n_Ascend310B4.om # Compiled Ascend offline model (AI Core executable)
└── metadata.yaml # Model metadata (classes, image size, task, etc.).om 文件是 CANN 运行时在设备上加载的编译后的离线模型。其名称包含目标 SoC,以便工件具备自我描述性;每个目录只保留一个 .om,因为加载器会选择它在那裡找到的单个模型。metadata.yaml 包含类名、图像大小以及 Ultralytics 推理管道使用的其他信息。
Link to this section部署导出的 YOLO Ascend 模型#
成功将 Ultralytics YOLO 模型导出到 Ascend 格式后,下一步是在 Ascend 硬件上部署它。
Link to this section运行时安装#
推理需要设备上的 CANN 运行时以及封装了 CANN 的 pyACL 绑定的 ais_bench Python 软件包。从华为 Ascend 工具仓库构建并安装它:
# On the Ascend device, with CANN installed and sourced
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# Build and install the ais_bench inference wheel
git clone https://gitee.com/ascend/tools.git
cd tools/ais-bench_workload/tool/ais_bench
pip3 wheel ./backend -v
pip3 install ./aclruntime-*.whl
pip3 wheel ./ -v
pip3 install ./ais_bench-*.whl将导出的 yolo26n_ascend_model 目录复制到设备上,然后像使用任何其他 Ultralytics 格式一样运行推理。
Link to this section推荐工作流程#
- 使用 Ultralytics Train 模式训练你的模型,或从预训练检查点开始。
- 在安装了 CANN 的任何 Linux 主机上导出到 Ascend,并传递与你的目标 SoC 匹配的
name。 - 将导出的模型目录复制到 Ascend 设备。
- 使用 CANN 运行时和
ais_bench进行部署以进行设备端推理。
Link to this section实际应用场景#
在 Ascend 硬件上运行的 YOLO 模型适用于广泛的嵌入式和工业视觉应用:
- 工业自动化:生产线上的高速质量检查和缺陷检测。
- 智能监控:无需中央服务器即可在边缘网关上进行实时多相机目标检测。
- 机器人:自主移动机器人和协作机械臂的车载感知。
- 智慧城市:低功耗路侧单元上的交通监控和行人分析。
Link to this section总结#
在本指南中,你已经学习了如何使用 CANN ATC 编译器将 Ultralytics YOLO 模型导出到 Huawei Ascend .om 格式。导出完全在主机上运行,生成一个自包含的模型目录,并通过单个 name 参数定位任何受支持的 Ascend SoC——为你提供了一条从训练好的 .pt 检查点到 Ascend AI 处理器上加速 FP16 推理的直接路径。
有关用法的更多详细信息,请访问官方 CANN 文档。
此外,如果你想了解有关其他 Ultralytics YOLO 集成的更多信息,请访问我们的集成指南页面以查找大量有用的资源。
Link to this section常见问题解答#
Link to this section如何将我的 Ultralytics YOLO 模型导出为 Ascend 格式?#
安装 Ultralytics 和 CANN 工具包,加载 CANN 环境使 atc 位于你的 PATH 中,然后在 Python 中使用 model.export(format="ascend", name="Ascend310B4") 或从 CLI 使用 yolo export model=yolo26n.pt format=ascend name=Ascend310B4 进行导出。将 name 设置为你部署设备的 SoC。
Link to this section导出模型需要 Ascend 硬件吗?#
不需要。ATC 编译器完全在主机上运行,因此编译可以在未连接 NPU 的标准 x86-64 或 ARM64 Linux 机器上进行。你只需要 Ascend 硬件来运行导出的 .om 的推理。
Link to this section为什么我的导出失败并显示 "No supported Ops kernel and engine are found"?#
你的 CANN 安装不包含你请求的 SoC 的算子内核。每个工具包都捆绑了特定 SoC 系列的内核,因此请安装与你的目标匹配的 Ascend-cann-kernels-<soc> 软件包,或者使用为该设备系列构建的容器镜像。
Link to this section为什么 Ascend 导出只支持 FP16?#
Ascend AI Core 卷积仅接受 DT_FLOAT16 和 DT_INT8 张量。FP32 离线模型将无法在硬件上执行,因此导出器使用 --precision_mode=force_fp16 进行编译并拒绝显式的 quantize=32 请求。
Link to this section支持哪些 Ascend 设备?#
任何你安装的 CANN 工具包为其提供内核的 SoC,通过 name 参数进行选择。有关四个经过验证的目标及其在 Ultralytics Platform 上的可用性,请参阅支持的设备。