资料

dtop

Jetson有Jtop,Linux有Htop,RDK也有Dtop! - 板卡使用 - 地瓜机器人论坛

模型量化

首先准备yolov11模型

转onnx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# yolo11_to_onnx.py
from ultralytics import YOLO

# 加载你训练好的 YOLOv11 模型
pt_file = "best.pt"

model = YOLO(pt_file)

# 导出 ONNX(RDK S100 兼容模式)
model.export(
format="onnx",
imgsz=640, # 必须和训练时一致
batch=1, # 固定 batch=1(RDK 推荐)
opset=11, # 必须为 11!
dynamic=False, # 关闭动态 shape(避免 BPU 不支持)
simplify=True, # 优化图(移除冗余节点)
nms=False, # 先不带 NMS(RDK BPU 可能不支持 NonMaxSuppression)
device="cpu" # 导出时用 CPU 避免 GPU 干扰
)

print(f"✅ YOLOv11 ONNX 已生成: {pt_file.replace('.pt', '.onnx')}")

hb_compile算子检测

使用hb_compile检测BPU算子支持,S100 用 nash-e,S100P 用 nash-m

1
2
3
4
hb_compile \
--march nash-e \
--model ./best.onnx \
--input-shape images 1x3x640x640

hb_compile量化工具

直接量化,快速性能评测模式(开启fast-perf),会转为int8-NV12模型

1
2
3
4
hb_compile --fast-perf \
--model /open_explorer/data/best.onnx \
--march nash-m \
--input-shape images 1x3x640x640

自定义量化细节

创建yolo11_quantize.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

编辑
# 模型参数组
model_parameters:
onnx_model: "best.onnx"
march: "nash-m" # S100P 用 nash-m,S100 用 nash-e
output_model_file_prefix: "yolo11_bgr"
working_dir: "./model_output"

# 输入信息参数组
input_parameters:
input_name: "images" # ONNX 模型的输入节点名(用 netron 查看)
input_type_train: "bgr" # 训练时是 BGR
input_type_rt: "bgr" # 运行时也用 BGR(关键!)
input_layout_train: "NCHW" # YOLOv8/v11 通常是 NCHW
input_shape: "1x3x640x640" # 根据你的模型实际输入改
mean_value: "0 0 0" # 如果训练时没减均值,就设为 0
scale_value: "0.003921568627451" # = 1/255,如果训练时归一化到 [0,1]

# 校准参数组
#calibration_parameters:
# cal_data_dir: "./calib_data" # 必须存在且包含校准图片(BGR 格式)

# 编译参数组
compiler_parameters:
compile_mode: "latency"
core_num: 1
optimize_level: "O2"