尝试使用OE3.2量化 Nvidia发布的FoundationStereo模型
步骤如下:
生成配置文件:
hb_config_generator --full-yaml --model FSV2320.onnx --march nash-e
生成内容如下:
calibration_parameters:
cal_data_dir: ./calibration_data_dir;./calibration_data_dir
quant_config: {}
compiler_parameters:
advice: 0
balance_factor: 0
cache_mode: disable
cache_path: ''
compile_mode: latency
core_num: 1
debug: true
jobs: 16
max_time_per_fc: 0
optimize_level: O2
input_parameters:
input_layout_train: NCHW;NCHW
input_name: left_image;right_image
input_shape: 1x3x320x736;1x3x320x736
input_type_rt: nv12;nv12
input_type_train: bgr;bgr
mean_value: ''
scale_value: ''
separate_batch: false
std_value: ''
model_parameters:
debug_mode: ''
march: nash-e
onnx_model: FSV2320.onnx
output_model_file_prefix: FSV2320
output_nodes: ''
remove_node_name: ''
remove_node_type: ''
working_dir: ./model_output
鉴于只是做通过性验证不追求精度删除了校准数据目录使用随机数据
量化命令
hb_compile --config full_compile_config.yaml
获得命令行输出如下:
2026-03-03 10:28:59,236 INFO The log will be stored in /Data/Work/S100FS00/hb_compile.log
2026-03-03 10:28:59,237 INFO Start hb_compile...
2026-03-03 10:28:59,238 INFO hbdk version: 4.2.11
2026-03-03 10:28:59,238 INFO hmct version: 2.4.1
2026-03-03 10:28:59,239 INFO hb_compile version: 3.3.22
2026-03-03 10:28:59,240 INFO Start verifying yaml
2026-03-03 10:29:01,041 INFO Using the onnx model file: /Data/Work/S100FS00/FSV2320.onnx
2026-03-03 10:29:01,043 INFO Model has 2 inputs according to model file
2026-03-03 10:29:01,046 WARNING Please note that the parameter norm_type has been deprecated and will be determined by the specification of the mean/scale/std parameters
2026-03-03 10:29:01,047 INFO The calibration dataset has not been specified, the calibration method is modified to skip
2026-03-03 10:29:01,048 WARNING The input node left_image's input_source is not be specified, it will be specified as None by default
2026-03-03 10:29:01,048 WARNING The input node right_image's input_source is not be specified, it will be specified as None by default
2026-03-03 10:29:01,050 INFO The parameter compile_mode is specified as latency, the balance_factor will be specified as 100.
2026-03-03 10:29:01,050 INFO End verifying yaml
2026-03-03 10:29:01,054 INFO Start to Horizon NN Model Convert.
2026-03-03 10:29:08,567 INFO Loading horizon_nn debug methods: set().
2026-03-03 10:29:08,572 INFO The specified model compilation architecture: nash-e.
2026-03-03 10:29:08,574 INFO The specified model compilation optimization parameters: [].
2026-03-03 10:29:08,575 INFO Start to prepare the onnx model.
2026-03-03 10:29:11,874 INFO Input ONNX Model Information:
IR Version: 8
Opset Version: ['ai.onnx v17', 'horizon v1']
Model Producer: pytorch v2.6.0
Model Domain: None
Model Version: None
Graph Input:
left_image : shape=[1, 3, 320, 736], dtype=FLOAT32
...t_image : shape=[1, 3, 320, 736], dtype=FLOAT32
Graph Output:
disparity : shape=[1, 1, 320, 736], dtype=FLOAT32
2026-03-03 10:29:11,885 INFO The input model's opset version is 17, try to convert to opset version of 19.
2026-03-03 10:29:28,311 INFO End to prepare the onnx model.
2026-03-03 10:29:31,251 INFO Saving model to: /Data/Work/S100FS00/model_output/FSV2320_original_float_model.onnx.
2026-03-03 10:29:31,252 INFO Start to optimize the onnx model.
2026-03-03 10:34:40,802 INFO End to optimize the onnx model.
2026-03-03 10:34:55,048 INFO Saving model to: /Data/Work/S100FS00/model_output/FSV2320_optimized_float_model.onnx.
2026-03-03 10:34:55,051 INFO The activation calibration configuration:
calibration_type: fixed
2026-03-03 10:34:55,052 INFO Start to calibrate the model.
2026-03-03 10:34:55,848 INFO No calibration data provided, using random data.
2026-03-03 10:40:18,030 INFO Run calibration model with fixed thresholds method.
2026-03-03 10:43:07,417 INFO End to calibrate the model.
2026-03-03 10:43:21,592 INFO Saving model to: /Data/Work/S100FS00/model_output/FSV2320_calibrated_model.onnx.
2026-03-03 10:43:21,594 INFO Start to quantize the model.
2026-03-03 10:46:05,174 INFO End to quantize the model.
2026-03-03 10:46:18,368 INFO Saving model to: /Data/Work/S100FS00/model_output/FSV2320_ptq_model.onnx.
2026-03-03 10:46:20,479 INFO End to Horizon NN Model Convert.
2026-03-03 10:46:20,488 INFO Start to export model.
Convert Node onnx::Resize ver 19 failed!
Details of the node...
input: "/cost_agg/conv_patch/conv_patch.0/Conv_output_0_calibrated"
input: ""
input: "/cost_agg/Constant_output_0"
output: "/cost_agg/Resize_output_0"
name: "/cost_agg/Resize"
op_type: "Resize"
attribute {
name: "coordinate_transformation_mode"
s: "half_pixel"
type: STRING
}
attribute {
name: "cubic_coeff_a"
f: -0.75
type: FLOAT
}
attribute {
name: "mode"
s: "linear"
type: STRING
}
attribute {
name: "nearest_mode"
s: "floor"
type: STRING
}
doc_string: "/usr/local/lib/python3.12/dist-packages/torch/nn/functional.py(4693): interpolate\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/model/stereo_depth/foundation_stereo/submodule.py(413): forward\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1730): _slow_forward\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1751): _call_impl\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1740): _wrapped_call_impl\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/model/stereo_depth/foundation_stereo/foundation_stereo.py(209): forward\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1730): _slow_forward\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1751): _call_impl\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1740): _wrapped_call_impl\n/usr/local/lib/python3.12/dist-packages/torch/jit/_trace.py(129): wrapper\n/usr/local/lib/python3.12/dist-packages/torch/jit/_trace.py(138): forward\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1751): _call_impl\n/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py(1740): _wrapped_call_impl\n/usr/local/lib/python3.12/dist-packages/torch/jit/_trace.py(1498): _get_trace_graph\n/usr/local/lib/python3.12/dist-packages/torch/onnx/utils.py(844): _trace_and_get_graph_from_model\n/usr/local/lib/python3.12/dist-packages/torch/onnx/utils.py(937): _create_jit_graph\n/usr/local/lib/python3.12/dist-packages/torch/onnx/utils.py(1053): _model_to_graph\n/usr/local/lib/python3.12/dist-packages/torch/onnx/utils.py(1428): _export\n/usr/local/lib/python3.12/dist-packages/torch/onnx/utils.py(495): export\n/usr/local/lib/python3.12/dist-packages/torch/onnx/__init__.py(383): export\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/scripts/export.py(196): stereo_onnx_export\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/scripts/export.py(326): run_export\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/scripts/export.py(62): main\n/tao-pt/nvidia_tao_pytorch/core/decorators/workflow.py(51): _func\n/usr/local/lib/python3.12/dist-packages/hydra/core/utils.py(186): run_job\n/usr/local/lib/python3.12/dist-packages/hydra/_internal/hydra.py(119): run\n/usr/local/lib/python3.12/dist-packages/hydra/_internal/utils.py(458): <lambda>\n/usr/local/lib/python3.12/dist-packages/hydra/_internal/utils.py(220): run_and_report\n/usr/local/lib/python3.12/dist-packages/hydra/_internal/utils.py(457): _run_app\n/usr/local/lib/python3.12/dist-packages/hydra/_internal/utils.py(394): _run_hydra\n/tao-pt/nvidia_tao_pytorch/core/hydra/hydra_runner.py(110): wrapper\n/tao-pt/nvidia_tao_pytorch/cv/depth_net/scripts/export.py(337): <module>\n"
domain: ""
2026-03-03 10:46:27,916 ERROR *** ERROR-OCCUR-DURING hbdk.export ***, error message:
hb_compile.log 内容如下:
2026-03-03 10:28:59,236 file: tool_utils.py func: tool_utils line No: 80 The log will be stored in /Data/Work/S100FS00/hb_compile.log
2026-03-03 10:28:59,237 file: hb_compile.py func: hb_compile line No: 280 Start hb_compile...
2026-03-03 10:28:59,238 file: hb_compile.py func: hb_compile line No: 281 hbdk version: 4.2.11
2026-03-03 10:28:59,238 file: hb_compile.py func: hb_compile line No: 282 hmct version: 2.4.1
2026-03-03 10:28:59,239 file: hb_compile.py func: hb_compile line No: 283 hb_compile version: 3.3.22
2026-03-03 10:28:59,240 file: hb_compile.py func: hb_compile line No: 33 Start verifying yaml
2026-03-03 10:28:59,247 file: params_parser.py func: params_parser line No: 1142 Using abs path /Data/Work/S100FS00/FSV2320.onnx
2026-03-03 10:29:01,041 file: params_parser.py func: params_parser line No: 177 Using the onnx model file: /Data/Work/S100FS00/FSV2320.onnx
2026-03-03 10:29:01,042 file: onnx_parser.py func: onnx_parser line No: 39 Model input names: ['left_image', 'right_image']
2026-03-03 10:29:01,043 file: params_parser.py func: params_parser line No: 188 Model has 2 inputs according to model file
2026-03-03 10:29:01,045 file: params_parser.py func: params_parser line No: 1142 Using abs path /Data/Work/S100FS00/model_output
2026-03-03 10:29:01,045 file: params_parser.py func: params_parser line No: 370 node_dict: {}
2026-03-03 10:29:01,046 file: params_parser.py func: params_parser line No: 647 Please note that the parameter norm_type has been deprecated and will be determined by the specification of the mean/scale/std parameters
2026-03-03 10:29:01,047 file: params_parser.py func: params_parser line No: 784 The calibration dataset has not been specified, the calibration method is modified to skip
2026-03-03 10:29:01,048 file: params_parser.py func: params_parser line No: 916 The input node left_image's input_source is not be specified, it will be specified as None by default
2026-03-03 10:29:01,048 file: params_parser.py func: params_parser line No: 916 The input node right_image's input_source is not be specified, it will be specified as None by default
2026-03-03 10:29:01,050 file: params_parser.py func: params_parser line No: 981 The parameter compile_mode is specified as latency, the balance_factor will be specified as 100.
2026-03-03 10:29:01,050 file: hb_compile.py func: hb_compile line No: 36 End verifying yaml
2026-03-03 10:29:01,051 file: wrap_utils.py func: wrap_utils line No: 40 Start to execute hmct.custom.op_registration.op_register.
2026-03-03 10:29:01,051 file: wrap_utils.py func: wrap_utils line No: 43 hmct.custom.op_registration.op_register input args ()
2026-03-03 10:29:01,052 file: wrap_utils.py func: wrap_utils line No: 46 hmct.custom.op_registration.op_register input kwargs {}
2026-03-03 10:29:01,052 file: wrap_utils.py func: wrap_utils line No: 50 End to execute hmct.custom.op_registration.op_register.
2026-03-03 10:29:01,053 file: wrap_utils.py func: wrap_utils line No: 40 Start to execute hmct.api.build_model.
2026-03-03 10:29:01,053 file: wrap_utils.py func: wrap_utils line No: 43 hmct.api.build_model input args ()
2026-03-03 10:29:01,053 file: wrap_utils.py func: wrap_utils line No: 46 hmct.api.build_model input kwargs {'params': {'cali_dict': {'calibration_type': ''}, 'input_dict': {'left_image': {'input_shape': [1, 3, 320, 736]}, 'right_image': {'input_shape': [1, 3, 320, 736]}}, 'node_dict': {}, 'debug_methods': [], 'output_nodes': [], 'optimization_methods': None, 'quant_config': {}, 'check_mode': True}}
2026-03-03 10:29:01,054 file: model_builder.py func: model_builder line No: 36 Start to Horizon NN Model Convert.
2026-03-03 10:29:08,567 file: model_debugger.py func: model_debugger line No: 67 Loading horizon_nn debug methods: set().
2026-03-03 10:29:08,572 file: model_builder.py func: model_builder line No: 230 The specified model compilation architecture: nash-e.
2026-03-03 10:29:08,574 file: model_builder.py func: model_builder line No: 244 The specified model compilation optimization parameters: [].
2026-03-03 10:29:08,575 file: model_builder.py func: model_builder line No: 36 Start to prepare the onnx model.
2026-03-03 10:29:11,874 file: display_model.py func: display_model line No: 69 Input ONNX Model Information:
IR Version: 8
Opset Version: ['ai.onnx v17', 'horizon v1']
Model Producer: pytorch v2.6.0
Model Domain: None
Model Version: None
Graph Input:
left_image : shape=[1, 3, 320, 736], dtype=FLOAT32
...t_image : shape=[1, 3, 320, 736], dtype=FLOAT32
Graph Output:
disparity : shape=[1, 1, 320, 736], dtype=FLOAT32
2026-03-03 10:29:11,885 file: preprocess_model.py func: preprocess_model line No: 380 The input model's opset version is 17, try to convert to opset version of 19.
2026-03-03 10:29:28,311 file: model_builder.py func: model_builder line No: 39 End to prepare the onnx model.
2026-03-03 10:29:31,251 file: model_builder.py func: model_builder line No: 287 Saving model to: /Data/Work/S100FS00/model_output/FSV2320_original_float_model.onnx.
2026-03-03 10:29:31,252 file: model_builder.py func: model_builder line No: 36 Start to optimize the onnx model.
2026-03-03 10:33:55,439 file: constant_folding.py func: constant_folding line No: 71 Summary info for constant folding:
2026-03-03 10:33:55,440 file: constant_folding.py func: constant_folding line No: 72 After constant folding, the number of nodes has changed from 34003 to 9511.
2026-03-03 10:33:55,441 file: constant_folding.py func: constant_folding line No: 76 After constant_folding, the number of parameters has changed from 122435652 to 331860857.
2026-03-03 10:33:55,442 file: constant_folding.py func: constant_folding line No: 81 Detailed info for constant folding:
2026-03-03 10:33:55,443 file: constant_folding.py func: constant_folding line No: 88
2026-03-03 10:34:03,444 file: constant_folding.py func: constant_folding line No: 71 Summary info for constant folding:
2026-03-03 10:34:03,445 file: constant_folding.py func: constant_folding line No: 72 After constant folding, the number of nodes has changed from 9413 to 9413.
2026-03-03 10:34:03,446 file: constant_folding.py func: constant_folding line No: 76 After constant_folding, the number of parameters has changed from 331892593 to 331892593.
2026-03-03 10:34:03,447 file: constant_folding.py func: constant_folding line No: 81 Detailed info for constant folding:
2026-03-03 10:34:03,447 file: constant_folding.py func: constant_folding line No: 88
2026-03-03 10:34:09,331 file: constant_folding.py func: constant_folding line No: 71 Summary info for constant folding:
2026-03-03 10:34:09,332 file: constant_folding.py func: constant_folding line No: 72 After constant folding, the number of nodes has changed from 8888 to 8888.
2026-03-03 10:34:09,333 file: constant_folding.py func: constant_folding line No: 76 After constant_folding, the number of parameters has changed from 331893210 to 331893210.
2026-03-03 10:34:09,333 file: constant_folding.py func: constant_folding line No: 81 Detailed info for constant folding:
2026-03-03 10:34:09,333 file: constant_folding.py func: constant_folding line No: 88
2026-03-03 10:34:15,159 file: constant_folding.py func: constant_folding line No: 71 Summary info for constant folding:
2026-03-03 10:34:15,161 file: constant_folding.py func: constant_folding line No: 72 After constant folding, the number of nodes has changed from 8532 to 8532.
2026-03-03 10:34:15,162 file: constant_folding.py func: constant_folding line No: 76 After constant_folding, the number of parameters has changed from 331884282 to 331884282.
2026-03-03 10:34:15,162 file: constant_folding.py func: constant_folding line No: 81 Detailed info for constant folding:
2026-03-03 10:34:15,163 file: constant_folding.py func: constant_folding line No: 88
2026-03-03 10:34:22,744 file: constant_folding.py func: constant_folding line No: 71 Summary info for constant folding:
2026-03-03 10:34:22,746 file: constant_folding.py func: constant_folding line No: 72 After constant folding, the number of nodes has changed from 8481 to 8481.
2026-03-03 10:34:22,747 file: constant_folding.py func: constant_folding line No: 76 After constant_folding, the number of parameters has changed from 331874498 to 331874498.
2026-03-03 10:34:22,748 file: constant_folding.py func: constant_folding line No: 81 Detailed info for constant folding:
2026-03-03 10:34:22,748 file: constant_folding.py func: constant_folding line No: 88
2026-03-03 10:34:40,802 file: model_builder.py func: model_builder line No: 39 End to optimize the onnx model.
2026-03-03 10:34:55,048 file: model_builder.py func: model_builder line No: 287 Saving model to: /Data/Work/S100FS00/model_output/FSV2320_optimized_float_model.onnx.
2026-03-03 10:34:55,051 file: quant_config.py func: quant_config line No: 295 The activation calibration configuration:
calibration_type: fixed
2026-03-03 10:34:55,052 file: model_builder.py func: model_builder line No: 36 Start to calibrate the model.
2026-03-03 10:34:55,845 file: dataset.py func: dataset line No: 128 input name: left_image, number_of_samples: 1
2026-03-03 10:34:55,847 file: dataset.py func: dataset line No: 128 input name: right_image, number_of_samples: 1
2026-03-03 10:34:55,848 file: calibrate.py func: calibrate line No: 38 No calibration data provided, using random data.
2026-03-03 10:40:18,030 file: fixed_calibrater.py func: fixed_calibrater line No: 33 Run calibration model with fixed thresholds method.
2026-03-03 10:43:07,417 file: model_builder.py func: model_builder line No: 39 End to calibrate the model.
2026-03-03 10:43:21,592 file: model_builder.py func: model_builder line No: 287 Saving model to: /Data/Work/S100FS00/model_output/FSV2320_calibrated_model.onnx.
2026-03-03 10:43:21,594 file: model_builder.py func: model_builder line No: 36 Start to quantize the model.
2026-03-03 10:46:05,174 file: model_builder.py func: model_builder line No: 39 End to quantize the model.
2026-03-03 10:46:18,368 file: model_builder.py func: model_builder line No: 287 Saving model to: /Data/Work/S100FS00/model_output/FSV2320_ptq_model.onnx.
2026-03-03 10:46:20,479 file: model_builder.py func: model_builder line No: 39 End to Horizon NN Model Convert.
2026-03-03 10:46:20,487 file: wrap_utils.py func: wrap_utils line No: 50 End to execute hmct.api.build_model.
2026-03-03 10:46:20,488 file: hbm_builder.py func: hbm_builder line No: 275 Start to export model.
2026-03-03 10:46:20,489 file: wrap_utils.py func: wrap_utils line No: 40 Start to execute hbdk.export.
2026-03-03 10:46:20,489 file: wrap_utils.py func: wrap_utils line No: 43 hbdk.export input args ()
2026-03-03 10:46:20,490 file: wrap_utils.py func: wrap_utils line No: 46 hbdk.export input kwargs {'output_prefix_name': 'FSV2320'}
2026-03-03 10:46:27,912 file: tool_utils.py func: tool_utils line No: 138 Exception in command: main
2026-03-03 10:46:27,915 file: tool_utils.py func: tool_utils line No: 139 Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/utils/wrap_utils.py", line 49, in wrapper
result = func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/hbir_handle.py", line 57, in export_hbir
return export(proto=ptq_model, name=output_prefix_name)
File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/onnx/__init__.py", line 42, in export
graph.emit_mlir_func_op(OpConvertorRegistry(), True)
File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/frontend/adaptor.py", line 358, in emit_mlir_func_op
node_adaptor.emit_mlir_op(registry)
File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/frontend/adaptor.py", line 210, in emit_mlir_op
raise e
File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/frontend/adaptor.py", line 195, in emit_mlir_op
results = cvt.emit_mlir_op(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/onnx/opset18.py", line 200, in emit_mlir_op
assert len(input_shape) == 4
AssertionError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/utils/tool_utils.py", line 136, in __decorator
func(*args, **kargs)
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/hb_compile.py", line 300, in main
onnx_config_mode(config, skip=skip)
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/hb_compile.py", line 214, in onnx_config_mode
hbm_build(conf, ptq_model, skip=skip)
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/hb_compile.py", line 125, in hbm_build
hbm_builder.build()
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/compile/hbm_builder.py", line 332, in build
self.export_model()
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/compile/hbm_builder.py", line 276, in export_model
self.float_hbir = HBIRHandle.export_hbir(
File "/usr/local/lib/python3.10/dist-packages/horizon_tc_ui/utils/wrap_utils.py", line 54, in wrapper
raise ValueError(f"*** ERROR-OCCUR-DURING {module_info} ***," +
ValueError: *** ERROR-OCCUR-DURING hbdk.export ***, error message:
2026-03-03 10:46:27,916 file: tool_utils.py func: tool_utils line No: 140 *** ERROR-OCCUR-DURING hbdk.export ***, error message:
OE3.2是在工具链Docker镜像ai_toolchain_ubuntu_22_s100_cpu_v3.2.0中运行的
FSV2320.onnx对应了 Nvidia模型发布页面的deployable_foundationstereo_small_320x736_v2.0.onnx
