I trained a tensorflow model (fully convolutional network for pixel-by-pixel image segmentation). I am trying to run it in Android studio but it always crashes. I couldn't find any solution of the issue on Stackoverflow or TF git repo.
This is what I get in Logcat:
10-06 15:38:28.613 8273-8291/? I/TensorFlowInferenceInterface: Checking to see if TensorFlow native methods are already loaded
10-06 15:38:28.614 8273-8291/? E/art: No implementation found for long org.tensorflow.contrib.android.RunStats.allocate() (tried Java_org_tensorflow_contrib_android_RunStats_allocate and Java_org_tensorflow_contrib_android_RunStats_allocate__)
10-06 15:38:28.614 8273-8291/? I/TensorFlowInferenceInterface: TensorFlow native methods not found, attempting to load via tensorflow_inference
10-06 15:38:28.627 8273-8291/? W/native: cpu_feature_guard.cc:33 The TensorFlow library was compiled to use SSE instructions, but these aren't available on your machine.
10-06 15:38:28.627 8273-8291/? W/native: cpu_feature_guard.cc:33 The TensorFlow library was compiled to use SSE2 instructions, but these aren't available on your machine.
10-06 15:38:28.627 8273-8291/? W/native: cpu_feature_guard.cc:33 The TensorFlow library was compiled to use SSE3 instructions, but these aren't available on your machine.
10-06 15:38:28.630 8273-8291/? I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
10-06 15:38:28.670 8273-8291/? I/TensorFlowInferenceInterface: Model load took 12ms, TensorFlow version: 1.2.0
10-06 15:38:28.670 8273-8291/? I/TensorFlowInferenceInterface: Successfully loaded model from 'dummy_segmentation_model.pb'
[ 10-06 15:38:28.715 8273: 8292 D/ ]
HostConnection::get() New Host Connection established 0x88320100, tid 8292
10-06 15:38:28.716 8273-8292/? I/OpenGLRenderer: Initialized EGL, version 1.4
10-06 15:38:28.716 8273-8292/? D/OpenGLRenderer: Swap behavior 1
10-06 15:38:28.716 8273-8292/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
10-06 15:38:28.716 8273-8292/? D/OpenGLRenderer: Swap behavior 0
10-06 15:38:28.720 8273-8292/? D/EGL_emulation: eglCreateContext: 0xa85850c0: maj 3 min 1 rcv 4
10-06 15:38:28.814 8273-8292/? D/EGL_emulation: eglMakeCurrent: 0xa85850c0: ver 3 1 (tinfo 0xa8583210)
10-06 15:38:28.815 8273-8292/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
10-06 15:38:28.815 8273-8292/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
10-06 15:38:28.815 8273-8292/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
10-06 15:38:28.858 8273-8292/? D/EGL_emulation: eglMakeCurrent: 0xa85850c0: ver 3 1 (tinfo 0xa8583210)
10-06 15:38:31.349 8273-8292/com.cognexa.showimage D/EGL_emulation: eglMakeCurrent: 0xa85850c0: ver 3 1 (tinfo 0xa8583210)
10-06 15:38:31.360 8273-8292/com.cognexa.showimage D/OpenGLRenderer: endAllActiveAnimators on 0x9ae1f780 (RippleDrawable) with handle 0x892d4200
10-06 15:38:34.727 8273-8292/com.cognexa.showimage D/EGL_emulation: eglMakeCurrent: 0xa85850c0: ver 3 1 (tinfo 0xa8583210)
10-06 15:38:38.684 8273-8273/com.cognexa.showimage A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 8273 (gnexa.showimage)
[ 10-06 15:38:38.684 1295: 1295 W/ ]
debuggerd: handling request: pid=8273 uid=10080 gid=10080 tid=8273
This is the important part of Android code, where I feed the image of size 600x600 to tensorflow model and where it crashes:
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Mat mat = new Mat();
Bitmap bmp32 = image_bitmap.copy(conf, true);
Utils.bitmapToMat(bmp32, mat);
Mat mat_resized = new Mat();
Size size = new Size(600, 600);
Imgproc.resize(mat, mat_resized, size);
Bitmap bmp_resized = Bitmap.createBitmap(600, 600, conf);
Utils.matToBitmap(mat_resized, bmp_resized);
int w = bmp_resized.getWidth();
int h = bmp_resized.getHeight();
bmp_resized.getPixels(intValues, 0, w, 0, 0, w, h);
int lenint = intValues.length;
for (int i = 0; i < intValues.length; ++i) {
final int val = intValues[i];
floatValues[i * 3 + 0] = (((val >> 16) & 0xFF) - imageMean) / imageStd;
floatValues[i * 3 + 1] = (((val >> 8) & 0xFF) - imageMean) / imageStd;
floatValues[i * 3 + 2] = ((val & 0xFF) - imageMean) / imageStd;
}
// Copy the input data into TensorFlow.
Trace.beginSection("feed");
tfHelper.feed(inputName, floatValues, 1, 600, 600, 3);
Trace.endSection();
// Run the inference call.
Trace.beginSection("run");
tfHelper.run(outputNames, logStats);
Trace.endSection();
where tfHelper is an instance of org.tensorflow.contrib.android.TensorFlowInferenceInterface.
If I comment last 3 lines, the app doesn't crash. I think it isn't a memory issue, as I tried it also with a small version of the model (which is only ~50kB ).
Thanks!