Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'tensorflow' has no attribute 'name_scope' with Keras

I am trying to run a script, but I struggle already at the imports. This import

from keras.preprocessing.image import save_img

raises the following error:

AttributeError: module 'tensorflow' has no attribute 'name_scope'.

I am using the following packages.

Keras                     2.2.2,                     
Keras-Applications        1.0.4,                   
Keras-Preprocessing       1.0.2,                   
tensorflow                1.9.0,                     
tensorflow-gpu            1.9.0                
like image 235
Henrik Avatar asked Aug 07 '18 10:08

Henrik


2 Answers

I was unable to reproduce with the same versions of the keras and tensorflow, reinstalling keras and tensorflow, may solve the issue, please use commands below:

pip install --upgrade pip setuptools wheel
pip install -I tensorflow
pip install -I keras

NOTE: The -I parameter stands for ignore installed package.

like image 56
Andriy Ivaneyko Avatar answered Nov 10 '22 23:11

Andriy Ivaneyko


For everyone who use Tensorflow 2.0 and stumble upon this question with the same error, like I did: I solved it by changing the imports from keras.xxx to tensorflow.keras.xxx

like image 4
zeyger Avatar answered Nov 10 '22 23:11

zeyger