2017-08-28 81 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中,它只接受一维数组作为输出。因此,您需要确保在张量流模型中只输出一维数组。