How to add operations to Tensorflow Android build
I am trying to get my Tensorflow model running on Android, so I am using nightly build here and following the Android demo , I successfully started the Android Tensorflow library and loaded the model using the code below.
inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);
And the magazine shows that the results are good.
I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
I/TensorFlowInferenceInterface: Model load took 1007ms, TensorFlow version: 1.2.0-rc0
I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/model.pb'
However, when I finished feeding all the input nodes
inferenceInterface.feed("input1", new int[]{1, 2, 3}, 1, 3);
inferenceInterface.feed("input2", new int[]{3}, 1);
inferenceInterface.feed("input3", new int[]{4}, 1);
Then call the run method
inferenceInterface.run(new String[]{"output"});
Tensorflow is breaking saying some kernels are not registered
E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[input1, input2, input3], outputs:[output]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ...jnitest, PID: 16357
java.lang.RuntimeException: Unable to start activity ComponentInfo{...MainActivity}: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>
[[Node: .../LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>
[[Node: dynamic_seq2seq/decoder/decoder_1/LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at org.tensorflow.Session.run(Native Method)
at org.tensorflow.Session.access$100(Session.java:48)
at org.tensorflow.Session$Runner.runHelper(Session.java:295)
at org.tensorflow.Session$Runner.run(Session.java:245)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:142)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:111)
at ...jnitest.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
.. 9 more
I think "LessEqual" for int32 should be defined in Tensorflow, but just not built with the Tensorflow Android Lib.
So my question is how to include more cores in the android lib build or any other way to resolve this, any help would be much appreciated.
source to share
I recommend reading this free eBook: Building Mobile Apps with TensorFlow
It has a section on What Ops Are Available on Mobile?
(page 33) that explains how Add the implementation to the build
for these kernels the op will be removed by default for mobile builds.
FYI, the book is written by Pete Varden ( GitHub , who works at Google and is one of the developers of TensorFlow.
source to share