配置Keras以使用Tensorflow而不是Theano [英] Configuring Keras to use Tensorflow instead of Theano
问题描述
我正在尝试在Anaconda virtualenv下配置Keras安装,并在Ubuntu 17.04下运行所有安装.我已经通过conda
安装了keras-gpu
,并通过运行python -c 'import keras'
生成了一个引导~/.keras
目录;最后,我已经在该目录中更新了keras.json
,将tensorflow
作为后端而不是theano
.
I'm trying to configure Keras install under an Anaconda virtualenv with all of that running under Ubuntu 17.04. I've installed keras-gpu
via conda
, and have generated a bootstrap ~/.keras
directory by running python -c 'import keras'
; finally, I've updated my keras.json
within that directory to include tensorflow
as the backend rather than theano
.
我还尝试使用conda
上可用的常规非GPU keras
进行这些步骤.
I've also tried those steps with the regular, non-GPU keras
available on conda
.
我遇到的问题是,我的keras.json
中的backend
选项正在读取(因为无效值引发异常),但是被Anaconda本身获取export
的环境变量所取代- -根据grep
,有以下几种情况:
The issue I'm getting is that the backend
option in my keras.json
is being read (since invalid values raise exceptions), but is being overruled by an environment variable that gets export
ed by Anaconda itself -- according to grep
, there are a few instances of:
export KERAS_BACKEND=tensorflow
export KERAS_BACKEND=theano
...散布在~/miniconda3/pkgs/keras-2.0.2-py36_1/
中的许多文件中.
... Scattered around a number of files in ~/miniconda3/pkgs/keras-2.0.2-py36_1/
.
由于文件包管理器会自动将这些文件放到这里,因此我不愿意手动编辑这些文件,但我也想避免在每个会话开始时明确指定KERAS_BACKEND=tensorflow
,并且我想避免使用解决方案涉及到direnv
之类的工具.
I'm hesitant to manually edit these files since they're automatically put there by the package manager, but I also want to avoid explicitly specifying KERAS_BACKEND=tensorflow
at the start of each session, and I'd like to avoid solutions involving tools like direnv
.
如何让conda
的keras
默认使用tensorflow
?
推荐答案
The problem is probably in the file activate.sh
of the keras package on conda-forge. The export
statements in this file are unnecessary and should be removed IMO. There's just no reason to restrict linux users to use theano as Keras backend (or TensorFlow for Mac OSX).
#!/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 could solve the problem by:
- 从activate.sh中删除这些环境设置.
- 删除当前安装的
keras
和keras-gpu
,然后 用conda install -c defaults keras
安装keras: 非conda-forge版本的keras似乎还可以.我的机器上没有找到任何这些环境设置. -
pip install keras
:删除当前安装的keras
和keras-gpu
,然后仅安装python软件包.
- Removing those environment settings from activate.sh.
- Removing currently installed
keras
andkeras-gpu
, and then install keras withconda install -c defaults keras
: the non-conda-forge version of keras seems to be okay. I didn't find any of those env settings on my machine. pip install keras
: removing currently installedkeras
andkeras-gpu
, and then install the python package only.
这篇关于配置Keras以使用Tensorflow而不是Theano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!