Friday, September 8, 2017

Output Dimension Issue running TensorFlow graph Android

Leave a Comment

I have output my tensorflow graph into Android and I am trying to run it. I input some data from a CSV and it appears to work okay however the output of the final node is a batch x time x feature_dims and the only output functions I can see are single arrays.

The error I receive is:

08-28 10:01:44.162 10602-10602/com.example.rob.android_kds E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[the_input], outputs:[output_node0] 08-28 10:01:44.162 10602-10602/com.example.rob.android_kds E/TensorFlowInferenceInterface: Inference exception: java.lang.IllegalArgumentException: Input shape axis 0 must equal 3, got shape [1]                                                                                                [[Node: fc1/unstack = Unpack[T=DT_INT32, axis=0, num=3, _device="/job:localhost/replica:0/task:0/cpu:0"](fc1/Shape)]] 08-28 10:01:44.162 10602-10602/com.example.rob.android_kds I/System.out: readOutput 08-28 10:01:44.172 10602-10602/com.example.rob.android_kds E/AndroidRuntime: FATAL EXCEPTION: main                                                                             Process: com.example.rob.android_kds, PID: 10602                                                                             java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0                                                                                 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)                                                                                 at java.util.ArrayList.get(ArrayList.java:308)                                                                                 at org.tensorflow.contrib.android.TensorFlowInferenceInterface.getTensor(TensorFlowInferenceInterface.java:486)                                                                                 at org.tensorflow.contrib.android.TensorFlowInferenceInterface.readNodeIntoFloatBuffer(TensorFlowInferenceInterface.java:332)                                                                                 at org.tensorflow.contrib.android.TensorFlowInferenceInterface.readNodeFloat(TensorFlowInferenceInterface.java:287)                                                                                 at com.example.rob.android_kds.MainActivity$1.onClick(MainActivity.java:171)                                                                                 at android.view.View.performClick(View.java:5697)                                                                                 at android.view.View$PerformClick.run(View.java:22526)                                                                                 at android.os.Handler.handleCallback(Handler.java:739)                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                 at android.os.Looper.loop(Looper.java:158)                                                                                 at android.app.ActivityThread.main(ActivityThread.java:7225)                                                                                 at java.lang.reflect.Method.invoke(Native Method)                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

This is my code segment:

               // Copy the input data into TensorFlow.                System.out.println("inputNode");                Trace.beginSection("fillNodeFloat");                //input is 3x234x26 and array is a unravelled arr = 18252                tensorflow.fillNodeFloat(                        "the_input", new int[]{3 * 234 * 26}, arr);                Trace.endSection();                 // Run the inference call.                System.out.println("runInference");                Trace.beginSection("runInference");                String outputNode = "output_node0";                String[] outputNodes = {outputNode};                tensorflow.runInference(outputNodes);                Trace.endSection();                 // Copy the output Tensor back into the output array.                System.out.println("readOutput");                Trace.beginSection("readNodeFloat");                //output should be batchxtimex29 (3 x 234 x 29) = 20358 flattened array                float[] output=new float[20358];                 tensorflow.readNodeFloat(outputNode, output); // ERROR HERE                Trace.endSection(); 

Any help appreciated (full code here https://github.com/mlrobsmt/kds2Droid), thanks

2 Answers

Answers 1

Not sure but according to your error message that says Input shape axis 0 must equal 3, got shape [1] and this line of your code that define your input array float[] arr=new float[18252]; i hope the reason for your exception is that your input doesn't have an appropriate shape. In fact i think that your input should be a 3D array instead of a vector.

Answers 2

I think the problem with output dimension. In tensor flow Android it only accepts a 1D array as output. Therefore you need to make sure that in your tensor flow model only outputs a 1D array.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment