Toybrick

标题: rk1126 模型加载rknn_init fail! ret=-6 [打印本页]

作者: iplayword    时间: 2021-1-11 19:19
标题: rk1126 模型加载rknn_init fail! ret=-6
Check model fail
rknn_init fail! ret=-6
int main(int argc, char **argv) {
rknn_context ctx;
        int ret;
        int model_len = 0;
        unsigned char *model;
        const char *model_path = argv[1];int xx=argc;
        if(xx<0)
                printf("xxxxxxxxxxxxxxxxxxxxerrrrrrrrrrrr\n");
        printf("xxxxxxxxxxxxxx  Loading model ...\n");
        model = load_model(model_path, &model_len);
        ret = rknn_init(&ctx, model, model_len, 0);
        if (ret < 0) {
                printf("rknn_init fail! ret=%d\n", ret);
                return -1;}rknn_sdk_version version;ret = rknn_query(ctx, RKNN_QUERY_SDK_VERSION, &version,
                        sizeof(rknn_sdk_version));
        printf("api version   : %s\n", version.api_version);
        printf("driver version: %s\n", version.drv_version);
}RKNN Toolkit: rknn_toolkit-1.4.0-cp36-cp36m-linux_x86_64.whl
RKNN Toolkit: (rknn_toolkit-1.6.0-cp36-cp36m-win_amd64.whl 下午升级1.6.0也是一样的问题)
[root@RV1126_RV1109:~]# strings /usr/lib/librknn_runtime.so | grep build
vsi_nn_kernel_add_build_option
librknn_runtime version 1.5.1 (161f53f build: 2020-11-05 15:12:30 base: 1126)
rw-r--r- 1 root root 3126876 Dec 30 11:45 /usr/lib/librknn_runtime.so
api version   : librknn_runtime version 1.5.1 (161f53f build: 2020-11-05 15:12:30 base: 1126)
driver version: 10126pc 默认模型 yolov3-tiny转码:
if name == '__main__':
MODEL_PATH = './yolov3tinyp.cfg'
WEIGHT_PATH = './yolov3tinyp.weights'
RKNN_MODEL_PATH = './yolov3tinyp.rknn'
im_file = './dog_bike_car_416x416.jpg'
DATASET = './dataset.txt'
  • download_yolov3_weight(WEIGHT_PATH)
  • Create RKNN object
    rknn = RKNN
NEED_BUILD_MODEL = Trueif NEED_BUILD_MODEL:    # Load caffe model
        print('--> Loading model')
        ret = rknn.load_darknet(model=MODEL_PATH, weight=WEIGHT_PATH)
        if ret != 0:
            print('load caffe model failed!')
            exit(ret)
        print('done')rknn.config(reorder_channel='0 1 2', mean_values=[[0, 0, 0]], std_values=[[255, 255, 255]],target_platform=['rk1109','rk1126'])
  • Build model
    print('--> Building model')
    ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
    if ret != 0:
    print('build model failed.')
    exit(ret)
    print('done')
  • Export rknn model
    print('--> Export RKNN model')
    ret = rknn.export_rknn(RKNN_MODEL_PATH)
    if ret != 0:
    print('Export rknn model failed.')
    exit(ret)
    print('done')
    else:
  • Direct load rknn model
    print('Loading RKNN model')
    ret = rknn.load_rknn(RKNN_MODEL_PATH)
    if ret != 0:
    print('load rknn model failed.')
    exit(ret)
    print('done')
print('--> init runtime')
  • ret = rknn.init_runtime()
    ret = rknn.init_runtime()
    if ret != 0:
    print('init runtime failed.')
    exit(ret)
    print('done')
img = cv2.imread(im_file)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  • inference
    print('--> inference')
    outputs = rknn.inference(inputs=[img])
    print('done')
input0_data = outputs[0]
    input1_data = outputs[1]
    input2_data = outputs[2]input0_data = input0_data.reshape(SPAN, LISTSIZE, GRID0, GRID0)
    input1_data = input1_data.reshape(SPAN, LISTSIZE, GRID1, GRID1)
    input2_data = input2_data.reshape(SPAN, LISTSIZE, GRID2, GRID2)input_data = []
    input_data.append(np.transpose(input0_data, (2, 3, 0, 1)))
    input_data.append(np.transpose(input1_data, (2, 3, 0, 1)))
    input_data.append(np.transpose(input2_data, (2, 3, 0, 1)))boxes, classes, scores = yolov3_post_process(input_data)image = cv2.imread(im_file)
    if boxes is not None:
        draw(image, boxes, scores, classes)cv2.imshow("results", image)
    cv2.waitKeyEx(0)rknn.release()





作者: iplayword    时间: 2021-1-11 19:21
  D [compute_node:349]Instance node[26] "CONV2D" ...
D [compute_node:349]Instance node[27] "RESIZE" ...
D [compute_node:349]Instance node[28] "CONCAT" ...
D [compute_node:349]Instance node[29] "CONV2D" ...
D [compute_node:349]Instance node[30] "LEAKY_RELU" ...
D [compute_node:349]Instance node[31] "CONV2D" ...
Check model fail
rknn_init fail! ret=-6





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