这是我的张量流模型输出层:
predict = tf.reshape(y_conv, [-1, 4, 309], name="output")
现在,我可以通过python代码得到这个模型的预测结果。
这是我的python代码:
with tf.Graph().as_default():
output_graph_def = tf.GraphDef()
with open(pb_path, "rb") as f:
# load pb file
output_graph_def.ParseFromString(f.read())
tf.import_graph_def(output_graph_def, name="")
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
# input params
input_image_tensor = sess.graph.get_tensor_by_name("Placeholder:0")
input_olaceholder2 = sess.graph.get_tensor_by_name("Placeholder_2:0")
output_tensor_name = sess.graph.get_tensor_by_name("output:0")
# test image
im = read_image(image_path)
out = sess.run(output_tensor_name, feed_dict={input_image_tensor: im, input_olaceholder2: 1.0})
print(out.shape) # (1,4,309)
我想在 java 中运行这个模型(在 Android 中)并将结果放在 float[4][309] 数组中。
这是我的java代码:
TensorFlowInferenceInterface inferenceInterface = new TensorFlowInferenceInterface(assetMngr, modelName);
String[] outputNames = new String[]{"output"};
float[] inputData = getFloatImage(bitmap);
// input
inferenceInterface.feed("Placeholder:0", inputData, 1, inputW, inputH, 1);
inferenceInterface.feed("Placeholder_2:0", new float[]{1}, 1);
// run model
inferenceInterface.run(outputNames);
//get output
float[][] classes = new float[4][309];
// error:Cannot resolve method 'fetch(java.lang.String, float[][])'
inferenceInterface.fetch(outputNames[0], classes);
如何获得 float[][] 的输出结果?