diff options
-rw-r--r-- | tensorflow/examples/tutorials/mnist/mnist_softmax.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tensorflow/examples/tutorials/mnist/mnist_softmax.py b/tensorflow/examples/tutorials/mnist/mnist_softmax.py index 8b469fd9d1..1791f97a06 100644 --- a/tensorflow/examples/tutorials/mnist/mnist_softmax.py +++ b/tensorflow/examples/tutorials/mnist/mnist_softmax.py @@ -56,16 +56,18 @@ def main(_): cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_)) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) + sess = tf.InteractiveSession() # Train tf.initialize_all_variables().run() for _ in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) - train_step.run({x: batch_xs, y_: batch_ys}) + sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) # Test trained model 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({x: mnist.test.images, y_: mnist.test.labels})) + print(sess.run(accuracy, feed_dict={x: mnist.test.images, + y_: mnist.test.labels})) if __name__ == '__main__': parser = argparse.ArgumentParser() |