TensorFlow,实现解决方案



我是Python,机器学习和TensorFlow的新手,感到非常不知所措!

我仍在处理 MNIST 数据集,并有以下代码(我从 TensorFlow 教程中遵循了这些代码(:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data',one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape = [None,784])
y_ = tf.placeholder(tf.float32, shape = [None,10])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
sess.run(tf.global_variables_initializer())
y = tf.matmul(x,W) + b
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y,y_))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
for i in range(10):
    batch = mnist.train.next_batch(100)
    train_step.run(feed_dict={x: batch[0], y_: batch[1]})
    correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    print(accuracy.eval(feed_dict={x: mnist.test.images, y_:mnist.test.labels}))

我的问题是,从这里开始,如何提取解决方案以制作可用的应用程序?我的意思是,我如何进入一个阶段,我可以给它一个图像,并根据MNIST数据集的训练得到一个数字的预测。

非常感谢

使用您的代码,它应该像这样工作:

test_prediction = y.eval(feed_dict={x: mnist.test.images})

如果你想拥有"你自己的图像",你必须确保它们与你的mnist.test.images变量的格式相同。在这种情况下,您可以将上述代码中的 mnist.test.images 替换为任何填充有长度为 787 的数组(图像为 28 x 28 像素(的 Numpy 数组。如果这有效,请告诉我!

相关内容

最新更新