Toybrick

标题: pytorch转rknn后 调用init_runtime失败 [打印本页]

作者: BCAIZLF    时间: 2023-11-21 17:00
标题: pytorch转rknn后 调用init_runtime失败
本帖最后由 BCAIZLF 于 2023-11-21 17:00 编辑

1.利用pytorch做模型量化感知训练。
2.成功转换为rknn模型。
3.调用rknn.init_runtime(perf_debug=True)失败

pt转rknn代码
from PIL import Image
import numpy as np
#from matplotlib import pyplot as plt

import re
import math
import random
from PIL import Image
from rknn.api import RKNN
import os
os.environ["CUDA_VISIBLE_DEVICES"] ="2"
if __name__ == '__main__':

    # Create RKNN object
    rknn = RKNN(verbose=True)

    rknn.config(mean_values=[[0,0,0]], reorder_channel='', batch_size=1,target_platform=['rv1126'])#rk3399pro#'rv1109','rv1126'#,target_platform=['rk3399pro','rk1808']

    # Load tensorflow model
    print('--> Loading model')
    # rknn.load_darknet(model='./yolov3.cfg', weight="./yolov3.weights")
    ret = rknn.load_pytorch(model='/work/models/pt/VGGTCNQnewjit.pt', input_size_list=[[3,96,288]])
    # ret = rknn.load_onnx(model = '/work/models/onnx/epoch_20220721_192x320_320s_yuanban.onnx')
    print('done.........................................')

    # Build model
    print('--> Building model')
    # ret = rknn.build(do_quantization=False)#True
    ret = rknn.build(do_quantization=False, dataset='/work/files/dataset_192x320.txt', pre_compile=False)#True
    # ret = rknn.build(do_quantization=False,pre_compile=True)#True
    if ret != 0:
        print('Build pytorch failed!')
        exit(ret)
    print('done')


    rknn.export_rknn('/work/models/rknn/VGGTCNQnewjit.rknn')

    print('export VGGTCNQnewjit.rknn done')

    exit(0)



运行脚本代码报错
from rknn.api import RKNN
import numpy as np
RKNN_LOG_LEVEL=5
def init_model(rknn_path):
    rknn = RKNN()
    print('build rknn')
    rknn.load_rknn(rknn_path)
    print('load rknn')
    ret = rknn.init_runtime(perf_debug=True)
    print(ret)
    if ret != 0:
        print('Init runtime environment failed')
        exit(ret)
    rknn.eval_perf()
    return rknn

if __name__ == '__main__':
    p = np.ones([1,3,96,288],dtype=np.uint8)
    model = init_model('/work/models/rknn/VGGTCNQ.rknn')
    output = model.inference([p])
    print('done!')

作者: BCAIZLF    时间: 2023-11-21 17:00
本帖最后由 BCAIZLF 于 2023-11-21 16:47 编辑


作者: BCAIZLF    时间: 2023-11-21 17:00
root@ba37fca837f5:/work/code# python time_test.py
build rknn
load rknn
librknn_runtime version 1.7.1 (bd41dbc build: 2021-10-28 16:15:23 base: 1131)
Verify rknn graph fail!
Create RKNN model fail, error=-6
E Catch exception when init runtime!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 897, in rknn.api.rknn_base.RKNNBase.init_runtime
E   File "rknn/api/rknn_runtime.py", line 341, in rknn.api.rknn_runtime.RKNNRuntime.build_graph
E Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID
E Please feedback the detailed log file <log_feedback_to_the_rknn_toolkit_dev_team.log> to the RKNN Toolkit development team.
E You can also check github issues: https://github.com/rockchip-linux/rknn-toolkit/issues
-1
Init runtime environment failed




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3