Trouble running tf.InteractiveSession() in Jupyter

566 views Asked by At

I am having trouble running tf.InteractiveSession() in Jupyter and I am not sure how to amend it. I am a beginner so I would appreciate some guidance!

Inputting this code here:

import tensorflow as tf
sess = tf.InteractiveSession()

x = tf.constant([[1, 2]])
negMatrix = tf.negative(x)

result = negMatrix.eval()
print(result)

sess.close()

Produces this error message:

**AttributeError**: module 'tensorflow' has no attribute 'InteractiveSession'
1

There are 1 answers

0
AudioBubble On

Using Tensorflow 2.6.0. you can import tf.compat.v1.InteractiveSession()

Sample working code below

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()

Output

30.0