|
本帖最后由 求大佬指教 于 2019-11-26 13:38 编辑
在Android studio里debug时出现两次推理结果是一样的
两个输入分别如下:
native是下面这样写的:
- JNIEXPORT jfloatArray JNICALL Java_MicroBrainFaceRec_RecFunctions_FaceRecFeature
- (JNIEnv *env,jobject obj, jint handle,jbyteArray bitmap, jint channels){
- uint8_t *rgba = NULL;
- // Get matrix pointer
- if (NULL != bitmap) {
- rgba = (uint8_t *)env->GetByteArrayElements(bitmap, 0);
- } else {
- LOGE("caffe-jni predict(): invalid args: jrgba(NULL)");
- return nullptr;
- }
- int const rgba_len = env->GetArrayLength(bitmap);
- LOGI("rgba_len= %d\n", rgba_len);
- float *inData = (float*)malloc(rgba_len* sizeof(float));
- //float inData[49152]={};
- size_t plane_size = 128*128;
- for (size_t i = 0; i < plane_size; i++) {
- inData[i] = static_cast<float>(rgba[i * 3 + 2]); // B
- inData[plane_size + i] = static_cast<float>(rgba[i * 3 + 1]); // G
- inData[2 * plane_size + i] = static_cast<float>(rgba[i * 3]); // R
- // Alpha is discarded
- inData[i] = (inData[i] - 127.5) * 0.0078125;
- inData[plane_size + i] = (inData[plane_size + i] - 127.5) * 0.0078125;
- inData[2 * plane_size + i] = (inData[2 * plane_size + i] - 127.5) * 0.0078125;
- }
- //float outFeature[512] = {};
- jfloatArray outFeature = env->NewFloatArray(512);
- jfloat* y0 = env->GetFloatArrayElements(outFeature,0);
- use_rknn::run_rknn(inData,y0);
- env->ReleaseFloatArrayElements(outFeature, y0, 0);
- free(inData);
- return outFeature;
- }
其中用rknn设置如下:
- bool run_rknn(float *inData, float *y0){
- if(!created) {
- LOGE("run: create hasn't successful!");
- return false;
- }
- rknn_input inputs[1];
- inputs[0].index = input_index;
- inputs[0].buf = inData;
- inputs[0].size = inputs_attr[0].n_elems* sizeof(float);
- //inputs[0].size = Size;
- inputs[0].pass_through = false;
- inputs[0].type = RKNN_TENSOR_FLOAT32;
- 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;
- }
- ret = rknn_run(ctx, nullptr);
- if(ret < 0) {
- LOGE("rknn_run fail! ret=%d\n", ret);
- return false;
- }
- 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 = outputs_attr[0].n_elems * sizeof(float);;
- ret = rknn_outputs_get(ctx, 1, outputs, nullptr);
- if(ret < 0) {
- LOGE("rknn_outputs_get fail! ret=%d\n", ret);
- return false;
- }
- rknn_outputs_release(ctx, 1, outputs);
- return true;
- }
运行的时候为什么第二个结果和第一个是一样的,我将两个分别注释以后,运行都可以得到正确的结果,但是同时运行的时候第二个结果总和第一个一样,这是为什么呢? |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|