When using keras to build a neural network, I encountered the following problems:
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
Encountered this problem because tensorflow and keras versions conflict, then we need to know the corresponding versions of tensorflow and keras.
corresponding version
The following is the keras version corresponding to TF1 and TF2
Framework | Env name (–env parameter) | Description | Docker Image Packages and Nvidia Settings | |
TensorFlow 2.2 | tensorflow-2.2 | TensorFlow 2.2.0 + Keras 2.3.1 on Python 3.7. floydhub/tensorflow | TensorFlow-2.2 | |
TensorFlow 2.1 | tensorflow-2.1 | TensorFlow 2.1.0 + Keras 2.3.1 on Python 3.6. | floydhub/tensorflow | TensorFlow-2.1 |
TensorFlow 2.0 | tensorflow-2.0 | TensorFlow 2.0.0 + Keras 2.3.1 on Python 3.6. floydhub/tensorflow | TensorFlow-2.0 | |
TensorFlow 1.15 | tensorflow-1.15 | TensorFlow 1.15.0 + Keras 2.3.1 on Python 3.6. floydhub/tensorflow TensorFlow-1.15 | ||
TensorFlow 1.14 | tensorflow-1.14 | TensorFlow 1.14.0 + Keras 2.2.5 on Python 3.6. floydhub/tensorflow TensorFlow-1.14 | ||
TensorFlow 1.13 | tensorflow-1.13 | TensorFlow 1.13.0 + Keras 2.2.4 on Python 3.6. floydhub/tensorflow TensorFlow-1.13 | ||
TensorFlow 1.12 | tensorflow-1.12 | TensorFlow 1.12.0 + Keras 2.2.4 on Python 3.6. floydhub/tensorflow TensorFlow-1.12 |
locally installed version
Get the version of keras
import keras
keras.__version__
Get the version of tensorflow
import tensorflow
tensorflow.__version__
uninstall
uninstall keras
pip uninstall keras
pip uninstall tensorflow
Install the corresponding version
如Python 3.6,需要安装TensorFlow 1.12.0 + Keras 2.2.4
pip install keras==2.2.4
pip install tensorflow==1.12
Solve the corresponding problem! ! !