Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow retrained inception v3 model crashes on Android

I had retrained TensorFlow Inception v3 model with my own dataset as described in this tutorial.

Now I'm trying to build and run TensorFlow Android example using my retrained model. I built the native code from the example as is, copied the model (.pb) and label (.txt) files to the assets dir and changed the model parameters in TensorFlowImageListener.java:

private static final int NUM_CLASSES = 5; // number of categories
private static final int INPUT_SIZE = 299;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Mul:0";
private static final String OUTPUT_NAME = "final_result:0";

But the app crashes when parsing the model file loaded from assets:

08-12 16:02:08.258 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:115 Loading TensorFlow.
08-12 16:02:08.258 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:117 Making new SessionOptions.
08-12 16:02:08.259 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:120 Got config, 0 devices
08-12 16:02:08.264 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:123 Session created.
08-12 16:02:08.264 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:126 Graph created.
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:130 Acquired AssetManager.
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:132 Reading file to proto: file:///android_asset/tensorflow_inception_graph.pb
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: jni_utils.cc:120 Opening asset tensorflow_inception_graph.pb from disk with copy.
08-12 16:02:09.382 25253-25253/com.iliakplv.tensorflow A/native: jni_utils.cc:123 Check failed: message->ParseFromArray(memory, data_size) 
08-12 16:02:09.382 25253-25253/com.iliakplv.tensorflow A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 25253 (tech.tensorflow)

P.S. I also tried using tensorflow/python/tools/strip_unused.py (as it suggested here) like this:

bazel build tensorflow/python/tools:strip_unused && \
bazel-bin/tensorflow/python/tools/strip_unused \
--input_graph=some_graph_def.pb \
--output_graph=/tmp/stripped_graph.pb \
--input_node_names=Mul
--output_node_names=final_result

Didn't help.

like image 249
Ilia Kopylov Avatar asked Feb 07 '23 09:02

Ilia Kopylov


1 Answers

The issue was with gradle compressing asset files which caused model parsing to fail. I disabled the compression for .pb files:

aaptOptions { noCompress 'pb' }
like image 186
Ilia Kopylov Avatar answered Feb 13 '23 06:02

Ilia Kopylov