问题
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.
I've also tried those steps with the regular, non-GPU keras available on conda.
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 exported by Anaconda itself -- according to grep, there are a few instances of:
export KERAS_BACKEND=tensorflow
export KERAS_BACKEND=theano
... Scattered around a number of files in ~/miniconda3/pkgs/keras-2.0.2-py36_1/.
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.
How can I get conda's keras to use tensorflow by default?
回答1:
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:
- Removing those environment settings from activate.sh.
- Removing currently installed
kerasandkeras-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 installedkerasandkeras-gpu, and then install the python package only.
来源:https://stackoverflow.com/questions/46572361/configuring-keras-to-use-tensorflow-instead-of-theano