0

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?

F.S.
  • 1,175
  • 2
  • 14
  • 34

1 Answers1

1

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
Srikar
  • 112
  • 1
  • 7