【发布时间】:2017-02-26 12:58:01
【问题描述】:
我正在学习如何将 Tensorflow 与 MNIST 教程一起使用,但我在教程的某个要点上有所阻碍。
这里是提供的代码:
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
saver = tf.train.Saver()
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
但我实际上根本不明白变量“W”(权重)和“b”(偏差)在计算时是如何变化的? 在每批中,它们都初始化为零,但在 ? 我完全看不出他们将在代码中的哪些地方进行更改?
非常感谢您!
【问题讨论】:
标签: python python-3.x machine-learning tensorflow