Reputation: 1261
This is a beginner question on learning Tensorflow. I'm used to playing around machine learning models in interactive shell like Jupyter notebook. I understand tensorflow
adopts the lazy execution style, so I can't easily print tensors to check.
After some research, I found two work around: tf.InteractiveSession()
or tf.enable_eager_execution()
. From what I understand, both allow me to print variables as I write them. Is this correct? And is there a preference?
Upvotes: 0
Views: 571
Reputation: 112
When using tf.InteractiveSession() you are still in lazy execution. So you can't print variable values. You only can get to see symbols.
sess = tf.InteractiveSession()
a = tf.random.uniform(shape=(2,3))
print(a) # <tf.Tensor 'random_uniform:0' shape=(2, 3) dtype=float32>
When using tf.enable_eager_execution() you can get to see variable values.
tf.enable_eager_execution()
a = tf.random.uniform(shape=(2,3))
print(a) # prints out value
Upvotes: 1