jefferyzhang 发表于 2020-6-2 11:45
1. python最终调用的就是c的api
2. c api更灵活,有更多的参数需要设置,你的问题9成是因为哪里没配置,用 ...
- rknn_input_output_num io_num;
- ret = rknn_query(ctx, RKNN_QUERY_IN_OUT_NUM, &io_num, sizeof(io_num));
- cout << io_num.n_input << endl;
- cout << io_num.n_output << endl;
- rknn_tensor_attr input_attrs[io_num.n_input];
- memset(input_attrs, 0, sizeof(input_attrs));
- cout << "INPUT : \n";
- 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));
- cout << input_attrs[i].n_dims << " " << input_attrs[i].n_elems << " ";
- for(int j = 0; j < input_attrs[i].n_dims; ++j) {
- cout << input_attrs[i].dims[j] << "*";
- }
- if(input_attrs[i].fmt == RKNN_TENSOR_NCHW)
- cout << "NCHW" << endl;
- else if(input_attrs[i].fmt == RKNN_TENSOR_NHWC)
- cout << "NHWC" << endl;
- }
- rknn_tensor_attr outputs_attr[io_num.n_output];
- memset(outputs_attr, 0, sizeof(outputs_attr));
- cout << "OUTPUT : \n";
- for (int i = 0; i < io_num.n_output; ++i)
- {
- outputs_attr[i].index = i;
- rknn_query(ctx, RKNN_QUERY_OUTPUT_ATTR, &(outputs_attr[i]), sizeof(outputs_attr[i]));
- cout << outputs_attr[i].n_dims << " " << outputs_attr[i].n_elems << endl;
- }
复制代码
- // set input
- rknn_input inputs[1];
- memset(inputs, 0, sizeof(inputs));
- inputs[0].index = 0;
- inputs[0].buf = img.data;
- inputs[0].size = image_size * image_size * 3;
- inputs[0].pass_through = false;
- inputs[0].type = RKNN_TENSOR_UINT8;
- inputs[0].fmt = RKNN_TENSOR_NHWC;
- ret = rknn_inputs_set(ctx, 1, inputs);
- if (ret < 0)
- {
- printf("rknn_input_set fail! ret=%d\n", ret);
- goto Error;
- }
- // get result
- ret = rknn_run(ctx, nullptr);
- if (ret < 0)
- {
- printf("rknn_run fail! ret=%d\n", ret);
- goto Error;
- }
- rknn_output outputs[3];
- memset(outputs, 0, sizeof(outputs));
- outputs[0].want_float = true;
- outputs[0].is_prealloc = false;
- outputs[1].want_float = true;
- outputs[1].is_prealloc = false;
- outputs[2].want_float = true;
- outputs[2].is_prealloc = false;
- ret = rknn_outputs_get(ctx, 3, outputs, nullptr);
复制代码
candela4rk 发表于 2020-6-2 16:22
输出是:
1
3
leok 发表于 2020-6-2 17:23
可以这样尝试分析:
1、python和c预处理结果是否一致;
2、推理结果是否一致;
欢迎光临 Toybrick (https://t.rock-chips.com/) | Powered by Discuz! X3.3 |