首页 > 解决方案 > 测试数据集上的张量流预测

问题描述

我无法打印出predictionon test data

谁能帮我填写sess.run输出步骤的输入谢谢!

def nn_model(data):  
    convnet = conv_2d(in_data, 32, 3, padding='same', activation='relu')  
    convnet = max_pool_2d(convnet, 2)  

logits = nn_model(next_element)  
prediction = tf.argmax(logits, 1)  

with tf.Session() as sess:  
    sess.run(init_op)  
    sess.run(training_init_op)  
    for i in range(epochs):  
        l, _, acc = sess.run([loss, optimizer, accuracy])  

output = sess.run(prediction, ***{logits:nn_model(test_data)}***)
output = np.argmax(output)
print("The prediction for test is :", output)

标签: pythontensorflow

解决方案


在这条线上:

output = sess.run(prediction, ***{logits:nn_model(test_data)}***)

您似乎正在尝试将您的测试数据(可能是 numpy 格式)传递给您的logits. logits传统上是模型输出的名称,这很令人困惑。在您的nn_model函数中,您应该为输入返回 logits(模型的输出)和占位符。通常你有这样的事情:

x = tf.placeholder(tf.float32, shape=(None, 1024))
labels = tf.placeholder(tf.float32, shape=(None,))

现在你的输出看起来像:

output = sess.run(logits, feed_dict={x:test_data, y:test_labels}

在测试数据的情况下,您可能不需要传递标签,但如果您想计算准确度,您将需要它们,您可以根据自己的需要来决定。

以下是您可以遵循的一些非常好的示例:

https://github.com/aymericdamien/TensorFlow-Examples


推荐阅读