0

I am going through the tensorflow tutorials (https://www.tensorflow.org/get_started/mnist/pros)

specifically:

with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  for i in range(20000):
    batch = mnist.train.next_batch(50)
    if i % 100 == 0:
      train_accuracy = accuracy.eval(feed_dict={
          x: batch[0], y_: batch[1], keep_prob: 1.0})
      print('step %d, training accuracy %g' % (i, train_accuracy))
    train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})

Everything up to this point runs perfectly. It completes the 20,000 steps of training. But then I get to this point:

  print('test accuracy %g' % accuracy.eval(feed_dict={
      x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0})) 

and this happens:

>>>  print('test accuracy %g' % accuracy.eval(feed_dict={
  File "<stdin>", line 1
    print('test accuracy %g' % accuracy.eval(feed_dict={
    ^
IndentationError: unexpected indent
>>>      x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
  File "<stdin>", line 1
    x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))

Now if I try and change the spacing, and print the final accuracy separately from the for loop, I get something even more unpleasant:

 print('test accuracy %g' % accuracy.eval(feed_dict={
...     x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
Traceback (most recent call last):
 ...

tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value Variable_12

Not really sure what's going on. Any suggestions or feedback would be greatly appreciated.

Thank you

  • It looks like you're using a 2-space indent convention in your first code block, but then you change to 4-space indent when you get the error. If you think you fixed the indentation and you're still getting an error, I'd suggest updating your post with the current indentation you're using (and use consistent indentation), and then post the Traceback. That'll make it easier to figure out what the problem is. – andrew_reece Nov 04 '17 at 06:03
  • You should name your variables to find it easier. Right now I can say that `Variable_12` is 12-th defined variable in your script. – Maxim Nov 04 '17 at 12:32
  • I am copying the code exactly as it is on the website and when I run it, it gives the indentation error. If I try and manual rearrange the last line to avoid the indentation error, i get this rather long error that is too long to post. – Sempronius Nov 04 '17 at 18:11
  • tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value Variable_2 [[Node: Variable_2/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_2"], _device="/job:localhost/replica:0/task:0/gpu:0"](Variable_2)]] [[Node: Mean_2/_23 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_79_Mean_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] – Sempronius Nov 04 '17 at 18:11
  • The above error message is part of what I see. And it repeats this same error 3 times. – Sempronius Nov 04 '17 at 18:12
  • Take a look at the website, all the variables have names. https://www.tensorflow.org/get_started/mnist/pros – Sempronius Nov 04 '17 at 18:13
  • Well, I got it working by just running the file from the command line after reinstalling everything and verifying installation with the file from tensorflow tutorial https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c . I'm not sure why that made a difference. – Sempronius Nov 04 '17 at 20:52

0 Answers0