-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonnx2rknn.py
39 lines (31 loc) · 1.06 KB
/
onnx2rknn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from rknn.api import RKNN
def build_rknn_model(onnx_model_path, quantize=True):
rknn = RKNN()
print('--> Config model')
rknn.config(mean_values=[[127.5, 127.5, 127.5]], std_values=[[127.5, 127.5, 127.5]],
quant_img_RGB2BGR=False,
quantized_algorithm='normal', target_platform='rk3588')
print('done')
print('--> Loading model')
ret = rknn.load_onnx(model=onnx_model_path, inputs=['images'], input_size_list=[[1,3,640,640]])
if ret != 0:
print('Load ONNX model failed!')
return ret
print('done')
print('--> Building model')
ret = rknn.build(do_quantization=quantize, dataset='./dataset.txt')
if ret != 0:
print('Build RKNN model failed!')
return ret
print('done')
print('--> Export RKNN model')
ret = rknn.export_rknn('./output.rknn')
if ret != 0:
print('Export RKNN model failed!')
return ret
print('done')
rknn.release()
return 0
if __name__ == '__main__':
model_path = './yolov8n-face.onnx'
build_rknn_model(model_path)