你好请问一下,我在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()