专家用TensorFlow MNIST进行预测

2024-05-19 10:29:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我遵循TensorFlow MNIST for Experts教程,但我不知道如何让经过训练的网络预测一组新的数据。

下面是我的代码:我有TensorFlow MNIST for Experts tutorial中的所有行,并导入了一个带有pandas的csv文件作为dataframetestt。

y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
feed_dict = {x: testt[0], keep_prob:1.0}
classification = y_conv.eval(y, feed_dict)
print(classification)

我得到这个错误

^{pr2}$

请帮忙。我不知道如何正确地调用经过训练的网络。


Tags: 数据代码网络fortftensorflowfeed教程
1条回答
网友
1楼 · 发布于 2024-05-19 10:29:12

您只需要在训练循环后使用sess.run调用来获得y的输出:

with tf.Session() as sess:
    for i in range(1000):
        batch = mnist.train.next_batch(100)
        train_step.run(feed_dict={x: batch[0], y_: batch[1]})

    logits = sess.run(y, feed_dict={x: test_data})
    pred = tf.nn.softmax(logits)
    print(pred)  # or print(tf.argmax(pred, dimension=1)) for the index

相关问题 更多 >

    热门问题