It seems that in Tensorflow, there are at least three methods to print out the value of a tensor. I've been reading here and there, yet still very confused.
These authors seem to summarize the different usage as:
- Python
print
: can only print out certain attributes of a tensor, e.g. its shape, because outside the computation graph it's merely an operation. tensor.eval()
: Not sure its difference withtf.print()
tf.print()
: can output the actual value of a tensor, but must be inserted somewhere in the graph as well as being used by some other operation otherwise it will be dangling and still not printed.
My confusion probably also lies in I'm not sure how much Python functionalities we can access in a tensorflow computation graph, or where the computation graph "ends" and Python code "begins". e.g.
- If I insert a Python print between two lines where I construct a computation graph, when I call
sess.run()
later, will this line be called? - If I want to print out multiple tensor values in a computation graph, where should I put these statements?
- What's the difference between
tensor.eval()
andtf.print()
? How should I use them differently?