ImportError: cannot import name abs from tensorflow.python.keras._impl.keras.backend
ImportError: cannot import name abs from tensorflow.python.keras._impl.keras.backend
Hi,
I was able to resolve this issue by removing all the tensorFlow and keras python3 packages from dist-packages dir itself , uninstalling using pip3 and then again installing tensorflow==1.8.0
tensorflow-gpu==1.8.0 , Keras==2.2.4
( The Potential reason which caused this specific erro was python referring multiple tensoflow-gpu,keras version packages files in dis-packages dir. Although installing a specific tensoflow-gpu,keras version via pip3 should ideally remove previous existing versions. But In my case that didnt occurred.)
Solution:
- Locate tensorflow , keras packages in dist-packages dir using
$ locate --basename tensorflow
command (provided you are using Ubuntu). In my case it is
$ locate –basename tensorflow
outputs –
/usr/local/lib/python3.5/dist-packages/tensorflow
/usr/local/lib/python3.5/dist-packages/tensorflow/include/tensorflow
/usr/share/nginx/html/projects/python/machine-learning/objectDetection/models-master/research/syntaxnet/tensorflow
&
$ locate –basename keras
outputs-
/usr/local/lib/python3.5/dist-packages/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/keras/api/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras
/usr/local/lib/python3.5/dist-packages/tensorflow/tools/api/generator/api/keras
/usr/share/nginx/html/projects/python/Playground/lambda/testkeras/keras
- Now that you are aware of the desired packages location. Simply remove the tensorflow and keras dirs and uninstall packages using below commands
Removing dirs
sudo rm -R /usr/local/lib/python3.5/dist-packages/tensorflow/
sudo rm -R /usr/share/nginx/html/projects/python/machine-learning/objectDetection/models-master/research/syntaxnet/tensorflow
sudo rm -R /usr/local/lib/python3.5/dist-packages/keras/
sudo rm -R /usr/share/nginx/html/projects/python/Playground/lambda/testkeras/keras
Uninstall using pip3
sudo pip3 uninstall tensorflow
sudo pip3 uninstall tensorflow-gpu
sudo pip3 uninstall keras
- Again Installing tensorflow, tensorflow-gpu ,keras
sudo pip3 install tensorflow==1.8.0
sudo pip3 install tensorflow-gpu==1.8.0
sudo pip3 install Keras==2.2.4