yaml文件配置

在配置yaml文件时出现一下错误,是不是因为yaml文件配置格式还是什么不对,日志如下:

root@ba74fe20fe05:/open_explorer# cat > /workspace/yolo11n_seg_config.yaml <<‘EOF’

model_parameters:
onnx_model: /workspace//yolo11n-seg.onnx
output_model_file_prefix: /workspace/yolo11n_seg
march: x5
input_parameters:
input_name: images
input_type: rgb
input_shape: [1, 3, 640, 640]
input_layout: NCHW
norm_type: data_scale
scale_value: 1.0
bration_paramete>
calibration_parameters:
calibration_data_dir: /workspace/calibration_images
calibration_type: default

compile_parameters:
optimize_method: bpu
target: x5
cores: 1
debug: false
EOF
root@ba74fe20fe05:/open_explorer# hb_mapper makertbin --config /workspace/config.yaml
Usage: hb_mapper makertbin [OPTIONS]

Error: Invalid value for ‘-c’ / ‘–config’: Path ‘/workspace/config.yaml’ does not exist.
root@ba74fe20fe05:/open_explorer# rm -f /workspace/yolo11n_seg_config.yaml
root@ba74fe20fe05:/open_explorer# cat > /workspace/yolo11n_seg_config.yaml <<‘EOF’

model_parameters:
onnx_model: /workspace/yolo11n-seg.onnx
output_model_file_prefix: /workspace/yolo11n_seg
march: x5

input_parameters:
input_name: images
input_type: rgb
input_shape: [1, 3, 640, 640]
input_layout: NCHW
norm_type: data_scale
scale_value: 1.0

calibration_parameters:
calibration_data_dir: /workspace/calibration_images
calibration_type: default

compile_parameters:
optimize_method: bpu
arget: x5
core> target: x5
cores: 1
debug: false
EOF
root@ba74fe20fe05:/open_explorer# hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml
2026-04-05 16:18:35,975 INFO log will be stored in /open_explorer/hb_mapper_makertbin.log
2026-04-05 16:18:35,975 INFO Start hb_mapper…
2026-04-05 16:18:35,975 INFO hbdk version 3.49.15
2026-04-05 16:18:35,975 INFO horizon_nn version 1.1.0
2026-04-05 16:18:35,975 INFO hb_mapper version 1.24.3
2026-04-05 16:18:35,975 INFO Start Model Convert…
2026-04-05 16:18:35,978 ERROR yaml file parse failed. Please double check your config file inputs
2026-04-05 16:18:35,979 ERROR Key ‘input_parameters’ error:
Wrong keys ‘input_layout’, ‘input_type’ in {‘input_name’: ‘images’, ‘input_type’: ‘rgb’, ‘input_shape’: [1, 3, 640, 640], ‘input_layout’: ‘NCHW’, ‘norm_type’: ‘data_scale’, ‘scale_value’: 1.0}
root@ba74fe20fe05:/open_explorer#

求各位佬解答

我来帮你分析这个 YAML 配置错误。从日志看,input_parameters 中的 input_layoutinput_type 是无效的配置项。

让我先搜索一下社区中正确的 hb_mapper 配置格式:

问题定位

你的 YAML 配置格式过时了。错误信息很明确:

Wrong keys 'input_layout', 'input_type'

这两个键名在新版 hb_mapper 工具链中已废弃,需要改用新格式。

解决方案

正确的 YAML 配置格式(X5 平台)

model_parameters:
  onnx_model: /workspace/yolo11n-seg.onnx
  march: x5
  output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
  input_name: images
  input_type_rt: nv12          # 板端推理输入类型
  input_type_train: rgb        # 训练时输入类型
  input_layout_train: NCHW     # 训练时布局
  norm_type: data_scale
  scale_value: 0.003921568627451  # 1/255

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: float32

compiler_parameters:
  compile_mode: latency
  optimize_level: O3
  debug: false

关键修改点

旧格式(错误) 新格式(正确)
input_type: rgb input_type_rt: nv12 + input_type_train: rgb
input_layout: NCHW input_layout_train: NCHW
input_shape: [1,3,640,640] 删除(工具链自动从 ONNX 读取)
calibration_type: default cal_data_type: float32
compile_parameters.optimize_method: bpu compiler_parameters.optimize_level: O3
compile_parameters.target: x5 删除(march 已指定)

执行步骤

# 1. 创建正确的配置文件
cat > /workspace/yolo11n_seg_config.yaml <<'EOF'
model_parameters:
  onnx_model: /workspace/yolo11n-seg.onnx
  march: x5
  output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
  input_name: images
  input_type_rt: nv12
  input_type_train: rgb
  input_layout_train: NCHW
  norm_type: data_scale
  scale_value: 0.003921568627451

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: float32

compiler_parameters:
  compile_mode: latency
  optimize_level: O3
  debug: false
EOF

# 2. 执行转换
hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml

参考资源

社区已有完整教程,建议查看:

注意事项

  1. 工具链版本:你用的是 hb_mapper version 1.24.3,配置格式已更新
  2. 分割模型:YOLO11-seg 有 6 个输出头,转换后可用 hb_perf 验证
  3. 校准数据:确保 /workspace/calibration_images 目录存在且有足够图片(建议 100+ 张)

转换成功后,可以用以下命令验证模型:

hb_perf /workspace/yolo11n_seg.bin

按照上面配置文件后,出现一下情况

root@ba74fe20fe05:/open_explorer# hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml
2026-04-05 16:47:00,306 INFO log will be stored in /open_explorer/hb_mapper_makertbin.log
2026-04-05 16:47:00,307 INFO Start hb_mapper…
2026-04-05 16:47:00,307 INFO hbdk version 3.49.15
2026-04-05 16:47:00,307 INFO horizon_nn version 1.1.0
2026-04-05 16:47:00,307 INFO hb_mapper version 1.24.3
2026-04-05 16:47:00,307 INFO Start Model Convert…
2026-04-05 16:47:00,309 INFO Using onnx model file: /workspace/yolo11n-seg.onnx
2026-04-05 16:47:00,334 INFO Model has 1 inputs according to model file
2026-04-05 16:47:00,334 ERROR Parse ‘model_parameters’ failed!
2026-04-05 16:47:00,334 ERROR yaml file parse failed. Please double check your config file inputs
2026-04-05 16:47:00,335 ERROR User input march invalid: ‘x5’ . It should in list [‘bernoulli2’, ‘bayes’, ‘bayes-e’]

怎么解决

问题定位

错误信息很明确:

User input march invalid: 'x5'. It should in list ['bernoulli2', 'bayes', 'bayes-e']

原因march 参数应该填芯片代号,不是产品名。

  • RDK X5 对应的芯片是 Bayes-E,应该用 bayes-e
  • x5 是产品名,工具链不识别

解决方案

修改 YAML 中的 march 参数:

model_parameters:
  onnx_model: /workspace/yolo11n-seg.onnx
  march: bayes-e              # 改为 bayes-e,不是 x5
  output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
  input_name: images
  input_type_rt: nv12
  input_type_train: rgb
  input_layout_train: NCHW
  norm_type: data_scale
  scale_value: 0.003921568627451

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: float32

compiler_parameters:
  compile_mode: latency
  optimize_level: O3
  debug: false

完整执行命令

# 重新创建配置文件
cat > /workspace/yolo11n_seg_config.yaml <<'EOF'
model_parameters:
  onnx_model: /workspace/yolo11n-seg.onnx
  march: bayes-e
  output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
  input_name: images
  input_type_rt: nv12
  input_type_train: rgb
  input_layout_train: NCHW
  norm_type: data_scale
  scale_value: 0.003921568627451

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: float32

compiler_parameters:
  compile_mode: latency
  optimize_level: O3
  debug: false
EOF

# 执行转换
hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml

芯片代号对照表

产品 芯片代号 (march)
RDK X3 / 旭日 X3 bernoulli2
RDK X5 bayes-e
其他 Bayes 系列 bayes

验证转换结果

转换成功后,用以下命令验证模型:

hb_perf /workspace/yolo11n_seg.bin

查看输出是否为 6 个输出头(YOLO11-seg 的特征)。


参考教程从头开始 YOLOV11 自训练模型的板端部署和量化 - 里面有完整的配置示例。

root@ba74fe20fe05:/workspace# hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml
2026-04-05 17:29:16,703 INFO log will be stored in /workspace/hb_mapper_makertbin.log
2026-04-05 17:29:16,703 INFO Start hb_mapper…
2026-04-05 17:29:16,703 INFO hbdk version 3.49.15
2026-04-05 17:29:16,703 INFO horizon_nn version 1.1.0
2026-04-05 17:29:16,703 INFO hb_mapper version 1.24.3
2026-04-05 17:29:16,703 INFO Start Model Convert…
2026-04-05 17:29:16,705 INFO Using onnx model file: /workspace/yolo11n-seg.onnx
2026-04-05 17:29:16,723 INFO Model has 1 inputs according to model file
2026-04-05 17:29:16,723 INFO Model input shape not given in yaml_file, using shape from model file: [[1, 3, 640, 640]]
2026-04-05 17:29:16,723 INFO nv12 input type rt received.
2026-04-05 17:29:16,723 WARNING The calibration dir name suffix is not the same as the value float32 of the parameter cal_data_type, the parameter setting will prevail
2026-04-05 17:29:16,723 INFO custom_op does not exist, skipped
2026-04-05 17:29:16,724 WARNING Input node images’s input_source not set, it will be set to pyramid by default
2026-04-05 17:29:16,725 INFO *******************************************
2026-04-05 17:29:16,725 INFO First calibration picture name: calib_00.jpg
2026-04-05 17:29:16,725 INFO First calibration picture md5:
079aa50fb05e391b2d956b860a880a30 /workspace/calibration_images/calib_00.jpg
2026-04-05 17:29:16,728 INFO *******************************************
2026-04-05 17:29:16,728 ERROR load cal data for input ‘images’ error
2026-04-05 17:29:16,729 ERROR cannot reshape array of size 103914 into shape (1,3,640,640)
root@ba74fe20fe05:/workspace#

这种情况如何解决呢

问题定位

错误信息很明确:

ERROR cannot reshape array of size 103914 into shape (1,3,640,640)

原因:校准数据格式不对。

  • 你的校准目录里是 JPG 图片文件
  • cal_data_type: float32 告诉工具链期望 原始 float32 数据
  • 工具链读取 JPG 文件二进制数据(103914 字节),无法 reshape 成 3×640×640=1,228,800 的数组

解决方案

方案一:使用图片格式(推荐,简单)

修改 YAML,让工具链直接读取 JPG 图片:

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: jpg          # 改为 jpg,工具链会自动解码

方案二:预处理校准数据(正式部署推荐)

使用 OE 包里的预处理脚本将图片转为 float32 格式:

# 1. 找到数据预处理脚本(在 OE 包里)
find /open_explorer -name "data_preprocess.py"

# 2. 执行预处理(假设脚本在 /open_explorer/tools/)
python3 /open_explorer/tools/data_preprocess.py \
  --src_dir /workspace/calibration_images \
  --dst_dir /workspace/calibration_data_float \
  --dst_type float32 \
  --img_size 640

# 3. 修改 YAML 指向新目录
calibration_parameters:
  cal_data_dir: /workspace/calibration_data_float
  cal_data_type: float32

方案三:快速验证(先跑通)

如果只是想快速验证流程,用方案一改 YAML 即可:

cat > /workspace/yolo11n_seg_config.yaml <<'EOF'
model_parameters:
  onnx_model: /workspace/yolo11n-seg.onnx
  march: bayes-e
  output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
  input_name: images
  input_type_rt: nv12
  input_type_train: rgb
  input_layout_train: NCHW
  norm_type: data_scale
  scale_value: 0.003921568627451

calibration_parameters:
  cal_data_dir: /workspace/calibration_images
  cal_data_type: jpg

compiler_parameters:
  compile_mode: latency
  optimize_level: O3
  debug: false
EOF

hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml

校准数据要求

要求 说明
数量 建议 100+ 张,最少 50 张
格式 JPG/PNG 或预处理后的 float32
尺寸 不需要严格 640×640,工具链会自动 resize
内容 应覆盖实际使用场景的各种情况

验证校准数据

# 检查图片数量和格式
ls -la /workspace/calibration_images/ | head -20
ls /workspace/calibration_images/ | wc -l

# 查看第一张图片信息(如果安装了 ImageMagick)
identify /workspace/calibration_images/calib_00.jpg

建议:先用方案一cal_data_type: jpg)跑通流程,确认模型转换成功后,再用方案二做正式部署的校准数据预处理。

参考教程:从头开始 YOLOV11 自训练模型的板端部署和量化 - 里面有完整的校准数据准备说明。

root@ba74fe20fe05:/workspace# cat > /workspace/yolo11n_seg_config.yaml <<‘EOF’

model_parameters:
onnx_model: /workspace/yolo11n-seg.onnx
march: bayes-e
output_model_file_prefix: /workspace/yolo11n_seg

input_parameters:
input_name: images
input_type_rt: nv12
input_type_train: rgb
input_layout_train: NCHW
norm_type: data_scale
scale_value: 0.003921568627451
bration_paramete>
calibration_parameters:
cal_data_dir: /workspace/calibration_uint8
cal_data_type: uint8

compiler_parameters:
compile_mode: la> compile_mode: latency
optimize_level: O3
debug: false
EOF
root@ba74fe20fe05:/workspace# hb_mapper makertbin --config /workspace/yolo11n_seg_config.yaml
2026-04-05 17:45:03,430 INFO log will be stored in /workspace/hb_mapper_makertbin.log
2026-04-05 17:45:03,431 INFO Start hb_mapper…
2026-04-05 17:45:03,431 INFO hbdk version 3.49.15
2026-04-05 17:45:03,431 INFO horizon_nn version 1.1.0
2026-04-05 17:45:03,431 INFO hb_mapper version 1.24.3
2026-04-05 17:45:03,431 INFO Start Model Convert…
2026-04-05 17:45:03,433 INFO Using onnx model file: /workspace/yolo11n-seg.onnx
2026-04-05 17:45:03,448 INFO Model has 1 inputs according to model file
2026-04-05 17:45:03,448 INFO Model input shape not given in yaml_file, using shape from model file: [[1, 3, 640, 640]]
2026-04-05 17:45:03,448 INFO nv12 input type rt received.
2026-04-05 17:45:03,449 INFO The calibration dir name suffix is the same as the value uint8 of the cal_data_type parameter and will be read with the value of cal_data_type.
2026-04-05 17:45:03,449 INFO custom_op does not exist, skipped
2026-04-05 17:45:03,449 WARNING Input node images’s input_source not set, it will be set to pyramid by default
2026-04-05 17:45:03,450 INFO *******************************************
2026-04-05 17:45:03,450 INFO First calibration picture name: calib_00.bin
2026-04-05 17:45:03,450 INFO First calibration picture md5:
e425de322b0316a2844f9b7f23d82466 /workspace/calibration_uint8/calib_00.bin
2026-04-05 17:45:03,454 INFO *******************************************
2026-04-05 17:45:04,113 ERROR wrong model type None
root@ba74fe20fe05:/workspace#

问题定位

错误信息:ERROR wrong model type None

原因hb_mapper makertbin 命令缺少 --model-type 参数。

你的 YAML 配置没问题,但命令不完整。

解决方案

修正命令

hb_mapper makertbin --model-type onnx --config /workspace/yolo11n_seg_config.yaml

关键:加上 --model-type onnx

完整执行流程

# 1. 确认 YAML 配置(你当前的配置没问题)
cat /workspace/yolo11n_seg_config.yaml

# 2. 执行转换(加上 --model-type onnx)
hb_mapper makertbin --model-type onnx --config /workspace/yolo11n_seg_config.yaml

# 3. 验证转换结果
hb_perf /workspace/yolo11n_seg.bin

命令参数说明

参数 说明
--model-type onnx 指定输入模型类型为 ONNX
--config xxx.yaml 指定配置文件路径

预期成功输出

转换成功后会看到类似输出:

INFO Model Convert finished successfully
INFO Output model: /workspace/yolo11n_seg.bin

然后用 hb_perf 验证模型结构,YOLO11-seg 应该有 6 个输出头


小提示:你的校准数据用 uint8 格式(.bin 文件)是可以的,说明你已经做过预处理了。直接加上 --model-type onnx 应该就能跑通。

参考教程:从头开始 YOLOV11 自训练模型的板端部署和量化 - 命令格式参考第 3 节。

你好,基础工具链使用可以参考model zoo现有案例体验一下转化流程,自己编写yaml可以参考,参考工具链手册来实现