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).
However, when I import Keras, it only uses the TensorFlow backend even after I changed the values in the Keras configuration file:
~ $ 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:
~ $ 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. Anyone know how to set it as such?
EDIT:
To answer @Marcin Możejko 's question:
~ $ which python
/Users/<my name>/anaconda/envs/ENVPy3/bin/python
Which is the conda virtual environment that Keras is installed in as well.
Same issue here, system setup:
The only way to change backend is to use KERAS_BACKEND environment variable. Json field is ignored.
EDIT:
The issue is Anaconda, open 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.
I have no idea who creates this file, keras or anaconda, and the reasoning behind this forcing. I'm just ignoring it and doing my own way:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With