我按照Keras documentation page的说明更改了keras.json
文件。但在我的Ipython笔记本中,它仍然说我使用Tensorflow作为后端。将Keras后端更改为Ipython笔记本中的Theano
也许这是关系到Jupyter设置莫名其妙?请提供帮助。我甚至不知道如何找出问题的来源。谢谢!
我按照Keras documentation page的说明更改了keras.json
文件。但在我的Ipython笔记本中,它仍然说我使用Tensorflow作为后端。将Keras后端更改为Ipython笔记本中的Theano
也许这是关系到Jupyter设置莫名其妙?请提供帮助。我甚至不知道如何找出问题的来源。谢谢!
你可以尝试在笔记本开始执行以下操作:
import os
os.environ["KERAS_BACKEND"] = "theano"
import keras; import keras.backend
if keras.backend.backend() != 'theano':
raise BaseException("This script uses other backend")
else:
keras.backend.set_image_dim_ordering('th')
print("Backend ok")
基本上环境KERAS_BACKEND可以通过Jupyter某些时候会自动覆盖,所以这是迫使它要的东西你导入keras前一种方式。后端。
# When I executed the suggestion -- the output I got..
BaseExceptionTraceback (most recent call last)
<ipython-input-7-c4352a2d60e6> in <module>()
3 import keras; import keras.backend
4 if keras.backend.backend() != 'theano':
----> 5 raise BaseException("This script uses other backend")
6 else:
7 keras.backend.set_image_dim_ordering('th')
BaseException: This script uses other backend
- 不知道,这将如何帮助,如果我们不能够动态改变后端。
- 取而代之的是什么帮助我的是以下几点: How to switch Backend with Keras (from TensionFlow to Theano)
守则IPython的
from keras import backend; print(backend._BACKEND)
from keras import backend as K
import os
def set_keras_backend(backend):
if K.backend() != backend:
os.environ['KERAS_BACKEND'] = backend
reload(K)
assert K.backend() == backend
print ("Change Keras Backend to Theano")
set_keras_backend("theano")
from keras import backend; print(backend._BACKEND)
输出在IPython中
tensorflow
Change Keras Backend to Theano
theano
参见[这里](HTTP: //www.nodalpoint.com/switch-keras-backend/)。 –
谢谢@ ParagS.Chandakkar。但它不适用于我。当我做'keras.backend.backend()'时,它仍然会说'tensorflow'。也许我可以通过卸载tensorflow来解决问题? – user3768495
你有没有试过KERAS_BACKEND = theano jupyter notebook --no-browser --ip xxx.xxx.xxx.xxx?然后keras.backend.set_image_dim_ordering('tf') – maz