python - 测试数据集上的张量流预测
问题描述
我无法打印出prediction
on 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)
解决方案
在这条线上:
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}
在测试数据的情况下,您可能不需要传递标签,但如果您想计算准确度,您将需要它们,您可以根据自己的需要来决定。
以下是您可以遵循的一些非常好的示例:
推荐阅读
- python - 通过对每个唯一用户进行分组并为每个唯一日期添加访问数列来对数据框进行排序和排名 Python
- python - 在 Django 中使用复选框下载文件?
- r - MatchIt(R 的倾向得分匹配包)引发有关产生的 NA 的错误
- android - 当试图让 ViewBinding 工作时,为什么我的一些布局文件需要以
而其他人没有? - python - 在“诗歌构建”上执行自定义功能
- c# - 如何让我的组合框停止自动更改值
- flutter - Flutter:在 SliverPersistentHeader 的“成形”区域中显示 SliverList
- testing - 如何使用不同的配置进行测试与部署安全帽可靠性?
- jenkins - 如何修复 Jenkins 的 yum 更新
- json - 特定位置的 JSON 值的术语(属性?)