def build_graph(reuse):
with tf.variable_scope('model', reuse=reuse):
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
keep_prob = tf.placeholder(tf.float32)
y_conv = forward(x, keep_prob)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
num_correct = tf.reduce_sum(tf.cast(correct_prediction, tf.float32))
no_op = tf.no_op()
return x, y_, keep_prob, train_step, num_correct, no_op
评论列表
文章目录