问题
1- I create a virtual env: mkvirtualenv kerasTH
2- I install keras using pip install keras
3- That's the output for pip list
Package Version
------------- -------
h5py 2.10.0
joblib 0.16.0
Keras 2.4.3
numpy 1.19.1
Pillow 7.2.0
pip 20.2.2
PyYAML 5.3.1
scikit-learn 0.23.2
scipy 1.5.2
setuptools 49.6.0
six 1.15.0
Theano 1.0.5
threadpoolctl 2.1.0
wheel 0.35.1
When I run python
and then import keras
I get this error ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
I edited the .keras/keras.json
file to have the following:
{
"image_dim_ordering": "th",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "theano"
}
I used
import os
os.environ['KERAS_BACKEND'] = 'theano'
Used KERAS_BACKEND='theano' python script.py
but I am still getting the same error. Not sure how to switch to theano, any suggestions ?
OS: Ubuntu 20.04 Python 3.8.2 pip 20.2.2 CUDA Version: 11.0
回答1:
Keras 2.4 is actually just a wrapper on top of tf.keras
, meaning that it does not support multiple backends, only the TensorFlow backend.
So you would need to use Keras 2.3, which does still support multiple backends.
来源:https://stackoverflow.com/questions/63587843/keras-isnt-using-theano