diff options
author | Vijay Vasudevan <vrv@google.com> | 2016-09-24 16:10:58 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-09-24 17:17:39 -0700 |
commit | dd9f539860d783907b1cda83ac5b27d42e6019bc (patch) | |
tree | f59dca98e0f033afdd06a820aa5703cdf7842879 /tensorflow/examples/tutorials | |
parent | 9c6caa3afbd48c37db8700e6e5a22b4d32355f5f (diff) |
Fix mnist_softmax tutorial to define the InteractiveSession and
use it instead of using .eval() and .run().
Change: 134184723
Diffstat (limited to 'tensorflow/examples/tutorials')
-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() |