【发布时间】:2017-11-14 05:28:37
【问题描述】:
我正在学习 Tensorflow,并按照教程制作了一个自定义模型以在 Android 应用程序中运行它,但我遇到了问题。我有以下代码:
public void testModel(Context ctx) {
String model_file = "file:///android_asset/model_graph.pb";
int[] result = new int[2];
float[] input = new float[]{0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 1.0F, 0.0F};
TensorFlowInferenceInterface inferenceInterface;
inferenceInterface = new TensorFlowInferenceInterface(ctx.getAssets(), model_file);
inferenceInterface.feed("input", input, 68);
inferenceInterface.run(new String[]{"output"});
inferenceInterface.fetch("output", result);
Log.v(TAG, Arrays.toString(result));
}
当应用尝试运行inferenceInterface.run(new String[]{"output"}) 方法时出现错误:
java.lang.IllegalArgumentException: In[0] is not a matrix
[[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_input_0_0, W1)]]
我不相信我创建的模型是问题所在,因为我能够在 Python 代码中使用它并获得肯定的结果。
【问题讨论】:
标签: android machine-learning tensorflow