[英]keras ignoring values in $HOME/.keras/keras.json file
I know the default backend for Keras has switched from Theano to TensorFlow, but with the dev version of Theano I can train on the GPU with OpenCL (I have an AMD card). 我知道Keras的默认后端已经从Theano切换到TensorFlow,但是使用开发版本的Theano,我可以使用OpenCL在GPU上进行训练(我有一张AMD卡)。
However, when I import Keras, it only uses the TensorFlow backend even after I changed the values in the Keras configuration file : 但是,当我导入Keras时, 即使我更改了Keras配置文件中的值 ,它也仅使用TensorFlow后端:
~ $ cat $HOME/.keras/keras.json
{"epsilon": 1e-07, "floatx": "float32", "backend": "theano"}
~ $ python -c 'import keras'
Using TensorFlow backend.
~ $ KERAS_BACKEND=theano python -c 'import keras'
Using Theano backend.
Mapped name None to device opencl0:2: AMD Radeon R9 M370X Compute Engine
In addition, I know that Keras is reading the configuration file after import because if I fill some non-valid value for "backend"
I get an error: 另外,我知道Keras在导入后正在读取配置文件,因为如果我为"backend"
填充一些无效值,我会收到错误:
~ $ cat $HOME/.keras/keras.json
{"epsilon": 1e-07, "floatx": "float32", "backend": "foobar"}
~ $ python -c 'import keras'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/antalek/anaconda/envs/ENVPy3/lib/python3.5/site-packages/keras/__init__.py", line 3, in <module>
from . import activations
File "/Users/antalek/anaconda/envs/ENVPy3/lib/python3.5/site-packages/keras/activations.py", line 3, in <module>
from . import backend as K
File "/Users/antalek/anaconda/envs/ENVPy3/lib/python3.5/site-packages/keras/backend/__init__.py", line 34, in <module>
assert _backend in {'theano', 'tensorflow'}
AssertionError
System details: 系统细节:
I would like to have Keras use Theano as the default backend. 我想让Keras使用Theano作为默认后端。 Anyone know how to set it as such? 有谁知道如何设置它?
EDIT: 编辑:
To answer @Marcin Możejko 's question: 要回答@MarcinMożejko的问题:
~ $ which python
/Users/<my name>/anaconda/envs/ENVPy3/bin/python
Which is the conda virtual environment that Keras is installed in as well. 这也是Keras安装的conda虚拟环境。
Same issue here, system setup: 同样的问题,系统设置:
The only way to change backend is to use KERAS_BACKEND environment variable. 更改后端的唯一方法是使用KERAS_BACKEND环境变量。 Json field is ignored. Json字段被忽略。
EDIT: The issue is Anaconda, open anaconda3/envs/ENV-NAME/etc/conda/activate.d/keras_activate.sh
编辑:问题是Anaconda,打开anaconda3/envs/ENV-NAME/etc/conda/activate.d/keras_activate.sh
#!/bin/bash
if [ "$(uname)" == "Darwin" ]
then
# for Mac OSX
export KERAS_BACKEND=tensorflow
elif [ "$(uname)" == "Linux" ]
then
# for Linux
export KERAS_BACKEND=theano
fi
You'll see that tensorflow is forced for MAC, and Theano for Linux. 您将看到强制MAC的张量流和Linux的Theano。
I have no idea who creates this file, keras or anaconda, and the reasoning behind this forcing. 我不知道是谁创建了这个文件,keras或anaconda,以及这种强制背后的原因。 I'm just ignoring it and doing my own way:) 我只是无视它并按自己的方式行事:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.