我在调试时如何在tensorflow中打印张量值

时间:2016-05-12 06:08:40

标签: tensorflow

功能:

def evaluation(logits, labels):

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

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

问题:

当我运行时,如何在张量“标签”或“logits”中打印值 代码如下:

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>

1 个答案:

答案 0 :(得分:3)

如果要在图表中打印张量,则需要使用Feed运行会话。

准备好feed_dict后尝试此操作。

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