0

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'
Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
  • What version of tensorflow and jupyter are you using? – aerijman Aug 27 '20 at 17:56
  • Does [this post](https://stackoverflow.com/questions/41333798/attributeerror-module-tensorflow-has-no-attribute-interactivesession) answer you question ? – NoeXWolf Aug 27 '20 at 17:58
  • Let me know if it's solved using tensorflow v 1.13.2 – aerijman Aug 27 '20 at 18:00
  • Does this answer your question? [AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'](https://stackoverflow.com/questions/41333798/attributeerror-module-tensorflow-has-no-attribute-interactivesession) –  Aug 27 '20 at 19:12

1 Answers1

0

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