yinhua.hui
yinhua.hui

Reputation: 35

How to print the value of a tensor in tensorflow when i was debugging

Function:

def evaluation(logits, labels):

     correct = tf.nn.in_top_k(logits, labels, 1)

     return tf.reduce_sum(tf.cast(correct, tf.int32))

end

Question:

How to print the value in the tensor "labels" or "logits",when i run the code as follow:

python -m pdb    fully_connected_feed.py
fully_connected_feed.py(16)<module>()
-> """Trains and Evaluates the MNIST network using a feed dictionary."""
(Pdb) b network.py:194
Breakpoint 1 at network.py:194
(Pdb) c
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA     library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally
network.py(194)evaluation()
-> correct = tf.nn.in_top_k(logits, labels, 1)
(Pdb) logits
<tf.Tensor 'softmax_linear/add:0' shape=(100, 4382) dtype=float32>

Upvotes: 1

Views: 2569

Answers (1)

Jin
Jin

Reputation: 714

When you want to print the tensor in the graph, you need to run the session with feed.

Try this after you get feed_dict ready.

print( sess.run( logits, feed_dict=feed_dict) )

Upvotes: 3

Related Questions