gpt4 book ai didi

python - 面向专家的 TensorFlow MNIST 预测

转载 作者:行者123 更新时间:2023-12-01 03:21:02 25 4
gpt4 key购买 nike

我正在学习 TensorFlow MNIST 专家教程,但我不知道如何让经过训练的网络来预测一组新数据。

下面是我的代码:我有 TensorFlow MNIST for Experts tutorial 中的所有行我导入了一个 csv 文件,其中包含 pandas 作为数据框 testt。

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)

我收到此错误

AttributeError                            Traceback (most recent call last)
<ipython-input-36-96dfe9b26149> in <module>()
2 y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
3 feed_dict = {x: testt[0], keep_prob:1.0}
----> 4 classification = y_conv.eval(y, feed_dict)
5 print(classification)

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in eval(self, feed_dict, session)
573
574 """
--> 575 return _eval_using_default_session(self, feed_dict, self.graph, session)
576
577

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _eval_using_default_session(tensors, feed_dict, graph, session)
3627 "`eval(session=sess)`.")
3628 else:
-> 3629 if session.graph is not graph:
3630 raise ValueError("Cannot use the given session to evaluate tensor: "
3631 "the tensor's graph is different from the session's "

AttributeError: 'dict' object has no attribute 'graph'

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

最佳答案

您只需在训练循环后通过 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

关于python - 面向专家的 TensorFlow MNIST 预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41917491/

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