mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-22 16:07:51 +08:00
[RKNPU2] Update quantitative model (#879)
* 对RKNPU2后端进行修改,当模型为非量化模型时,不在NPU执行normalize操作,当模型为量化模型时,在NUP上执行normalize操作 * 更新RKNPU2框架,输出数据的数据类型统一返回fp32类型 * 更新scrfd,拆分disable_normalize和disable_permute * 更新scrfd代码,支持量化 * 更新scrfd python example代码 * 更新模型转换代码,支持量化模型 * 更新文档 * 按照要求修改 * 按照要求修改 * 修正模型转换文档 * 更新一下转换脚本
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
model_path: ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx
|
||||
output_folder: ./Portrait_PP_HumanSegV2_Lite_256x144_infer
|
||||
target_platform: RK3568
|
||||
normalize:
|
||||
mean: [[0.5,0.5,0.5]]
|
||||
std: [[0.5,0.5,0.5]]
|
||||
outputs: None
|
||||
@@ -1,5 +0,0 @@
|
||||
model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx
|
||||
output_folder: ./picodet_s_416_coco_lcnet
|
||||
target_platform: RK3568
|
||||
normalize: None
|
||||
outputs: ['tmp_17','p2o.Concat.9']
|
||||
@@ -1,7 +0,0 @@
|
||||
model_path: ./scrfd_500m_bnkps_shape640x640.onnx
|
||||
output_folder: ./
|
||||
target_platform: RK3568
|
||||
normalize:
|
||||
mean: [[0.5,0.5,0.5]]
|
||||
std: [[0.5,0.5,0.5]]
|
||||
outputs: None
|
||||
@@ -1,7 +0,0 @@
|
||||
model_path: ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx
|
||||
output_folder: ./Portrait_PP_HumanSegV2_Lite_256x144_infer
|
||||
target_platform: RK3588
|
||||
normalize:
|
||||
mean: [[0.5,0.5,0.5]]
|
||||
std: [[0.5,0.5,0.5]]
|
||||
outputs: None
|
||||
@@ -1,5 +0,0 @@
|
||||
model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx
|
||||
output_folder: ./picodet_s_416_coco_lcnet
|
||||
target_platform: RK3588
|
||||
normalize: None
|
||||
outputs: ['tmp_16','p2o.Concat.9']
|
||||
@@ -1,7 +0,0 @@
|
||||
model_path: ./scrfd_500m_bnkps_shape640x640.onnx
|
||||
output_folder: ./
|
||||
target_platform: RK3588
|
||||
normalize:
|
||||
mean: [[0.5,0.5,0.5]]
|
||||
std: [[0.5,0.5,0.5]]
|
||||
outputs: None
|
||||
@@ -0,0 +1,15 @@
|
||||
mean:
|
||||
-
|
||||
- 128.5
|
||||
- 128.5
|
||||
- 128.5
|
||||
std:
|
||||
-
|
||||
- 128.5
|
||||
- 128.5
|
||||
- 128.5
|
||||
model_path: ./scrfd_500m_bnkps_shape640x640.onnx
|
||||
outputs_nodes:
|
||||
do_quantization: True
|
||||
dataset: "./datasets.txt"
|
||||
output_folder: "./"
|
||||
+9
-20
@@ -21,6 +21,7 @@ def get_config():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--verbose", default=True, help="rknntoolkit verbose")
|
||||
parser.add_argument("--config_path")
|
||||
parser.add_argument("--target_platform")
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
@@ -34,30 +35,19 @@ if __name__ == "__main__":
|
||||
model = RKNN(config.verbose)
|
||||
|
||||
# Config
|
||||
if yaml_config["normalize"] == "None":
|
||||
model.config(target_platform=yaml_config["target_platform"])
|
||||
else:
|
||||
mean_values = [[256 * mean for mean in mean_ls]
|
||||
for mean_ls in yaml_config["normalize"]["mean"]]
|
||||
std_values = [[256 * std for std in std_ls]
|
||||
for std_ls in yaml_config["normalize"]["std"]]
|
||||
model.config(
|
||||
mean_values=mean_values,
|
||||
std_values=std_values,
|
||||
target_platform=yaml_config["target_platform"])
|
||||
mean_values = yaml_config["mean"]
|
||||
std_values = yaml_config["std"]
|
||||
model.config(mean_values=mean_values, std_values=std_values, target_platform=config.target_platform)
|
||||
|
||||
# Load ONNX model
|
||||
print(type(yaml_config["outputs"]))
|
||||
print("yaml_config[\"outputs\"] = ", yaml_config["outputs"])
|
||||
if yaml_config["outputs"] == "None":
|
||||
if yaml_config["outputs_nodes"] is None:
|
||||
ret = model.load_onnx(model=yaml_config["model_path"])
|
||||
else:
|
||||
ret = model.load_onnx(
|
||||
model=yaml_config["model_path"], outputs=yaml_config["outputs"])
|
||||
ret = model.load_onnx(model=yaml_config["model_path"], outputs=yaml_config["outputs_nodes"])
|
||||
assert ret == 0, "Load model failed!"
|
||||
|
||||
# Build model
|
||||
ret = model.build(do_quantization=None)
|
||||
ret = model.build(do_quantization=yaml_config["do_quantization"], dataset=yaml_config["dataset"])
|
||||
assert ret == 0, "Build model failed!"
|
||||
|
||||
# Init Runtime
|
||||
@@ -69,9 +59,8 @@ if __name__ == "__main__":
|
||||
os.mkdir(yaml_config["output_folder"])
|
||||
|
||||
model_base_name = os.path.basename(yaml_config["model_path"]).split(".")[0]
|
||||
model_device_name = yaml_config["target_platform"].lower()
|
||||
model_device_name = config.target_platform.lower()
|
||||
model_save_name = model_base_name + "_" + model_device_name + ".rknn"
|
||||
ret = model.export_rknn(
|
||||
os.path.join(yaml_config["output_folder"], model_save_name))
|
||||
ret = model.export_rknn(os.path.join(yaml_config["output_folder"], model_save_name))
|
||||
assert ret == 0, "Export rknn model failed!"
|
||||
print("Export OK!")
|
||||
|
||||
Reference in New Issue
Block a user