0

This is code from the MNIST tutorial:

correct_prediction = tf.equal(tf.argmax(y, 1), y_)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(
  accuracy, feed_dict={
      x: mnist.test.images,
      y_: mnist.test.labels
  }))

I modelled this for my own neural network:

print(batch_ys.shape)  
correct_prediction = tf.equal(y, float_y_)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(
  accuracy, feed_dict={
      x: batch_test_x,
      y_: batch_ys
  }))

I get an error on the "y_: batch_ys" line saying "TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a int into a Tensor."

The first print statement in my code was to debug this which successfully prints out (2, 11, 1), which is clearly a tensor. Any ideas?

Any help will be greatly appreciated, thanks in advance.

1 Answers1

0
logging_hook = tf.train.LoggingTensorHook({"loss" : loss, 
    "accuracy" : accuracy}, every_n_iter=10)



return tf.estimator.EstimatorSpec(
    ...params...
    training_hooks = [logging_hook])

To see the output you have to set logging

tf.logging.set_verbosity(tf.logging.INFO)

check this answer

Ashfaque Ali Solangi
  • 1,883
  • 3
  • 22
  • 34
  • This does not help me as I am not trying to print any extra training metrics...I still do not know why my code doesn't work despite it being just like the MNIST tutorial's code, and why I get such an odd error. – Arjun Gupta Mar 10 '18 at 03:11