|
本帖最后由 nijiwu 于 2020-4-5 19:12 编辑
為了做測試,我用TF build了一個XOR的model.pb,並且轉成model.rknn,用rknn-api run在Android上。有一個小問題想請問,從第二次開始rknn_run之後透過rknn_outputs_get取的的結果,都是上一次的input data的結果。init後第一次都很正常。是否會是哪裏我有疏忽或是理解錯誤??
Logat以及Sorce code如下.....
04-04 09:21:08.385 I/rkhello ( 7299): rknn_init success!
04-04 09:21:09.387 V/rkhello ( 7299): postDelayed
04-04 09:21:10.044 E/rkhello ( 7299): run_xor
04-04 09:21:10.044 E/rkhello ( 7299): rknn_inputs=0
04-04 09:21:10.045 E/rkhello ( 7299): rknn_inputs=0
04-04 09:21:10.045 E/rkhello ( 7299): rknn_input_set success! ret=0
04-04 09:21:10.045 E/rkhello ( 7299): rknn_run success! ret=0
04-04 09:21:10.053 E/rkhello ( 7299): rknn_outputs_get=0.010529
04-04 09:21:10.054 V/rkhello ( 7299): outputs 0 0:0.010528564
04-04 09:21:12.684 E/rkhello ( 7299): run_xor
04-04 09:21:12.684 E/rkhello ( 7299): rknn_inputs=0
04-04 09:21:12.684 E/rkhello ( 7299): rknn_inputs=1
04-04 09:21:12.684 E/rkhello ( 7299): rknn_input_set success! ret=0
04-04 09:21:12.684 E/rkhello ( 7299): rknn_run success! ret=0
04-04 09:21:12.684 E/rkhello ( 7299): rknn_outputs_get=0.010529
04-04 09:21:12.685 V/rkhello ( 7299): outputs 0 0:0.010528564
04-04 09:21:14.569 E/rkhello ( 7299): run_xor
04-04 09:21:14.569 E/rkhello ( 7299): rknn_inputs=0
04-04 09:21:14.569 E/rkhello ( 7299): rknn_inputs=1
04-04 09:21:14.569 E/rkhello ( 7299): rknn_input_set success! ret=0
04-04 09:21:14.569 E/rkhello ( 7299): rknn_run success! ret=0
04-04 09:21:14.569 E/rkhello ( 7299): rknn_outputs_get=0.995605
04-04 09:21:14.569 V/rkhello ( 7299): outputs 0 0:0.99560547
bool run_xor(char *inData, float *y0) {
LOGE("run_xor");
LOGE("rknn_inputs=%d\n", (char*)inData[0]);
LOGE("rknn_inputs=%d\n", (char*)inData[1]);
rknn_input inputs[1];
inputs[0].index = input_index;
inputs[0].buf = inData;
inputs[0].size = 2;
inputs[0].pass_through = false;
inputs[0].type = RKNN_TENSOR_INT8;
inputs[0].fmt = RKNN_TENSOR_NCHW;
int ret = rknn_inputs_set(ctx, 1, inputs);
if(ret < 0) {
LOGE("rknn_input_set fail! ret=%d\n", ret);
return false;
}
LOGE("rknn_input_set success! ret=%d\n", ret);
ret = rknn_run(ctx, nullptr);
if(ret < 0) {
LOGE("rknn_run fail! ret=%d\n", ret);
return false;
}
LOGE("rknn_run success! ret=%d\n", ret);
rknn_output outputs[1];
outputs[0].want_float = true;
outputs[0].is_prealloc = true;
outputs[0].index = output_index0;
outputs[0].buf = y0;
outputs[0].size = 1*sizeof(float);
ret = rknn_outputs_get(ctx, 1, outputs, nullptr);
if(ret < 0) {
LOGE("rknn_outputs_get fail! ret=%d\n", ret);
return false;
}
float* output = (float*)outputs[0].buf;
LOGE("rknn_outputs_get=%f\n", *output);
rknn_outputs_release(ctx, 1, outputs);
return true;
}
|
|