使用hobot_dnn 工具对量化后的模型执行推理,得到的结果和在电脑上运行的效果差距很大

你好请问一下,我在RDK X5板卡上按照教程,将ONNX转换为bin文件,并编写py代码,调用hobot_dnn执行forward,我做的是低光增强,执行后的效果出现明显过曝现象,并且指标比电脑跑的低了很多,请问应该是哪个地方出了问题,下面是我的量化配置文件、模型转换log以及py推理脚本:


Copyright (c) 2020 D-Robotics.All Rights Reserved.

模型转化相关的参数

model_parameters:

必选参数

onnx_model: ‘model_sdsdin_960_540.onnx’

必选参数:

Caffe网络描述文件, 例如:prototxt: ‘./horizon_x3_caffe.prototxt’

#prototxt: ‘’
march: “bayes-e”
layer_out_dump: True
working_dir: ‘dzh_model_sdsdin_960_540_output’
output_model_file_prefix: ‘dzh_model_enhance_sdsdin_960_540’
#node_info: {

“/Div_1/Div”: {‘ON’: ‘BPU’,‘InputType’: ‘int16’,‘OutputType’: ‘int16’}

#}

模型输入相关参数

input_parameters:

input_name: “”
input_shape: ‘1x3x960x540’
input_type_rt: ‘nv12’
input_layout_rt: ‘’

input_type_train: ‘bgr’

input_type_train: ‘rgb’

input_layout_train: ‘NCHW’

input_batch: 1

norm_type: ‘data_scale’

scale_value: 0.003921568627451

模型量化相关参数

calibration_parameters:

cal_data_dir: ‘sdsin_train’

cal_data_type: ‘float32’
calibration_type: ‘default’
preprocess_on: True

compiler_parameters:

compile_mode: ‘latency’
debug: False
core_num: 1
optimize_level: ‘O3’
root@169a2d55a12c:/open_explorer# hb_mapper makertbin --model-type onnx --config ./Model/dzh/dzh_config.yaml
2026-03-17 19:49:05,200 INFO log will be stored in /open_explorer/hb_mapper_makertbin.log
2026-03-17 19:49:05,201 INFO Start hb_mapper....
2026-03-17 19:49:05,201 INFO hbdk version 3.49.15
2026-03-17 19:49:05,201 INFO horizon_nn version 1.1.0
2026-03-17 19:49:05,201 INFO hb_mapper version 1.24.3
2026-03-17 19:49:05,201 INFO Start Model Convert....
2026-03-17 19:49:05,206 INFO Using onnx model file: /open_explorer/Model/dzh/model_sdsdin_960_540.onnx
2026-03-17 19:49:05,221 INFO Model has 1 inputs according to model file
2026-03-17 19:49:05,221 INFO Model name not given in yaml_file, using model name from model file: ['input']
2026-03-17 19:49:05,221 INFO nv12 input type rt received.
2026-03-17 19:49:05,222 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-03-17 19:49:05,222 INFO custom_op does not exist, skipped
2026-03-17 19:49:05,222 WARNING Input node input's input_source not set, it will be set to pyramid by default
2026-03-17 19:49:05,222 WARNING User input 'preprocess_on' will be deprecated. If you want to simplify the calibration process, please use 'skip' in  'calibration_type'
2026-03-17 19:49:05,236 INFO *******************************************
2026-03-17 19:49:05,236 INFO First calibration picture name: 0091x1.png
2026-03-17 19:49:05,236 INFO First calibration picture md5:
344585aef5c2e5c72b33196836403a34  /open_explorer/Model/dzh/sdsin_train/0091x1.png
2026-03-17 19:49:05,462 INFO *******************************************
2026-03-17 19:49:15,127 INFO Start to Horizon NN Model Convert.
2026-03-17 19:49:15,130 INFO Loading horizon_nn debug methods:{'dump_all_models', 'dump_all_layers_output', 'check_model_output_consistency'}
2026-03-17 19:49:15,130 INFO The activation calibration parameters:
    calibration_type:     ['max', 'kl']
    max_percentile:       [0.99995, 1.0]
    per_channel:          [True, False]
    asymmetric:           [True, False]
The modelwise search parameters:
    similarity:           0.995
    metric:               cosine-similarity
2026-03-17 19:49:15,131 INFO input input is from pyramid. Its layout is set to NHWC
2026-03-17 19:49:15,131 INFO The specified model compilation architecture: bayes-e.
2026-03-17 19:49:15,131 INFO The specified model compilation optimization parameters: [].
2026-03-17 19:49:15,146 INFO Start to prepare the onnx model.
2026-03-17 19:49:15,149 INFO Input ONNX Model Information:
ONNX IR version:          6
Opset version:            ['ai.onnx v11', 'horizon v1']
Producer:                 pytorch v2.1.1
Domain:                   None
Version:                  None
Graph input:
    input:                shape=[1, 3, 960, 540], dtype=FLOAT32
Graph output:
    output:               shape=[1, 3, 960, 540], dtype=FLOAT32
    83:                   shape=[1, 18, 960, 540], dtype=FLOAT32
2026-03-17 19:49:15,238 INFO End to prepare the onnx model.
2026-03-17 19:49:15,258 INFO Saving model to: dzh_model_enhance_sdsdin_960_540_original_float_model.onnx.
2026-03-17 19:49:15,259 INFO Start to optimize the onnx model.
2026-03-17 19:49:15,345 INFO End to optimize the onnx model.
2026-03-17 19:49:15,348 INFO Saving model to: dzh_model_enhance_sdsdin_960_540_optimized_float_model.onnx.
2026-03-17 19:49:15,348 INFO Start to calibrate the model.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-17 19:49:17,084 INFO There are 50 samples in the data set.
2026-03-17 19:49:17,084 INFO Run calibration model with modelwise search method.
2026-03-17 19:49:17,100 WARNING The input0 of Node(name:/ReduceMin_1, type:ReduceMin) does not support data type: int16
2026-03-17 19:49:17,127 WARNING The input0 of Node(name:/ReduceMin_1, type:ReduceMin) does not support data type: int8
2026-03-17 19:49:17,134 INFO Calibration using batch 8
calibration in progress: 100%|████████████████████████████████████████████████| 7/7 [01:38<00:00, 14.11s/it]
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-17 19:51:33,278 INFO Select max method.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-17 19:51:33,493 INFO End to calibrate the model.
2026-03-17 19:51:33,541 INFO Saving model to: dzh_model_enhance_sdsdin_960_540_calibrated_model.onnx.
2026-03-17 19:51:33,542 INFO Start to quantize the model.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-17 19:51:33,748 INFO End to quantize the model.
2026-03-17 19:51:33,782 INFO Saving model to: dzh_model_enhance_sdsdin_960_540_quantized_model.onnx.
2026-03-17 19:51:33,782 INFO Start to compile the model with march bayes-e.
2026-03-17 19:51:33,958 INFO Compile submodel: main_graph_subgraph_0
2026-03-17 19:51:34,303 INFO hbdk-cc parameters:['--O3', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'pyramid']
[==================================================] 100%
2026-03-17 19:51:36,040 INFO consumed time 0.230362
2026-03-17 19:51:36,071 INFO hbir_model has been saved as : main_graph_subgraph_0.hbir
2026-03-17 19:51:36,205 INFO FPS=980.95, latency = 1019.4 us, DDR = 7050432 bytes   (see main_graph_subgraph_0.html)
2026-03-17 19:51:36,206 INFO Compile submodel: main_graph_subgraph_1
2026-03-17 19:51:36,323 INFO hbdk-cc parameters:['--O3', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'ddr']
2026-03-17 19:59:56,871 INFO consumed time 500.528
2026-03-17 19:59:56,893 INFO hbir_model has been saved as : main_graph_subgraph_1.hbir
2026-03-17 19:59:57,070 INFO FPS=20.49, latency = 48805.9 us, DDR = 323527200 bytes   (see main_graph_subgraph_1.html)
2026-03-17 19:59:57,113 INFO Compile submodel: main_graph_subgraph_2
2026-03-17 19:59:57,114 INFO hbdk-cc parameters:['--O3', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'ddr']
2026-03-17 19:59:57,605 INFO consumed time 0.469184
2026-03-17 19:59:57,613 INFO hbir_model has been saved as : main_graph_subgraph_2.hbir
2026-03-17 19:59:57,659 INFO FPS=867.65, latency = 1152.5 us, DDR = 7833792 bytes   (see main_graph_subgraph_2.html)
2026-03-17 20:00:09,797 INFO core[0] open!
2026-03-17 20:00:43,386 INFO The consistency check between the quantized model and the hybrid model is passed.
2026-03-17 20:00:43,443 INFO End to compile the model with march bayes-e.
2026-03-17 20:00:43,447 INFO Saving model to: dzh_model_enhance_sdsdin_960_540_hybrid_model.onnx.
2026-03-17 20:00:56,366 INFO The main quantized node information:
=================================================================================================================================
Node                                              ON   Subgraph  Type                    Cosine Similarity  Threshold  DataType
---------------------------------------------------------------------------------------------------------------------------------
HZ_PREPROCESS_FOR_input                           BPU  id(0)     HzSQuantizedPreprocess  1.000008           127.0      int8
/ReduceMin                                        CPU  --        ReduceMin               --                 --         float
/Sub                                              CPU  --        Sub                     0.999936           --         float
/ReduceMax                                        CPU  --        ReduceMax               --                 --         float
/Sub_1                                            CPU  --        Sub                     --                 --         float
/Div                                              CPU  --        Div                     0.999958           --         float
/e_conv1/Conv                                     BPU  id(1)     HzSQuantizedConv        0.999978           1.0        int8
/relu/LeakyRelu                                   BPU  id(1)     HzLut                   1.000161           0.941067   int8
/e_conv2/Conv                                     BPU  id(1)     HzSQuantizedConv        1.000176           0.941067   int8
/relu_1/LeakyRelu                                 BPU  id(1)     HzLut                   1.000404           0.738363   int8
/e_conv3/Conv                                     BPU  id(1)     HzSQuantizedConv        0.999784           0.738363   int8
/relu_2/LeakyRelu                                 BPU  id(1)     HzLut                   0.999837           0.713695   int8
/e_conv4/Conv                                     BPU  id(1)     HzSQuantizedConv        0.999995           0.713695   int8
/relu_3/LeakyRelu                                 BPU  id(1)     HzLut                   1.000188           1.49487    int8
/relu_2/LeakyRelu_output_0_calibrated_Requantize  BPU  id(1)     HzRequantize            --                 --         int8
/Concat                                           BPU  id(1)     Concat                  1.000012           0.713695   int8
/e_conv5/Conv                                     BPU  id(1)     HzSQuantizedConv        0.999674           1.49487    int8
/relu_4/LeakyRelu                                 BPU  id(1)     HzLut                   0.999913           1.91934    int8
/relu_1/LeakyRelu_output_0_calibrated_Requantize  BPU  id(1)     HzRequantize            --                 --         int8
/Concat_1                                         BPU  id(1)     Concat                  0.999827           0.738363   int8
/e_conv6/Conv                                     BPU  id(1)     HzSQuantizedConv        0.999560           1.91934    int8
/relu_5/LeakyRelu                                 BPU  id(1)     HzLut                   0.999686           1.65678    int8
/relu/LeakyRelu_output_0_calibrated_Requantize    BPU  id(1)     HzRequantize            --                 --         int8
/Concat_2                                         BPU  id(1)     Concat                  0.999780           0.941067   int8
/e_conv7/Conv                                     BPU  id(1)     HzSQuantizedConv        1.000018           1.65678    int8
/Tanh                                             BPU  id(1)     HzLut                   1.000046           2.35818    int8
/Split                                            BPU  id(1)     Split                   1.000010           0.982263   int8
/Pow                                              BPU  id(1)     HzLut                   0.999504           1.0        int8
/Sub_2                                            BPU  id(1)     HzSElementwiseSub       0.999864           1.0        int8
/Mul                                              BPU  id(1)     HzSElementwiseMul       0.999697           0.982263   int8
/Add                                              BPU  id(1)     HzSElementwiseAdd       0.999962           1.0        int8
/Pow_1                                            BPU  id(1)     HzLut                   0.999504           1.0        int8
/Sub_3                                            BPU  id(1)     HzSElementwiseSub       0.999881           1.0        int8
/Mul_1                                            BPU  id(1)     HzSElementwiseMul       0.999711           0.982263   int8
/Add_1                                            BPU  id(1)     HzSElementwiseAdd       0.999822           1.0        int8
/Pow_2                                            BPU  id(1)     HzLut                   0.999848           1.0        int8
/Sub_4                                            BPU  id(1)     HzSElementwiseSub       0.999458           1.0        int8
/Mul_2                                            BPU  id(1)     HzSElementwiseMul       0.999246           0.982263   int8
/Add_2                                            BPU  id(1)     HzSElementwiseAdd       0.999777           1.0        int8
/Pow_3                                            BPU  id(1)     HzLut                   0.999779           1.0        int8
/Sub_5                                            BPU  id(1)     HzSElementwiseSub       0.999172           1.0        int8
/Mul_3                                            BPU  id(1)     HzSElementwiseMul       0.999050           0.982263   int8
/Add_3                                            BPU  id(1)     HzSElementwiseAdd       0.999638           1.0        int8
/Pow_4                                            BPU  id(1)     HzLut                   0.999706           1.0        int8
/Pow_5                                            BPU  id(1)     HzLut                   0.999646           1.0        int8
/Sub_6                                            BPU  id(1)     HzSElementwiseSub       0.997420           1.0        int8
/Mul_4                                            BPU  id(1)     HzSElementwiseMul       0.997453           0.982263   int8
/Add_4                                            BPU  id(1)     HzSElementwiseAdd       0.999724           1.0        int8
/Pow_6                                            BPU  id(1)     HzLut                   0.999646           1.0        int8
/Pow_7                                            BPU  id(1)     HzLut                   0.999569           1.0        int8
/Sub_7                                            BPU  id(1)     HzSElementwiseSub       0.998106           1.0        int8
/Mul_5                                            BPU  id(1)     HzSElementwiseMul       0.998104           0.982263   int8
/Add_5                                            BPU  id(1)     HzSElementwiseAdd       0.999695           1.0        int8
/Concat_3                                         BPU  id(1)     Concat                  1.000046           0.982263   int8
/ReduceMin_1                                      CPU  --        ReduceMin               --                 1.0        float
/Sub_8                                            CPU  --        Sub                     0.999667           1.0        float
/Mul_6                                            BPU  id(2)     HzSQuantizedConv        0.999732           1.0        int8
/ReduceMax_1                                      CPU  --        ReduceMax               --                 1.0        float
/Sub_9                                            CPU  --        Sub                     --                 1.0        float
/Div_1                                            CPU  --        Div                     0.999732           --         float
2026-03-17 20:00:56,367 INFO The quantized model output:
====================================================================================================
Output                             Cosine Similarity  L1 Distance  L2 Distance  Chebyshev Distance
----------------------------------------------------------------------------------------------------
output                             0.999732           3.052497     0.003180     15.175667
83                                 1.000046           0.003692     0.000002     0.020938
/e_conv5/Conv_output_0_calibrated  0.999674           0.006633     0.000003     0.185087
/Mul_6_output_0                    0.999732           3.052497     0.003180     15.175667
/e_conv7/Conv_output_0_calibrated  1.000018           0.007344     0.000003     0.048771
/e_conv4/Conv_output_0_calibrated  0.999995           0.004082     0.000002     0.034099
/e_conv2/Conv_output_0_calibrated  1.000176           0.002122     0.000001     0.017915
/e_conv6/Conv_output_0_calibrated  0.999560           0.006584     0.000004     0.509599
/e_conv3/Conv_output_0_calibrated  0.999784           0.002667     0.000001     0.034106
/e_conv1/Conv_output_0_calibrated  0.999978           0.002275     0.000001     0.187827
2026-03-17 20:00:56,407 INFO End to Horizon NN Model Convert.
2026-03-17 20:00:56,420 INFO start convert to *.bin file....
2026-03-17 20:00:56,449 INFO ONNX model output num : 10
2026-03-17 20:00:56,470 INFO ############# model deps info #############
2026-03-17 20:00:56,470 INFO hb_mapper version   : 1.24.3
2026-03-17 20:00:56,470 INFO hbdk version        : 3.49.15
2026-03-17 20:00:56,470 INFO hbdk runtime version: 3.15.55.0
2026-03-17 20:00:56,470 INFO horizon_nn version  : 1.1.0
2026-03-17 20:00:56,470 INFO ############# model_parameters info #############
2026-03-17 20:00:56,471 INFO onnx_model          : /open_explorer/Model/dzh/model_sdsdin_960_540.onnx
2026-03-17 20:00:56,471 INFO BPU march           : bayes-e
2026-03-17 20:00:56,471 INFO layer_out_dump      : True
2026-03-17 20:00:56,471 INFO log_level           : DEBUG
2026-03-17 20:00:56,471 INFO working dir         : /open_explorer/Model/dzh/dzh_model_sdsdin_960_540_output
2026-03-17 20:00:56,471 INFO output_model_file_prefix: dzh_model_enhance_sdsdin_960_540
2026-03-17 20:00:56,472 INFO ############# input_parameters info #############
2026-03-17 20:00:56,472 INFO ------------------------------------------
2026-03-17 20:00:56,473 INFO ---------input info : input ---------
2026-03-17 20:00:56,473 INFO input_name          : input
2026-03-17 20:00:56,473 INFO input_type_rt       : nv12
2026-03-17 20:00:56,473 INFO input_space&range   : regular
2026-03-17 20:00:56,473 INFO input_layout_rt     : None
2026-03-17 20:00:56,473 INFO input_type_train    : rgb
2026-03-17 20:00:56,473 INFO input_layout_train  : NCHW
2026-03-17 20:00:56,473 INFO norm_type           : data_scale
2026-03-17 20:00:56,473 INFO input_shape         : 1x3x960x540
2026-03-17 20:00:56,473 INFO scale_value         : 0.003921568627451,
2026-03-17 20:00:56,473 INFO cal_data_dir        : /open_explorer/Model/dzh/sdsin_train
2026-03-17 20:00:56,473 INFO cal_data_type       : float32
2026-03-17 20:00:56,473 INFO ---------input info : input end -------
2026-03-17 20:00:56,474 INFO ------------------------------------------
2026-03-17 20:00:56,474 INFO ############# calibration_parameters info #############
2026-03-17 20:00:56,474 INFO preprocess_on       : True
2026-03-17 20:00:56,474 INFO calibration_type:   : default
2026-03-17 20:00:56,474 INFO per_channel         : False
2026-03-17 20:00:56,474 INFO ############# compiler_parameters info #############
2026-03-17 20:00:56,474 INFO debug               : False
2026-03-17 20:00:56,474 INFO compile_mode        : latency
2026-03-17 20:00:56,474 INFO hbdk_pass_through_params: --O3 --core-num 1 --fast
2026-03-17 20:00:56,474 INFO input-source        : {'input': 'pyramid', '_default_value': 'ddr'}
2026-03-17 20:00:56,478 INFO Convert to runtime bin file successfully!
2026-03-17 20:00:56,478 INFO End Model Convert
### **推理脚本**

#!/usr/bin/env python3
import sys
import os
import cv2
import numpy as np
from utils import bgr2nv12_opencv, adjust_contrast, get_image_files, save_modeldata_to_img
try:
from hobot_dnn import pyeasy_dnn as dnn
except ImportError:
from hobot_dnn_rdkx5 import pyeasy_dnn as dnn

#提取模型名后缀
def get_model_suffix(model_path):
model_name = os.path.splitext(os.path.basename(model_path))\[0\]
if model_name.startswith(“dzh_model\_”):
return model_name.replace(“dzh_model\_”, “”, 1)
return model_name

def run_single_image(models, input_width, input_height, img_path, out_path,  enable_postprocess=False):
if not os.path.exists(img_path):
print(f"输入图片不存在: {img_path}“)
return False
img = cv2.imread(img_path, cv2.IMREAD_COLOR)
if img is None:
print(f"无法读取图片: {img_path}”)
return False
orig_h, orig_w = img.shape\[:2\]
print(f"原始输入尺寸: {orig_w} x {orig_h}“)
resized = cv2.resize(img, (input_width, input_height), interpolation=cv2.INTER_AREA)
nv12_data = bgr2nv12_opencv(resized)
if nv12_data is None:
print(“NV12 转换失败”)
return False
try:
outputs = models\[0\].forward(nv12_data)
except Exception as e:
print(f"模型推理失败: {e}”)
return False

if len(outputs) == 0:
    print("模型未返回任何输出")
    return False
if save_modeldata_to_img(outputs, out_path, (orig_w, orig_h), enable_postprocess=enable_postprocess):
    print(f"已保存输出图片到: {out_path}")
    print(f"最终输出尺寸: {orig_w} x {orig_h} (已缩放回原始输入尺寸 ✔️)")
    return True
return False


def main():
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(\_*file*\_)))
img_dir = os.path.join(base_dir, “dataset”, “sdsdin”)
output_dir = os.path.join(base_dir, “outputs/sdsdin_960x540_contrast”)
test_num = 0  # 0表示默认处理全部图片
model_path = os.path.join(base_dir, “bin/dzh_model_enhance_sdsdin_960_540.bin”)
enable_postprocess = False# 是否启用后处理


if not os.path.exists(model_path):
    print(f"模型文件不存在: {model_path}")
    sys.exit(-1)

print(f"正在加载模型: {model_path}")
try:
    models = dnn.load(model_path)
    input_shape = models\[0\].inputs\[0\].properties.shape
    if len(input_shape) == 4:
        input_height, input_width = input_shape\[2\], input_shape\[3\]
    else:
        input_width, input_height = 1080, 1080
    print(f"模型加载成功,输入尺寸: {input_width}x{input_height}")
except Exception as e:
    print(f"模型加载失败: {e}")
    sys.exit(-1)

image_files = get_image_files(img_dir)
if len(image_files) == 0:
    print(f"错误: 文件夹中没有找到图片文件: {img_dir}")
    sys.exit(-1)

if test_num > 0:
    image_files = image_files\[:test_num\]

model_suffix = get_model_suffix(model_path)
os.makedirs(output_dir, exist_ok=True)

print(f"\\n找到 {len(image_files)} 张图片")
success_count = 0
failed_count = 0
for idx, img_path in enumerate(image_files, 1):
    input_base = os.path.splitext(os.path.basename(img_path))\[0\]
    input_ext = os.path.splitext(os.path.basename(img_path))\[1\] or ".png"
    output_path = os.path.join(output_dir, f"{input_base}\_{model_suffix}{input_ext}")
    print(f"\\n\[{idx}/{len(image_files)}\] 处理: {os.path.basename(img_path)}")
    if run_single_image(models=models, input_width=input_width, input_height=input_height, img_path=img_path, out_path=output_path, enable_postprocess=enable_postprocess):
        success_count += 1
    else:
        failed_count += 1
print(f"\\n处理完成!成功: {success_count} 张, 失败: {failed_count} 张")


if \_*name*\_ == “\_*main*\_”:
main()

目前从量化导致的精度下降方面没有很好的问题发现,目前看余弦的相似度比较可观,这块就需要参考算法工具链来进行一些基础的排查了,每一个阶段的ONNX模型分开进行验证

感谢您提供详细的模型转换日志、配置文件和推理脚本!从您的描述来看,问题集中在 RDK X5板卡上使用 hobot_dnn 执行量化后模型推理时,结果出现明显过曝现象,且指标比电脑端运行效果差很多


:magnifying_glass_tilted_left: 问题分析

:white_check_mark: 已确认的正确点:

  • 模型成功从 ONNX 转换为 .bin 文件。
  • 量化过程完成,且通过 cosine similarity 验证了输出一致性(大部分节点相似度 >0.99)。
  • 推理脚本结构合理,调用 hobot_dnn.load()forward() 正常。
  • 输入图像格式处理(BGR → NV12)也已实现。

:warning: 关键疑点:过曝 + 性能/精度下降

虽然量化后的模型在“数值一致性”上表现尚可(余弦相似度高),但实际视觉效果出现过曝,说明:

模型输出值范围与预期不符,或输入预处理/后处理未对齐。

这通常不是量化本身的问题,而是:

1. :camera: 输入图像预处理不一致

您在配置中指定了:

input_type_rt: 'nv12'
input_layout_rt: ''
input_type_train: 'rgb'
input_layout_train: 'NCHW'
norm_type: 'data_scale'
scale_value: 0.003921568627451

但在推理脚本中,您是这样处理的:

resized = cv2.resize(img, (input_width, input_height), interpolation=cv2.INTER_AREA)
nv12_data = bgr2nv12_opencv(resized)

:warning: 问题可能出在这里:

  • cv2.imread(...) 默认读取的是 BGR 格式,没问题。
  • bgr2nv12_opencv 函数是否做了正确的归一化?比如是否将 [0,255] 映射到 [0,1][0,255]
  • 更重要的是:您在配置文件里用了 scale_value: 0.003921568627451(即 1/255),但在推理脚本中没有显式做除法缩放!

:backhand_index_pointing_right: 这会导致模型接收到的输入值远大于预期(例如 255 → 1.0,而模型期望的是 0~1 的 float32),从而导致激活值爆炸 → 输出过曝!


2. :framed_picture: 后处理缺失或错误

您的脚本中设置了:

enable_postprocess=False

但模型是用于低光增强的,很可能需要后处理(如 clip 到 [0,1]、反归一化、gamma 调整等)才能得到合理图像。

即使模型输出是浮点数,如果直接保存为 uint8 图像而不做任何限制,也会因为超出范围(>255)被截断成白色 → 过曝。

:white_check_mark: 建议在 save_modeldata_to_img 函数中加入:

# 限制输出范围
output_clipped = np.clip(output, 0.0, 1.0)  # 如果模型输出是 [0,1]
output_uint8 = (output_clipped * 255).astype(np.uint8)

或者如果是原始 float32 数据,需先进行:

output_normalized = (output - output.min()) / (output.max() - output.min() + 1e-8)
output_uint8 = (output_normalized * 255).astype(np.uint8)

3. :test_tube: ONNX 模型内部结构异常(潜在风险)

从 log 中可以看到:

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

这些警告虽然不影响最终编译,但可能暗示某些层在转换过程中丢失了维度信息,尤其是涉及 Sub, Div, ReduceMin 等操作——这些在低光增强任务中很常见(比如亮度减去均值、对比度调整等)。

建议:

  • 在转换前,用 onnxruntime 加载模型,手动检查每一层的输入输出形状;
  • 使用 netron 可视化模型结构,确认是否有意外的 reshape 或 broadcast 导致数据错位。

4. :brain: 模型训练 vs 推理环境差异

您提到“电脑上跑的效果好”,这可能是由于:

  • 训练时使用的数据预处理方式不同(比如 RGB 归一化方式、裁剪策略、增强类型);
  • 推理时未使用相同的 mean/std normalization;
  • 板卡上的硬件加速器(BPU)对某些算子支持有限,导致近似误差累积。

:white_check_mark: 解决方案建议

:check_mark: 第一步:修复输入预处理

修改推理脚本中的图像预处理部分,在 bgr2nv12_opencv 之后添加归一化:

# 在 resize 和 nv12 转换后,确保输入是 [0,1] 浮点数
img_float = resized.astype(np.float32) / 255.0  # 归一化到 [0,1]
nv12_data = bgr2nv12_opencv(img_float)  # 注意这个函数要支持 float 输入!

:warning: 如果 bgr2nv12_opencv 只接受 uint8,请先做:

img_uint8 = (img_float * 255).astype(np.uint8)
nv12_data = bgr2nv12_opencv(img_uint8)

然后在 forward 之前,再做一次 scale:

# 假设模型期望输入是 [0,1],则无需额外 scale
# 若模型期望是 [-1,1] 或其他,请根据 config 调整

:check_mark: 第二步:启用后处理并限制输出范围

save_modeldata_to_img 函数中增加:

def save_modeldata_to_img(outputs, out_path, orig_size, enable_postprocess=False):
    output = outputs[0].reshape(*orig_size[::-1], 3)  # 假设输出是 HxWx3
    if enable_postprocess:
        # 低光增强常用 post-process:clip + gamma
        output = np.clip(output, 0.0, 1.0)
        gamma = 0.8  # 示例参数,可根据需求调整
        output = np.power(output, gamma)
    else:
        # 直接 clip 到 [0,1] 防止溢出
        output = np.clip(output, 0.0, 1.0)

    output_uint8 = (output * 255).astype(np.uint8)
    cv2.imwrite(out_path, output_uint8)
    return True

:check_mark: 第三步:逐级验证模型行为

  1. 单独测试 ONNX 模型(在 PC 上用 onnxruntime):

    import onnxruntime as ort
    sess = ort.InferenceSession(model_path_onnx)
    input_name = sess.get_inputs()[0].name
    pred = sess.run(None, {input_name: input_data.astype(np.float32)})
    
  2. 比较 ONNX 输出与 hobot_dnn 输出

    • 将同一张图分别喂给 ONNX 和 hobot_dnn;
    • 对比两个输出的像素值分布、最大最小值、直方图;
    • 如果差距大,说明是输入/后处理问题;如果接近,则可能是硬件加速器精度损失。
  3. 尝试关闭量化,仅做编译
    修改 config 中 calibration_type: 'default''skip',跳过量化,看是否仍有过曝 —— 如果没有,那就是量化引入的问题。


:check_mark: 第四步:参考官方文档 & 工具链支持

您提到“算法工具链”,建议联系 D-Robotics 官方技术支持团队,提供以下材料以便他们协助排查:

  • 完整的 .yaml 配置文件
  • 转换 log (hb_mapper_makertbin.log)
  • 推理脚本
  • 一张示例输入图片 + 输出图片(带过曝截图)
  • 您希望达到的“低光增强”效果标准(如 PSNR、SSIM、主观评价)

:pushpin: 总结

项目 当前状态 建议
输入预处理 :red_exclamation_mark:未做归一化,可能导致输入过大 添加 img / 255.0
输出后处理 :cross_mark:未启用,易导致过曝 启用 np.clip + 可选 gamma 调整
模型结构 :warning:有 warning 层,可能影响精度 用 Netron 查看结构,确认无错位
量化影响 :yellow_circle:相似度高,但视觉效果差 可能是输入/输出映射问题,非量化本身
支持渠道 :blue_book:官方工具链支持 提供完整日志给 D-Robotics 技术支持

:speech_balloon: 最终回复建议(可用于论坛回复)

感谢您的详细提问!从日志来看,模型量化和编译流程基本正常,余弦相似度较高,说明数值层面没有严重偏差。

但出现过曝现象,极有可能是因为:

  1. 输入图像未归一化(应除以 255);
  2. 输出未做 clipping 或 gamma 调整,导致超出 [0,1] 范围被截断为白色;
  3. 部分层存在 shape warning,虽不影响编译,但可能影响推理逻辑。

:white_check_mark: 请优先检查并修正输入预处理和输出后处理代码,特别是 bgr2nv12_opencv 后是否进行了归一化,以及 save_modeldata_to_img 是否加了 np.clip

如果仍无法解决,建议提供一张原始图和对应输出图,我们可进一步协助定位具体哪一层出了问题。

同时,欢迎联系 D-Robotics 官方技术支持,提供完整的转换日志和配置文件,他们会更深入地帮助您排查硬件加速器相关的问题。


如果您需要我帮您生成一个修复后的推理脚本版本,或者想让我搜索类似问题的社区讨论,请告诉我 :+1:

祝调试顺利!:rocket:

请问下我需要具体如何操作呢
每一个阶段的ONNX模型分开进行验证指的是把模型拆分转换为多个ONNX吗

你好!感谢你的跟进提问。你问得很关键 —— “每一个阶段的ONNX模型分开进行验证”指的是把模型拆分转换为多个ONNX吗?

:white_check_mark: 简短回答:不是拆分成多个ONNX文件,而是“逐阶段验证每个中间ONNX模型”的输出是否符合预期。


:puzzle_piece: 什么是“逐阶段验证ONNX模型”?

在模型转换流程中(尤其是使用 hb_mapper 这类工具),模型会经历多个处理阶段:

  1. 原始 ONNX → 优化后的 ONNXoptimized_float_model.onnx
  2. 优化后 ONNX → 校准后的 ONNXcalibrated_model.onnx
  3. 校准后 ONNX → 量化后的 ONNXquantized_model.onnx
  4. 量化后 ONNX → 编译成 BPU 可执行的 .bin 文件

每个阶段都会生成一个中间 ONNX 文件,这些文件是可独立加载和推理的


:magnifying_glass_tilted_left: 为什么要逐阶段验证?

因为:

  • 如果某个阶段的输出异常(比如形状错位、数值爆炸),它会影响后续所有阶段;
  • 即使最终模型看起来“能跑”,但可能只是“勉强工作”,实际精度或视觉效果差;
  • 通过逐阶段验证,可以精准定位问题发生在哪个环节,而不是盲目怀疑量化或硬件。

:hammer_and_wrench: 如何操作?—— 举个例子

假设你有如下转换链:

original.onnx → optimized_float_model.onnx → calibrated_model.onnx → quantized_model.onnx

步骤 1:用 onnxruntime 加载并推理 optimized_float_model.onnx

import onnxruntime as ort
import numpy as np

# 加载模型
sess = ort.InferenceSession("optimized_float_model.onnx")
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name

# 准备输入数据(与原图一致)
img = cv2.imread("test.jpg")
img_resized = cv2.resize(img, (960, 540))
img_float = img_resized.astype(np.float32) / 255.0  # 归一化到 [0,1]
input_data = img_float.transpose(2, 0, 1)[np.newaxis, :, :, :]  # NCHW

# 推理
pred = sess.run([output_name], {input_name: input_data})[0]

# 打印输出形状和范围
print("Output shape:", pred.shape)
print("Min:", pred.min(), "Max:", pred.max())

:backhand_index_pointing_right: 如果这个阶段输出正常(比如数值在合理范围,没有 NaN 或 Inf),说明前半段没问题。


步骤 2:加载 calibrated_model.onnx,同样做推理

注意:有些模型在 calibration 阶段会插入 fake quantization 节点,但如果你只是想看输出是否合理,可以忽略这些节点,只关心输入→输出映射。

你可以用同样的输入数据,测试它的输出是否和上一步接近(余弦相似度 >0.99 是好的)。


步骤 3:加载 quantized_model.onnx,再做一次推理

这时候你可能会看到:

  • 输出值范围变小(因为量化为 int8);
  • 但如果你没做 post-process,直接保存图像,就会过曝!

所以这里建议你在推理脚本里加一个“反量化 + clip”的步骤:

# 假设 output 是 int8 数据,需要先转 float 并 scale 回 [0,1]
output_float = output.astype(np.float32) * scale_factor  # scale_factor 来自 config
output_clipped = np.clip(output_float, 0.0, 1.0)
output_uint8 = (output_clipped * 255).astype(np.uint8)

:warning: 注意:scale_factor 的值通常来自配置中的 scale_value,但在量化过程中可能被修改,你需要从 dzh_model_enhance_sdsdin_960_540_quantized_model.onnx 的 metadata 中提取。


:test_tube: 小技巧:用 Netron 可视化模型结构

安装 Netron,打开你的 .onnx 文件,可以看到:

  • 每一层的输入/输出形状;
  • 是否有 reshape、transpose、slice 等操作;
  • 是否存在你不熟悉的算子(如 /Sub, /Div);
  • 是否有 layer 的 shape warning(如你 log 中提到的)

这有助于你判断:是不是某一层的维度错了,导致后面的数据错位?


:pushpin: 总结:你该怎么做?

目标 操作
:white_check_mark: 验证每一阶段 ONNX 输出 使用 onnxruntime 加载每个中间 ONNX 文件,传入相同输入,检查输出形状和数值范围
:white_check_mark: 定位过曝源头 重点检查 quantized_model.onnx 的输出是否超出 [0,1],以及是否缺少 post-process
:white_check_mark: 确认输入预处理一致性 在推理脚本中确保 bgr2nv12_opencv 后做了归一化(除以 255),且模型期望的是 [0,1]
:white_check_mark: 查看模型结构 用 Netron 查看是否有意外 reshape 或 broadcast 导致数据错位

:light_bulb: 补充建议:如果不想自己写验证脚本

你可以直接运行官方提供的 hb_mapper 工具自带的 “模型一致性检查”功能(如果有),或者联系 D-Robotics 技术支持,提供:

  • 所有中间 ONNX 文件(.onnx
  • 输入图片
  • 期望输出(比如电脑端的效果截图)

他们可以用他们的工具链帮你自动对比各阶段输出差异。


:memo: 最终回复模板(可用于论坛回复)

你好!关于“每一个阶段的ONNX模型分开进行验证”,这不是指把模型拆成多个文件,而是指在转换流程中,每完成一个阶段(如优化、校准、量化),就单独加载那个阶段的 ONNX 文件,在相同的输入下做推理,并检查输出是否合理

举例来说:

  • 先验证 optimized_float_model.onnx 的输出是否和原始 ONNX 一致;
  • 再验证 calibrated_model.onnx 的输出是否稳定;
  • 最后验证 quantized_model.onnx 的输出是否在 [0,1] 范围内,且经过 post-process 后不会过曝。

你可以用 Python + onnxruntime 快速实现这个验证。我也可以帮你写一个简单的验证脚本模板。

另外,你 log 中提到的 /Sub 层 shape warning,虽然不影响编译,但也值得留意 —— 它可能暗示某些层在转换时丢失了维度信息,建议用 Netron 可视化查看结构。

如果你需要,我可以为你生成一个完整的“逐阶段验证脚本”,方便你一步步排查问题 :blush:


有任何具体操作卡住的地方,随时告诉我,我会一步步带你解决!:flexed_biceps:
祝调试顺利,早日解决过曝问题!:rocket:

量化生成文件夹里有很多不同阶段的ONNX文件,可以分别推理定位一下问题出现在哪里

感谢 Marcelo 的补充!你提到的非常关键 —— 量化生成文件夹里确实会输出多个中间 ONNX 文件,比如:

  • dzh_model_enhance_sdsdin_960_540_original_float_model.onnx(原始模型)
  • dzh_model_enhance_sdsdin_960_540_optimized_float_model.onnx(优化后)
  • dzh_model_enhance_sdsdin_960_540_calibrated_model.onnx(校准后)
  • dzh_model_enhance_sdsdin_960_540_quantized_model.onnx(量化后)

这些文件都是可独立加载和推理的 ONNX 模型,你可以用 onnxruntime 逐个加载它们,传入相同的输入图像,观察每一步的输出是否合理。


:white_check_mark: 推荐操作流程:逐阶段验证 + 定位过曝源头

:test_tube: 第一步:准备测试脚本(Python + onnxruntime)

你可以创建一个简单的 Python 脚本,用于加载每个中间 ONNX 文件并做推理:

import onnxruntime as ort
import numpy as np
import cv2

def load_and_infer_onnx(model_path, input_data):
    sess = ort.InferenceSession(model_path)
    input_name = sess.get_inputs()[0].name
    output_name = sess.get_outputs()[0].name
    
    pred = sess.run([output_name], {input_name: input_data})[0]
    
    print(f"Model: {model_path}")
    print(f"Output shape: {pred.shape}")
    print(f"Min: {pred.min():.6f}, Max: {pred.max():.6f}")
    print(f"Mean: {pred.mean():.6f}, Std: {pred.std():.6f}")
    return pred

# 示例:加载一张图片作为输入
img = cv2.imread("test.jpg")
img_resized = cv2.resize(img, (960, 540))
img_float = img_resized.astype(np.float32) / 255.0  # 归一化到 [0,1]
input_data = img_float.transpose(2, 0, 1)[np.newaxis, :, :, :]  # NCHW

# 依次加载各个中间 ONNX 文件进行推理
models_to_test = [
    "dzh_model_enhance_sdsdin_960_540_original_float_model.onnx",
    "dzh_model_enhance_sdsdin_960_540_optimized_float_model.onnx",
    "dzh_model_enhance_sdsdin_960_540_calibrated_model.onnx",
    "dzh_model_enhance_sdsdin_960_540_quantized_model.onnx"
]

for model_path in models_to_test:
    try:
        output = load_and_infer_onnx(model_path, input_data)
        # 如果是 quantized_model,可能需要反量化
        if "quantized_model" in model_path:
            # 假设 scale_value 是 0.003921568627451(来自你的 config)
            scale_factor = 0.003921568627451
            output_float = output.astype(np.float32) * scale_factor
            print("After dequantization:", output_float.min(), output_float.max())
            output = output_float
    except Exception as e:
        print(f"Failed to infer {model_path}: {e}")

:light_bulb: 这个脚本会打印每个阶段的输出范围。如果某个阶段的 Max > 1.0Min < 0.0,说明该阶段输出异常 → 可能是预处理/后处理不一致导致!


:bullseye: 第二步:定位“过曝”具体发生在哪一层?

从你的 log 中可以看到:

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

这提示某些层在转换时维度信息丢失了。虽然不影响编译,但可能导致后续数据错位。

:white_check_mark: 建议用 Netron 打开 quantized_model.onnx,查看是否有以下问题:

  • 是否有 Sub, Div, ReduceMin 等操作被错误地应用在错误维度上?
  • 输出张量形状是否与预期一致(如 HxWx3)?
  • 是否存在 reshape 或 broadcast 导致数据错位?

:puzzle_piece: 第三步:结合硬件推理结果做交叉验证

你现在已经在 RDK X5 上用 hobot_dnn 推理了 .bin 文件,得到的是过曝图像。

:backhand_index_pointing_right: 现在你可以这样做:

  1. 用上面的脚本加载 quantized_model.onnx,获取其输出;
  2. 将这个输出直接保存为图像(加 np.clip*255);
  3. 对比这个图像和你在板卡上看到的图像 —— 如果两者一致,说明问题是输入预处理或后处理未对齐
  4. 如果两者不一致,说明是ONNX 模型内部结构或算子实现差异

:pushpin: 总结:你现在可以做的三件事

目标 操作
:magnifying_glass_tilted_left: 定位过曝源头 onnxruntime 加载所有中间 ONNX 文件,对比输出数值范围
:compass: 确认模型结构 用 Netron 查看 quantized_model.onnx,确认无维度错位或异常算子
:hammer_and_wrench: 修复输入/输出映射 在推理脚本中确保:
- 输入图像是 [0,1] 浮点数
- 输出图像经过 np.clip(0,1)*255 后保存

:speech_balloon: 最终回复建议(可用于论坛回复)

你好 Marcelo!非常感谢你的提醒 —— 确实,hb_mapper 在转换过程中会生成多个中间 ONNX 文件,例如:

  • original_float_model.onnx
  • optimized_float_model.onnx
  • calibrated_model.onnx
  • quantized_model.onnx

这些文件都可以用 onnxruntime 单独加载和推理。我们推荐你逐个加载这些模型,传入相同的输入图像,检查每一步的输出是否合理

举例来说:

  • 如果 quantized_model.onnx 的输出值远大于 1.0,说明量化后未做反量化或 clipping;
  • 如果 calibrated_model.onnx 的输出已经出现异常,那问题可能出在校准阶段;
  • 使用 Netron 可视化模型结构,有助于发现 /Sub, /Div 等层是否存在维度错误。

我可以为你写一个完整的“逐阶段验证脚本”,方便你快速定位问题。只需提供你的模型路径和输入图片即可 :blush:

同时,如果你希望我帮你分析某个特定 ONNX 文件的内容(比如输出形状、节点名称),也可以直接发给我,我会帮你解读!


有任何具体操作卡住的地方,随时告诉我,我会一步步带你解决!:flexed_biceps:
祝调试顺利,早日解决过曝问题!:rocket:

我使用onnxruntime推理每一层模型时,会报错说存在不支持的算子HZ_PREPROCESS_FOR_input,我已经关闭量化参数了不知道为啥转换时还是会自动生成这个算子,导致无法推理
yaml文件:

# Copyright (c) 2020 D-Robotics.All Rights Reserved.

# 模型转化相关的参数
model_parameters:
  # 必选参数

  onnx_model: 'model_sdsdin_960_540.onnx'
  march: "bayes-e"
#  layer_out_dump: False
  working_dir: 'dzh_model_sdsdin_no_scale_output'
  output_model_file_prefix: 'model_sdsdin_no_scale'
# #模型输入相关参数
input_parameters:

 # input_name: ""
  input_shape: '1x3x960x540'
  input_type_rt: 'rgb'
  input_layout_rt: 'NCHW'

  # 必选参数
  # 原始浮点模型训练框架中所使用训练的数据类型,可选的值为rgb/bgr/gray/featuremap/yuv444, 例如:input_type_>
  input_type_train: 'rgb'

  # 必选参数
  # 原始浮点模型训练框架中所使用训练的数据排布, 可选值为 NHWC/NCHW, 例如:input_layout_train: 'NHWC'
  input_layout_train: 'NCHW'

  # input_batch: 1
 # 必选参数
  # 原始浮点模型训练框架中所使用数据预处理方法,可配置:no_preprocess/data_mean/data_scale/data_mean_and_sc>
  norm_type: 'no_preprocess'

calibration_parameters:
  # 必选参数
  cal_data_dir: './sdsdin_calibration'
# run_on_cpu: ['Identity_2', '/Div_mul']
  cal_data_type: 'float32'
  calibration_type: 'default'
  #calibration_type: 'skip'
  #preprocess_on: True
 # per_channel: True
  max_percentile: 1
 # 编译器相关参数
compiler_parameters:

  compile_mode: 'latency'
  debug: True
  core_num: 1
  optimize_level: 'O3'

转换log:

2026-03-27 10:03:56,648 INFO log will be stored in /open_explorer/hb_mapper_makertbin.log
2026-03-27 10:03:56,649 INFO Start hb_mapper....
2026-03-27 10:03:56,649 INFO hbdk version 3.49.15
2026-03-27 10:03:56,649 INFO horizon_nn version 1.1.0
2026-03-27 10:03:56,649 INFO hb_mapper version 1.24.3
2026-03-27 10:03:56,649 INFO Start Model Convert....
2026-03-27 10:03:56,660 INFO Using onnx model file: /open_explorer/Model/dzh/model_sdsdin_960_540.onnx
2026-03-27 10:03:56,679 INFO Model has 1 inputs according to model file
2026-03-27 10:03:56,680 INFO Model name not given in yaml_file, using model name from model file: ['input']
2026-03-27 10:03:56,680 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-03-27 10:03:56,680 INFO custom_op does not exist, skipped
2026-03-27 10:03:56,680 WARNING Input node input's input_source not set, it will be set to ddr by default
2026-03-27 10:03:56,716 INFO *******************************************
2026-03-27 10:03:56,717 INFO First calibration picture name: 0001x1.rgbchw
2026-03-27 10:03:56,717 INFO First calibration picture md5:
aff9d490b866e207fafcd623e31a30d0  /open_explorer/Model/dzh/sdsdin_calibration/0001x1.rgbchw
2026-03-27 10:03:56,798 INFO *******************************************
2026-03-27 10:03:59,599 INFO Start to Horizon NN Model Convert.
2026-03-27 10:03:59,601 INFO Loading horizon_nn debug methods:set()
2026-03-27 10:03:59,602 INFO The activation calibration parameters:
    calibration_type:     ['max', 'kl']
    max_percentile:       [0.99995, 1.0]
    per_channel:          [True, False]
    asymmetric:           [True, False]
The modelwise search parameters:
    similarity:           0.995
    metric:               cosine-similarity
The input of node /Pow are set to : int16
The output of node /Pow are set to : int16
The input of node /Pow_1 are set to : int16
The output of node /Pow_1 are set to : int16
The input of node /Pow_2 are set to : int16
The output of node /Pow_2 are set to : int16
The input of node /Pow_3 are set to : int16
The output of node /Pow_3 are set to : int16
The input of node /Pow_4 are set to : int16
The output of node /Pow_4 are set to : int16
The input of node /Pow_5 are set to : int16
The output of node /Pow_5 are set to : int16
The input of node /Pow_6 are set to : int16
The output of node /Pow_6 are set to : int16
The input of node /Pow_7 are set to : int16
The output of node /Pow_7 are set to : int16
The input of node /Sub_2 are set to : int16
The output of node /Sub_2 are set to : int16
The input of node /Sub_3 are set to : int16
The output of node /Sub_3 are set to : int16
The input of node /Sub_4 are set to : int16
The output of node /Sub_4 are set to : int16
The input of node /Sub_5 are set to : int16
The output of node /Sub_5 are set to : int16
The input of node /Sub_6 are set to : int16
The output of node /Sub_6 are set to : int16
The input of node /Sub_7 are set to : int16
The output of node /Sub_7 are set to : int16
The input of node /Mul are set to : int16
The output of node /Mul are set to : int16
The input of node /Mul_1 are set to : int16
The output of node /Mul_1 are set to : int16
The input of node /Mul_2 are set to : int16
The output of node /Mul_2 are set to : int16
The input of node /Mul_3 are set to : int16
The output of node /Mul_3 are set to : int16
The input of node /Mul_4 are set to : int16
The output of node /Mul_4 are set to : int16
The input of node /Mul_5 are set to : int16
The output of node /Mul_5 are set to : int16
The input of node /Split are set to : int16
The output of node /Split are set to : int16
The input of node /e_conv6/Conv are set to : int16
The output of node /e_conv6/Conv are set to : int16
The input of node /e_conv5/Conv are set to : int16
The output of node /e_conv5/Conv are set to : int16
There are 23 nodes designated to run on the bpu: ['/Pow', '/Pow_1', '/Pow_2', '/Pow_3', '/Pow_4', '/Pow_5', '/Pow_6', '/Pow_7', '/Sub_2', '/Sub_3', '/Sub_4', '/Sub_5', '/Sub_6', '/Sub_7', '/Mul', '/Mul_1', '/Mul_2', '/Mul_3', '/Mul_4', '/Mul_5', '/Split', '/e_conv6/Conv', '/e_conv5/Conv'].
2026-03-27 10:03:59,602 INFO The specified model compilation architecture: bayes-e.
2026-03-27 10:03:59,602 INFO The specified model compilation optimization parameters: [].
2026-03-27 10:03:59,602 INFO Start to prepare the onnx model.
2026-03-27 10:03:59,606 INFO Input ONNX Model Information:
ONNX IR version:          6
Opset version:            ['ai.onnx v11', 'horizon v1']
Producer:                 pytorch v2.1.1
Domain:                   None
Version:                  None
Graph input:
    input:                shape=[1, 3, 960, 540], dtype=FLOAT32
Graph output:
    output:               shape=[1, 3, 960, 540], dtype=FLOAT32
    83:                   shape=[1, 18, 960, 540], dtype=FLOAT32
2026-03-27 10:03:59,678 INFO End to prepare the onnx model.
2026-03-27 10:03:59,682 INFO Saving model to: model_sdsdin_no_scale_original_float_model.onnx.
2026-03-27 10:03:59,682 INFO Start to optimize the onnx model.
2026-03-27 10:03:59,771 INFO End to optimize the onnx model.
2026-03-27 10:03:59,774 INFO Saving model to: model_sdsdin_no_scale_optimized_float_model.onnx.
2026-03-27 10:03:59,774 INFO Start to calibrate the model.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-27 10:04:01,508 INFO There are 39 samples in the data set.
2026-03-27 10:04:01,508 INFO Run calibration model with modelwise search method.
2026-03-27 10:04:01,524 WARNING The output of Node(name:/Div, type:Div) does not support data type: int16
2026-03-27 10:04:01,557 INFO Calibration using batch 8
2026-03-27 10:04:01,563 WARNING The output of Node(name:/Div, type:Div) does not support data type: int8
2026-03-27 10:04:01,620 WARNING The input0 of Node(name:/ReduceMin_1, type:ReduceMin) does not support data type: int16
2026-03-27 10:04:01,620 WARNING The input0 of Node(name:/ReduceMin_1, type:ReduceMin) does not support data type: int8
calibration in progress: 100%|████████████████████████████████████████████████| 5/5 [01:18<00:00, 15.74s/it]
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-27 10:05:40,180 INFO Calibration using batch 8
calibration in progress: 100%|████████████████████████████████████████████████| 5/5 [00:27<00:00,  5.44s/it]
2026-03-27 10:06:07,821 INFO Calibration using batch 8
calibration in progress: 100%|████████████████████████████████████████████████| 5/5 [01:16<00:00, 15.24s/it]
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-27 10:08:37,351 INFO Select max-percentile:percentile=0.99995 method.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-27 10:08:37,490 INFO End to calibrate the model.
2026-03-27 10:08:37,662 INFO Saving model to: model_sdsdin_no_scale_calibrated_model.onnx.
2026-03-27 10:08:37,662 INFO Start to quantize the model.
Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub
        /Sub layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

Layer /Sub_8
        /Sub_8 layer, the shape of the tensor and maxshape_nhwc should be in range: [1, 10], but the tensor shape is 0, and the maxshape_nhwc shape is 4

2026-03-27 10:08:37,962 INFO End to quantize the model.
2026-03-27 10:08:38,038 INFO Saving model to: model_sdsdin_no_scale_quantized_model.onnx.
2026-03-27 10:08:38,038 INFO Start to compile the model with march bayes-e.
2026-03-27 10:08:38,233 INFO Compile submodel: main_graph_subgraph_0
2026-03-27 10:08:38,747 INFO hbdk-cc parameters:['--O3', '--debug', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'ddr']
2026-03-27 10:08:38,748 WARNING Can not find the scale for node HZ_PREPROCESS_FOR_input_NCHW2NHWC_LayoutConvert_Input0
[==================================================] 100%
2026-03-27 10:08:41,287 INFO consumed time 0.492542
2026-03-27 10:08:41,472 INFO FPS=867.65, latency = 1152.5 us, DDR = 7833792 bytes   (see main_graph_subgraph_0.html)
2026-03-27 10:08:41,474 INFO Compile submodel: main_graph_subgraph_1
2026-03-27 10:08:41,480 INFO hbdk-cc parameters:['--O3', '--debug', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'ddr']
2026-03-27 10:32:12,319 INFO consumed time 1410.81
2026-03-27 10:32:12,913 INFO FPS=15.38, latency = 65023.4 us, DDR = 460647456 bytes   (see main_graph_subgraph_1.html)
2026-03-27 10:32:13,017 INFO Compile submodel: main_graph_subgraph_2
2026-03-27 10:32:13,042 INFO hbdk-cc parameters:['--O3', '--debug', '--core-num', '1', '--fast', '--input-layout', 'NHWC', '--output-layout', 'NHWC', '--input-source', 'ddr']
2026-03-27 10:32:13,472 INFO consumed time 0.397282
2026-03-27 10:32:13,513 INFO FPS=867.65, latency = 1152.5 us, DDR = 7833792 bytes   (see main_graph_subgraph_2.html)
2026-03-27 10:32:13,784 INFO End to compile the model with march bayes-e.
2026-03-27 10:32:28,456 INFO The main quantized node information:
=================================================================================================================================
Node                                              ON   Subgraph  Type                    Cosine Similarity  Threshold  DataType
---------------------------------------------------------------------------------------------------------------------------------
HZ_PREPROCESS_FOR_input                           BPU  id(0)     HzSQuantizedPreprocess  0.053359           127.0      int8
/ReduceMin                                        CPU  --        ReduceMin               --                 --         float
/Sub                                              CPU  --        Sub                     0.053359           --         float
/ReduceMax                                        CPU  --        ReduceMax               --                 --         float
/Sub_1                                            CPU  --        Sub                     --                 --         float
/Div                                              CPU  --        Div                     0.053359           --         float
/e_conv1/Conv                                     BPU  id(1)     HzSQuantizedConv        0.872259           0.719826   int16
/relu/LeakyRelu                                   BPU  id(1)     HzLut                   0.881865           0.571334   int8
/e_conv2/Conv                                     BPU  id(1)     HzSQuantizedConv        0.930019           0.571334   int8
/relu_1/LeakyRelu                                 BPU  id(1)     HzLut2Layer             0.923090           0.563242   int16
/e_conv3/Conv                                     BPU  id(1)     HzSQuantizedConv        0.922909           0.563242   int16
/relu_2/LeakyRelu                                 BPU  id(1)     HzLut2Layer             0.931813           0.712144   int16
/e_conv4/Conv                                     BPU  id(1)     HzSQuantizedConv        0.903102           0.712144   int16
/relu_3/LeakyRelu                                 BPU  id(1)     HzLut2Layer             0.922594           1.5272     int16
/relu_2/LeakyRelu_output_0_calibrated_Requantize  BPU  id(1)     HzRequantize            --                 --         int16
/Concat                                           BPU  id(1)     Concat                  0.929136           0.712144   int16
/e_conv5/Conv                                     BPU  id(1)     HzSQuantizedConv        0.932277           1.5272     int16
/relu_4/LeakyRelu                                 BPU  id(1)     HzLut2Layer             0.923252           1.58091    int16
/relu_1/LeakyRelu_output_0_calibrated_Requantize  BPU  id(1)     HzRequantize            --                 --         int16
/Concat_1                                         BPU  id(1)     Concat                  0.923212           0.563242   int16
/e_conv6/Conv                                     BPU  id(1)     HzSQuantizedConv        0.944965           1.58091    int16
/relu_5/LeakyRelu                                 BPU  id(1)     HzLut2Layer             0.946740           1.34287    int16
/relu/LeakyRelu_output_0_calibrated_Requantize    BPU  id(1)     HzRequantize            --                 --         int8
/Concat_2                                         BPU  id(1)     Concat                  0.935996           0.571334   int8
/e_conv7/Conv                                     BPU  id(1)     HzSQuantizedConv        0.977795           1.34287    int8
/Tanh                                             BPU  id(1)     HzLut2Layer             0.996174           2.40376    int16
/Split                                            BPU  id(1)     Split                   0.999027           0.983796   int16
/Pow                                              BPU  id(1)     HzLut2Layer             0.147433           0.719826   int16
/Sub_2                                            BPU  id(1)     HzSElementwiseSub       0.025468           0.719826   int16
/Mul                                              BPU  id(1)     HzSElementwiseMul       0.026222           0.983796   int16
/Add                                              BPU  id(1)     HzSElementwiseAdd       0.042166           0.719826   int16
/Pow_1                                            BPU  id(1)     HzLut2Layer             0.092493           0.911607   int16
/Sub_3                                            BPU  id(1)     HzSElementwiseSub       0.011527           0.911607   int16
/Mul_1                                            BPU  id(1)     HzSElementwiseMul       0.011903           0.983796   int16
/Add_1                                            BPU  id(1)     HzSElementwiseAdd       0.031454           0.911607   int16
/Pow_2                                            BPU  id(1)     HzLut2Layer             0.052764           0.986896   int16
/Sub_4                                            BPU  id(1)     HzSElementwiseSub       0.003515           0.986896   int16
/Mul_2                                            BPU  id(1)     HzSElementwiseMul       0.003606           0.983796   int16
/Add_2                                            BPU  id(1)     HzSElementwiseAdd       0.024339           0.986896   int16
/Pow_3                                            BPU  id(1)     HzLut2Layer             0.032824           0.997992   int16
/Sub_5                                            BPU  id(1)     HzSElementwiseSub       0.001056           0.997992   int16
/Mul_3                                            BPU  id(1)     HzSElementwiseMul       0.001044           0.983796   int16
/Add_3                                            BPU  id(1)     HzSElementwiseAdd       0.020687           0.997992   int16
/Pow_4                                            BPU  id(1)     HzLut2Layer             0.024717           0.999503   int16
/Pow_5                                            BPU  id(1)     HzLut2Layer             0.028616           0.999503   int16
/Sub_6                                            BPU  id(1)     HzSElementwiseSub       0.000698           0.999006   int16
/Mul_4                                            BPU  id(1)     HzSElementwiseMul       0.000729           0.983796   int16
/Add_4                                            BPU  id(1)     HzSElementwiseAdd       0.022271           0.999503   int16
/Pow_6                                            BPU  id(1)     HzLut2Layer             0.028245           0.99922    int16
/Pow_7                                            BPU  id(1)     HzLut2Layer             0.034518           0.99922    int16
/Sub_7                                            BPU  id(1)     HzSElementwiseSub       0.000978           0.99844    int16
/Mul_5                                            BPU  id(1)     HzSElementwiseMul       0.000992           0.983796   int16
/Add_5                                            BPU  id(1)     HzSElementwiseAdd       0.024690           0.99922    int16
/Concat_3                                         BPU  id(1)     Concat                  0.996175           0.983796   int16
/ReduceMin_1                                      CPU  --        ReduceMin               --                 0.998728   float
/Sub_8                                            CPU  --        Sub                     0.024690           0.998728   float
/Mul_6                                            BPU  id(2)     HzSQuantizedConv        0.024690           0.998728   int8
/ReduceMax_1                                      CPU  --        ReduceMax               --                 0.998728   float
/Sub_9                                            CPU  --        Sub                     --                 0.998728   float
/Div_1                                            CPU  --        Div                     0.024690           --         float
2026-03-27 10:32:28,457 INFO The quantized model output:
=============================================================================
Output      Cosine Similarity  L1 Distance  L2 Distance  Chebyshev Distance
-----------------------------------------------------------------------------
output      0.024690           128.308025   0.116612     252.029404
83          0.996175           0.072071     0.000030     0.220031
2026-03-27 10:32:28,492 INFO End to Horizon NN Model Convert.
2026-03-27 10:32:28,499 INFO start convert to *.bin file....
2026-03-27 10:32:28,862 INFO ONNX model output num : 2
2026-03-27 10:32:28,875 INFO ############# model deps info #############
2026-03-27 10:32:28,875 INFO hb_mapper version   : 1.24.3
2026-03-27 10:32:28,875 INFO hbdk version        : 3.49.15
2026-03-27 10:32:28,875 INFO hbdk runtime version: 3.15.55.0
2026-03-27 10:32:28,875 INFO horizon_nn version  : 1.1.0
2026-03-27 10:32:28,875 INFO ############# model_parameters info #############
2026-03-27 10:32:28,876 INFO onnx_model          : /open_explorer/Model/dzh/model_sdsdin_960_540.onnx
2026-03-27 10:32:28,876 INFO BPU march           : bayes-e
2026-03-27 10:32:28,876 INFO layer_out_dump      : False
2026-03-27 10:32:28,876 INFO log_level           : DEBUG
2026-03-27 10:32:28,876 INFO working dir         : /open_explorer/Model/dzh/dzh_model_sdsdin_no_scale_output
2026-03-27 10:32:28,876 INFO output_model_file_prefix: model_sdsdin_no_scale
2026-03-27 10:32:28,876 INFO node info  : {'/Pow': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_1': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_2': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_3': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_4': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_5': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_6': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Pow_7': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_2': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_3': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_4': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_5': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_6': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Sub_7': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul_1': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul_2': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul_3': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul_4': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Mul_5': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/Split': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/e_conv6/Conv': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}, '/e_conv5/Conv': {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}}
2026-03-27 10:32:28,876 INFO ############# input_parameters info #############
2026-03-27 10:32:28,877 INFO ------------------------------------------
2026-03-27 10:32:28,877 INFO ---------input info : input ---------
2026-03-27 10:32:28,877 INFO input_name          : input
2026-03-27 10:32:28,877 INFO input_type_rt       : rgb
2026-03-27 10:32:28,877 INFO input_space&range   : regular
2026-03-27 10:32:28,877 INFO input_layout_rt     : NCHW
2026-03-27 10:32:28,877 INFO input_type_train    : rgb
2026-03-27 10:32:28,877 INFO input_layout_train  : NCHW
2026-03-27 10:32:28,877 INFO norm_type           : no_preprocess
2026-03-27 10:32:28,877 INFO input_shape         : 1x3x960x540
2026-03-27 10:32:28,877 INFO cal_data_dir        : /open_explorer/Model/dzh/sdsdin_calibration
2026-03-27 10:32:28,877 INFO cal_data_type       : float32
2026-03-27 10:32:28,878 INFO ---------input info : input end -------
2026-03-27 10:32:28,878 INFO ------------------------------------------
2026-03-27 10:32:28,878 INFO ############# calibration_parameters info #############
2026-03-27 10:32:28,878 INFO preprocess_on       : False
2026-03-27 10:32:28,878 INFO calibration_type:   : default
2026-03-27 10:32:28,878 INFO max_percentile      : 1.0
2026-03-27 10:32:28,878 INFO per_channel         : False
2026-03-27 10:32:28,878 INFO ############# compiler_parameters info #############
2026-03-27 10:32:28,878 INFO debug               : True
2026-03-27 10:32:28,878 INFO compile_mode        : latency
2026-03-27 10:32:28,878 INFO hbdk_pass_through_params: --O3 --debug --core-num 1 --fast
2026-03-27 10:32:28,879 INFO input-source        : {'input': 'ddr', '_default_value': 'ddr'}
2026-03-27 10:32:28,928 INFO Convert to runtime bin file successfully!
2026-03-27 10:32:28,929 INFO End Model Convert ```

你好!这个问题非常典型,很多开发者在用 hb_mapper 做模型转换时都会遇到。

:bullseye: 核心问题

HZ_PREPROCESS_FOR_input 是地平线工具链自动插入的预处理算子,即使你设置了 norm_type: 'no_preprocess',只要使用了 hb_mapper makertbin 命令,工具链就会自动添加这个算子用于 BPU 硬件加速。

这个算子只能在 RDK 板卡上通过 hobot_dnn 运行无法在 PC 上用 onnxruntime 推理


:white_check_mark: 解决方案:获取"纯净"的中间 ONNX 文件

方法一:从转换日志中找原始/优化后的 ONNX(推荐)

从你的转换 log 可以看到,hb_mapper 确实生成了多个中间文件:

INFO Saving model to: model_sdsdin_no_scale_original_float_model.onnx
INFO Saving model to: model_sdsdin_no_scale_optimized_float_model.onnx

这两个文件是不包含 HZ_PREPROCESS_FOR_input 算子的!

你可以直接用 onnxruntime 加载它们:

import onnxruntime as ort
import numpy as np
import cv2

# 加载原始浮点模型(不含 HZ_PREPROCESS_FOR_input)
sess = ort.InferenceSession("model_sdsdin_no_scale_original_float_model.onnx")

# 准备输入
img = cv2.imread("test.jpg")
img_resized = cv2.resize(img, (960, 540))
img_float = img_resized.astype(np.float32) / 255.0  # 归一化
input_data = img_float.transpose(2, 0, 1)[np.newaxis, :, :, :]  # NCHW

# 推理
input_name = sess.get_inputs()[0].name
output = sess.run(None, {input_name: input_data})[0]
print("Output shape:", output.shape)
print("Min/Max:", output.min(), output.max())

方法二:使用 calibration_type: 'skip' 并只取 original_float_model.onnx

你已经在 config 中尝试了 calibration_type: 'skip',但问题在于:

  • 即使 skip 校准,hb_mapper 仍然会生成带 HZ_PREPROCESS_FOR_inputcalibrated_model.onnxquantized_model.onnx
  • 只有 original_float_model.onnxoptimized_float_model.onnx 是"纯净"的

:white_check_mark: 正确做法:

calibration_parameters:
  calibration_type: 'skip'  # 跳过校准

然后只使用 model_sdsdin_no_scale_original_float_model.onnx 做验证。


方法三:手动修改 ONNX 文件(高级)

如果你一定要用 calibrated_model.onnxquantized_model.onnx,可以用 onnx-graphsurgeon 删除 HZ_PREPROCESS_FOR_input 节点:

import onnx
import onnx_graphsurgeon as gs

graph = gs.import_onnx(onnx.load("model_sdsdin_no_scale_calibrated_model.onnx"))

# 找到 HZ_PREPROCESS_FOR_input 节点
for node in graph.nodes:
    if node.name == "HZ_PREPROCESS_FOR_input":
        # 将此节点的输出直接连接到下一个节点的输入
        next_node = node.outputs[0].outputs[0]
        next_node.inputs[0] = node.inputs[0]
        graph.nodes.remove(node)
        break

onnx.save(gs.export_onnx(graph), "model_clean.onnx")

但这种方法不推荐,因为可能破坏模型的量化参数。


:bar_chart: 验证流程建议

阶段 文件 是否包含 HZ_PREPROCESS 能否用 onnxruntime
原始模型 original_float_model.onnx :cross_mark: :white_check_mark:
优化模型 optimized_float_model.onnx :cross_mark: :white_check_mark:
校准模型 calibrated_model.onnx :white_check_mark: :cross_mark: 不能
量化模型 quantized_model.onnx :white_check_mark: :cross_mark: 不能

推荐验证步骤:

  1. original_float_model.onnx + onnxruntime 验证基础功能
  2. optimized_float_model.onnx + onnxruntime 验证优化后是否一致
  3. hobot_dnn + .bin 文件在板卡上验证最终效果
  4. 对比 1 和 3 的输出,定位问题

:warning: 额外发现:你的量化效果很差!

从你的 log 中可以看到:

HZ_PREPROCESS_FOR_input  Cosine Similarity: 0.053359
/e_conv1/Conv            Cosine Similarity: 0.872259
/Sub_2                   Cosine Similarity: 0.025468
output                   Cosine Similarity: 0.024690  ← 非常低!

余弦相似度只有 0.024,说明量化后模型几乎失效了!

可能原因:

  1. 校准数据不足:你只用了 39 张图片,建议至少 100-500 张
  2. 校准数据分布不对:确保校准数据和实际推理数据分布一致
  3. 模型结构不适合 int8 量化:低光增强模型对精度敏感,建议用 int16 或混合精度

优化建议:

calibration_parameters:
  cal_data_dir: './sdsdin_calibration'
  cal_data_type: 'float32'
  calibration_type: 'default'
  max_percentile: 0.99995  # 改为 0.99995,避免极端值
  per_channel: True        # 开启 per-channel 量化

# 强制部分层用 int16
node_info:
  "/e_conv1/Conv": {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}
  "/e_conv2/Conv": {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}
  "/e_conv3/Conv": {'ON': 'BPU', 'InputType': 'int16', 'OutputType': 'int16'}

:memo: 总结

问题 解决方案
HZ_PREPROCESS_FOR_input 无法用 onnxruntime 推理 使用 original_float_model.onnxoptimized_float_model.onnx
量化后精度极差 (cosine=0.024) 增加校准数据、开启 per_channel、部分层用 int16
过曝问题 检查输入归一化 (/255.0) 和输出 clipping (np.clip(0,1))

下一步操作建议:

  1. 先用 original_float_model.onnx + onnxruntime 验证模型是否正常
  2. 如果正常,再对比板卡上的 .bin 推理结果
  3. 如果差距大,重点检查输入预处理和输出后处理
  4. 如果量化精度差,重新准备校准数据并调整量化配置

需要我帮你写一个完整的验证脚本吗?

只要 input_layout_rt != input_layout_train 或者数据排布/类型需要转换(如 NCHW → NHWC),hb_mapper 就会插入 HZ_PREPROCESS_FOR_xxx 节点来完成 layout/type 转换和归一化

参考手册,应该有提供 HB_ONNXRuntime 来推理插入了工具链节点的内容