2017-08-28 82 views
5

我輸出我的tensorflow圖到Android中,我試圖運行它。我從一個CSV輸入一些數據,它似乎工作正常,但最終節點的輸出是一個批次x時間x feature_dims和我可以看到唯一的輸出功能是單個數組。輸出尺寸問題運行TensorFlow圖Android

我收到的錯誤是:

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) 

這是我的代碼段:

   // 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(); 

任何幫助表示讚賞(完整的代碼在這裏https://github.com/mlrobsmt/kds2Droid),感謝

回答

0

不知道,但根據你的錯誤消息說Input shape axis 0 must equal 3, got shape [1]和你的代碼這行定義你的輸入數組float[] arr=new float[18252];我希望你的exc的原因eption是您的輸入沒有適當的形狀。事實上,我認爲你的輸入應該是一個3D數組,而不是一個矢量。

+0

我同意Pooyan,但是,從看着TensorFlow輸入選項,似乎沒有一種方式來輸入爲除了展開它,並使用tensorflow.fillNodeFloat(3d35「 ] {3 * 234 * 26},arr); – mlrob

0

我認爲輸出維度的問題。在張量流Android中,它只接受一維數組作爲輸出。因此,您需要確保在張量流模型中只輸出一維數組。