【发布时间】:2017-01-21 18:48:26
【问题描述】:
我是 Tensorflow 的新手,我不明白为什么输入占位符的尺寸通常与用于训练的批次大小一致。
在这个例子中我找到了here,而在官方 Mnist 教程中却不是
from get_mnist_data_tf import read_data_sets
mnist = read_data_sets("MNIST_data/", one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder("float", shape=[None, 784])
y_ = tf.placeholder("float", shape=[None, 10])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
sess.run(tf.initialize_all_variables())
y = tf.nn.softmax(tf.matmul(x,W) + b)
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
for i in range(1000):
batch = mnist.train.next_batch(50)
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, "float"))
print(accuracy.eval(feed_dict={x: mnist.test.images,
y_: mnist.test.labels}))
那么,对模型输入进行标注和创建模型输入并进行训练的最佳和正确方法是什么?
【问题讨论】:
-
形状是可选的,但指定形状可以帮助底层系统选择最有效的实现
标签: python machine-learning tensorflow deep-learning