使用 TensorFlow 模型进行预测 [英] Making predictions with a TensorFlow model

查看:48
本文介绍了使用 TensorFlow 模型进行预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了给定的 mnist 教程,并且能够训练模型并评估其准确性.但是,教程没有展示如何在给定模型的情况下进行预测.我对准确性不感兴趣,我只想使用模型来预测一个新示例,并在输出中查看所有结果(标签),每个结果都有指定的分数(已排序或未排序).

I followed the given mnist tutorials and was able to train a model and evaluate its accuracy. However, the tutorials don't show how to make predictions given a model. I'm not interested in accuracy, I just want to use the model to predict a new example and in the output see all the results (labels), each with its assigned score (sorted or not).

推荐答案

Deep MNIST for专家"示例,请参阅此行:

In the "Deep MNIST for Experts" example, see this line:

我们现在可以实现我们的回归模型.它只需要一行!我们将向量化的输入图像 x 乘以权重矩阵 W,加上偏置 b,并计算分配给的 softmax 概率每个班级.

We can now implement our regression model. It only takes one line! We multiply the vectorized input images x by the weight matrix W, add the bias b, and compute the softmax probabilities that are assigned to each class.

y = tf.nn.softmax(tf.matmul(x,W) + b)

只要拉上节点 y,你就会得到你想要的.

Just pull on node y and you'll have what you want.

feed_dict = {x: [your_image]}
classification = tf.run(y, feed_dict)
print classification

这几乎适用于您创建的任何模型 - 作为计算损失之前的最后一步之一,您将计算预测概率.

This applies to just about any model you create - you'll have computed the prediction probabilities as one of the last steps before computing the loss.

这篇关于使用 TensorFlow 模型进行预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆