|
板凳
楼主 |
发表于 2020-6-2 16:22:23
|
只看该作者
- 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;
- }
输出是:
1
3
INPUT :
4 150528 224*224*3*1*NCHW
OUTPUT :
4 12495
4 49980
4 199920
我的设置是
- // 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);
有什么需要改的吗?还有其他参数需要配置吗?教程里就这些了。
inputs[0].fmt我设置成NCHW就什么也检测不出来了,所以 inputs[0].fmt和input_attrs.fmt没关系,和实际输入有关系? |
|