Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have installed tensorflow from Source on Ubuntu 16.10 environment. Everything went smooth but now on compiling a program, it shows the following error:

Traceback (most recent call last):
  File "ff.py", line 3, in <module>
    sess = tf.InteractiveSession()
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

Didn't find any post related to this. Could someone please help?

like image 611
Saurav-- Avatar asked Dec 26 '16 16:12

Saurav--


2 Answers

sess=tf.compat.v1.InteractiveSession()

Use above line instead of sess = tf.InteractiveSession() line, if you are using tesorflow 2.0.0 version

like image 164
Risith Ratan Patra Avatar answered Oct 02 '22 00:10

Risith Ratan Patra


The error causes from Tensorflow version. When you've install v2.x and try to use v1.x, you'll get this error. To avoid this,

import tensorflow as tf
import tensorflow.compat.v1 as tfc

Use tfc instead of tf when you get the same error on the other functions like:

sess = tfc.InteractiveSession()

my_tensor = tfc.random_uniform((4, 4), 0, 1)
print(my_tensor)
like image 33
Oguzhan Bolukbas Avatar answered Oct 02 '22 01:10

Oguzhan Bolukbas