gpt4 book ai didi

java - 为什么我在这个演示中在 TensorFlowInferenceInterface 中获取了错误的结果?

转载 作者:行者123 更新时间:2023-11-30 00:04:52 25 4
gpt4 key购买 nike

这里是制作protocol buffer的程序。

# -*- coding:utf-8 -*-
import tensorflow as tf

session = tf.Session()

matrix1 = tf.constant([[1., 3.]], name='input1')
matrix2 = tf.constant([[2., 2.]], name='input2')
mat_add = tf.add(matrix1, matrix2, name='output1')
mat_sub = tf.subtract(matrix1, matrix2, name='output2')

session.run(mat_add)
session.run(mat_sub)


tf.train.write_graph(session.graph.as_graph_def(), "./models/", "simple.pb", as_text=False)

session.close()

这里是与 TensorFlowInferenceInterface 交互的 java 代码的主要部分。

inferenceInterface = new TensorFlowInferenceInterface(getAssets(),MODEL_FILE);

input1[0] = (float) 5.0; input1[1] = (float) 6.0;
input2[0] = (float) 2.0; input2[1] = (float) 3.0;


inferenceInterface.feed("input1", input1, new long[]{1,2});
inferenceInterface.feed("input2", input2, new long[]{1,2});

inferenceInterface.run(new String[]{"output1","output2"});

inferenceInterface.fetch("output1", output1);
inferenceInterface.fetch("output2", output2);


for(float f : output1)
Log.i(TAG, "output1: " + f);
for(float f : output2)
Log.i(TAG, "output2: " + f);

这是 result

加法结果总是正确的,但减法结果总是[1.0,1.0],这就是我想不通的原因,加减运算几乎相同而减法总是错误的A定值。任何意见都会有所帮助!请告诉我原因。提前致谢!

最佳答案

谢谢灰!问题已通过修改代码解决

matrix1 = tf.constant([[1., 3.]], name='input1')
matrix2 = tf.constant([[2., 2.]], name='input2')

matrix1 = tf.placeholder(dtype=tf.float32, shape=(1,2), name='input1')
matrix2 = tf.placeholder(dtype=tf.float32, shape=(1,2), name='input2')

关于java - 为什么我在这个演示中在 TensorFlowInferenceInterface 中获取了错误的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49207984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com