Reputation: 11
I was able to run the Inception-v3 model on Android just fine, and I now want to run my own trained TensorFlow model on Android. I'm following the approach from TensorFlow's image recognition tutorial and the Android TensorFlow demo, and adapting as necessary. From Android logcat, running into this when running the app:
E/native: tensorflow_inference_jni.cc:202 Error during inference: Invalid argument: Session was not created with a graph before Run()!
...
E/native: tensorflow_inference_jni.cc:159 Output [output/Softmax:0] not found, aborting!
Environment info: OS X Yosemite (10.10.5), LGE Nexus 5 (Android 6.0.1), Android SDK 23, Android OpenCV SDK 23, Bazel 0.4.0.
These are the steps I've taken so far:
tf.train.Saver()
then tf.train.write_graph()
coded_stream.SetTotalBytesLimit()
in jni_utils.cc to handle my large model sizeAs a sanity check, I have tested my model in C++ built with bazel following the tutorial here label_image, and my model correctly outputs a prediction. I have also tried playing with the order by which I save my graph def and checkpoint files before freezing, but no change.
Any help would be great.
Upvotes: 1
Views: 1187
Reputation: 11
This has been resolved (GitHub issue link here).
Steps taken: full sync with then latest tf build (last commit: 798ae42) and built using bazel -v 0.4.3-homebrew
. Android SDK v23 and NDK v23. Stripped off all preprocessing (i.e., removing OpenCV from build), and just replaced out of box tf inception demo with own model and label file. Logcat now shows:
01-06 10:27:39.048 26344-26344/? I/TensorFlowImageClassifier: Reading labels from: mylabels.txt
01-06 10:27:39.049 26344-26344/? I/TensorFlowImageClassifier: Read 7, 7 specified
01-06 10:27:39.049 26344-26344/? I/native: tensorflow_inference_jni.cc:97 Native TF methods loaded.
01-06 10:27:39.049 26344-26344/? I/TensorFlowInferenceInterface: Native methods already loaded.
01-06 10:27:39.049 26344-26344/? I/native: tensorflow_inference_jni.cc:85 Creating new session variables for 25a68072eeb0d05
01-06 10:27:39.049 26344-26344/? I/native: tensorflow_inference_jni.cc:113 Loading Tensorflow.
01-06 10:27:39.053 26344-26344/? I/native: tensorflow_inference_jni.cc:120 Session created.
01-06 10:27:39.053 26344-26344/? I/native: tensorflow_inference_jni.cc:126 Acquired AssetManager.
01-06 10:27:39.053 26344-26344/? I/native: tensorflow_inference_jni.cc:128 Reading file to proto: file:///android_asset/cnn_frozen_graph.pb
01-06 10:27:39.680 26344-26344/? I/native: tensorflow_inference_jni.cc:132 GraphDef loaded from file:///android_asset/cnn_frozen_graph.pb with 40 nodes.
01-06 10:27:39.680 26344-26344/? I/native: stat_summarizer.cc:38 StatSummarizer found 40 nodes
01-06 10:27:39.680 26344-26344/? I/native: tensorflow_inference_jni.cc:139 Creating TensorFlow graph from GraphDef.
01-06 10:27:39.713 26344-26344/org.tensorflow.demo I/native: tensorflow_inference_jni.cc:151 Initialization done in 664.038ms
01-06 10:27:39.714 26344-26344/org.tensorflow.demo I/tensorflow: ClassifierActivity: Sensor orientation: 90, Screen orientation: 0
01-06 10:27:39.714 26344-26344/org.tensorflow.demo I/tensorflow: ClassifierActivity: Initializing at size 640x480
Upvotes: 0