|
本帖最后由 zach 于 2022-6-16 12:59 编辑
我使用下面的代码来加载模型
- void create(int inputSize, int channel, int numResult, int numClasses, char *mParamPath) {
- img_width = inputSize;
- img_height = inputSize;
- img_channels = channel;
- int ret = 0;
- int model_len = 0;
- unsigned char *model = nullptr;
- // Load RKNN Model
- LOGE("Loading model: %s", mParamPath);
- model = load_model(mParamPath, &model_len);
- LOGE("rknn_init ...");
- ret = rknn_init(&ctx, model, model_len, 0, NULL);
- if (ret < 0) {
- LOGE("rknn_init fail! ret=%d\n", ret);
- return;
- }
- // Get Model Input Output Info
- ret = rknn_query(ctx, RKNN_QUERY_IN_OUT_NUM, &io_num, sizeof(io_num));
- if (ret != RKNN_SUCC) {
- LOGE("rknn_query fail! ret=%d\n", ret);
- return;
- }
- LOGE("model input num: %d, output num: %d\n", io_num.n_input, io_num.n_output);
- LOGE("input tensors:\n");
- rknn_tensor_attr input_attrs[io_num.n_input];
- memset(input_attrs, 0, sizeof(input_attrs));
- for (int i = 0; i < io_num.n_input; i++) {
- input_attrs[i].index = i;
- ret = rknn_query(ctx, RKNN_QUERY_INPUT_ATTR, &(input_attrs[i]),
- sizeof(rknn_tensor_attr));
- if (ret != RKNN_SUCC) {
- LOGE("rknn_query fail! ret=%d\n", ret);
- return;
- }
- printRKNNTensor(&(input_attrs[i]));
- }
- LOGE("output tensors:\n");
- rknn_tensor_attr output_attrs[io_num.n_output];
- memset(output_attrs, 0, sizeof(output_attrs));
- for (int i = 0; i < io_num.n_output; i++) {
- output_attrs[i].index = i;
- ret = rknn_query(ctx, RKNN_QUERY_OUTPUT_ATTR, &(output_attrs[i]),
- sizeof(rknn_tensor_attr));
- if (ret != RKNN_SUCC) {
- LOGE("rknn_query fail! ret=%d\n", ret);
- return;
- }
- printRKNNTensor(&(output_attrs[i]));
- }
- created = true;
- }
下面是报错信息
- 2021-09-16 22:44:12.122 2506-2560/com.rockchip.gpadc.ssddemo E/rkssd4j: Loading model: /data/user/0/com.rockchip.gpadc.ssddemo/cache/ssd_inception_v2.rknn
- 2021-09-16 22:44:12.183 2506-2560/com.rockchip.gpadc.ssddemo E/rkssd4j: rknn_init ...
- 2021-09-16 22:44:12.188 2506-2560/com.rockchip.gpadc.ssddemo E/RKNN_API: nnapi error: unable to open function ARKNN_destory_mem
- 2021-09-16 22:44:12.189 2506-2560/com.rockchip.gpadc.ssddemo E/RKNN_API: nnapi error: unable to open function ARKNN_create_mem
- 2021-09-16 22:44:12.189 2506-2560/com.rockchip.gpadc.ssddemo E/RKNN_API: nnapi error: unable to open function ARKNN_set_io_mem
- 2021-09-16 22:44:12.190 2506-2560/com.rockchip.gpadc.ssddemo E/neuralnetworks@ndk_bridge: ARKNN_client_create 0
- 2021-09-16 22:44:12.254 2506-2560/com.rockchip.gpadc.ssddemo E/neuralnetworks@ndk_bridge: Client init failed!
- 2021-09-16 22:44:12.254 2506-2560/com.rockchip.gpadc.ssddemo E/neuralnetworks@ndk_bridge: Ret Successfully!
- 2021-09-16 22:44:12.257 2506-2560/com.rockchip.gpadc.ssddemo E/rkssd4j: rknn_query fail! ret=-7
- 2021-09-16 22:44:12.257 2506-2560/com.rockchip.gpadc.ssddemo E/rkssd4j: run_ssd: create hasn't successful!
- 2021-09-16 22:44:12.259 2506-2560/com.rockchip.gpadc.ssddemo I/chatty: uid=10131(com.rockchip.gpadc.ssddemo) Thread-3 identical 1 line
- 2021-09-16 22:44:12.280 2506-2560/com.rockchip.gpadc.ssddemo E/rkssd4j: run_ssd: create hasn't successful!
时间没有校准,请忽略时间。
so库我使用的是 <sdk>/rknpu2/Android/librknn_api/arm64_v8a中的 librknn_api_android.so和librknnrt.so 相关的头文件我也移植到了工程中。
模型使用的是 <sdk>/rknpu2/examples/rknn_ssd_demo/model/ssd_inception_v2.rknn
从日志看,程序卡在了rknn_query, 查看文档-7表示传入的rknn_context无效,然后我打印了context,看起来也是有值的- E/rkssd4j: rknn_init ctx: 479969337520, model len: 32003278
请问这个该如何解决?研究好几天了 非常感谢!
已解决: 需要增加编译选项:
ADD_DEFINITIONS(-DANDROID_PLATFORM=android-21 -DANDROID_NDK -DDISABLE_IMPORTGL -DANDROID_TOOLCHAIN=clang -DANDROID_STL=gnustl_static)
|
|