kneron_model_converter/scripts/upgrade_input_params.py
2026-01-28 06:16:04 +00:00

69 lines
2.0 KiB
Python

import argparse
import json
# template
new_config_template = {
"model_info": {
"input_onnx_file": "/data1/yolov5s_e.onnx",
"model_inputs": []
},
"preprocess": {
"img_preprocess_method": "kneron",
"img_channel": "RGB",
"radix": 8,
"keep_aspect_ratio": True,
"pad_mode": 1,
"p_crop": {
"crop_x": 0,
"crop_y": 0,
"crop_w": 0,
"crop_h": 0
}
},
"simulator_img_files": []
}
# Parse arguments
argparser = argparse.ArgumentParser(
description="Run fix-point analyser, compiler and IP evaluator for KDP 520")
argparser.add_argument(
'old_config',
type=str
)
argparser.add_argument(
'new_config',
type=str
)
args = argparser.parse_args()
with open(args.old_config, 'r') as f:
old_config = json.load(f)
new_config = new_config_template
new_config["model_info"]["input_onnx_file"] = old_config["input_onnx_file"]
new_config["model_info"]["model_inputs"].append(
{"model_input_name": old_config["model_input_name"],
"input_image_folder": old_config["input_image_folder"]})
new_config["preprocess"]["img_preprocess_method"] = old_config["img_preprocess_method"]
new_config["preprocess"]["img_channel"] = old_config["img_channel"]
new_config["preprocess"]["radix"] = old_config["radix"]
new_config["preprocess"]["keep_aspect_ratio"] = (old_config["keep_aspect_ratio"] == "True")
new_config["preprocess"]["pad_mode"] = old_config["pad_mode"]
new_config["preprocess"]["p_crop"]["crop_x"] = old_config["pCrop"]["crop_x"]
new_config["preprocess"]["p_crop"]["crop_y"] = old_config["pCrop"]["crop_y"]
new_config["preprocess"]["p_crop"]["crop_w"] = old_config["pCrop"]["crop_h"]
new_config["preprocess"]["p_crop"]["crop_h"] = old_config["pCrop"]["crop_w"]
new_config["simulator_img_files"].append(
{"model_input_name": old_config["model_input_name"],
"input_image": old_config["simulator_img_file"]}
)
with open(args.new_config, 'w') as f:
json.dump(new_config, f)