Python 如何在训练过的模型上进行简单的Tensorflow预测?

Python 如何在训练过的模型上进行简单的Tensorflow预测?,python,tensorflow,Python,Tensorflow,我刚刚训练了一个这样的模型: with tf.Session() as sess: sess.run(tf.global_variables_initializer()) num_examples = len(X_train) print("W00T IT IS TRAINING That depends on how you defined your graph, and depends on how you defined the shape of the 'x'

我刚刚训练了一个这样的模型:

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    num_examples = len(X_train)

    print("W00T IT IS TRAINING That depends on how you defined your graph, and depends on how you defined the shape of the 'x' placeholder.
Supposing 'x' is defined like this:

x = tf.placeholder(shape=[None, IMG_WIDTH, IMG_HEIGHT, NUM_COLOR_CHANNELS], dtype=tf.float32)
predictions = sess.run(pred, feed_dict={x: img1})
将tf.Session()作为sess的
:
sess.run(tf.global\u variables\u initializer())
num_示例=len(X_列)

打印(“W00T这是培训,这取决于您如何定义图形,以及如何定义“x”占位符的形状。
假设“x”的定义如下:

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    num_examples = len(X_train)

    print("W00T IT IS TRAINING That depends on how you defined your graph, and depends on how you defined the shape of the 'x' placeholder.
Supposing 'x' is defined like this:

x = tf.placeholder(shape=[None, IMG_WIDTH, IMG_HEIGHT, NUM_COLOR_CHANNELS], dtype=tf.float32)
predictions = sess.run(pred, feed_dict={x: img1})
假设‘pred’是给出预测的张量,你只需要计算这个张量:


谢谢,我还不确定我是否理解。所以我使用了:
x=tf.placeholder(tf.float32,(None,32,32,3))
y=tf.placeholder(tf.int32,(None))
。我不确定在这种情况下,
pred
会是什么。pred可能是你网络的最后一层,它应该是你应用softmax函数的张量。啊哈,更新了这个问题……这是不是正确的预测?
?试图完全掌握最后一部分。我缺少了一些关于softmax的东西……逻辑s是您的网络正在计算的标量值,您应该应用softmax函数将该标量值转换为概率,如下所示:
pred=tf.nn.softmax(logits)
,然后您只需像前面所说的那样计算“pred”,就可以得到输入图像的网络预测概率:)。我希望这会有所帮助,请尽管问!!对不起,logits不是一个标量值,而是一个标量值向量,在应用softmax函数后,您会得到一个概率向量。