How to switch Backend with Keras (from TensorFlow to Theano)

DaniPaniz picture DaniPaniz · Feb 11, 2017 · Viewed 74.5k times · Source

I tried to switch Backend with Keras (from TensorFlow to Theano) but did not manage. I followed the temps described here but it doesn't work. I created a keras.json in the keras' directory (as it did not exist) but it doesn't change anything when I import it from Python.

Answer

nemo picture nemo · Feb 11, 2017

Create a .keras (note the . in front) folder in you home directory and put the keras.json file there.

For example, /home/DaniPaniz/.keras/keras.json (or ~/.keras/keras.json in short) if you are on a UNIX like system (MacOS X, Linux, *BSD). On Windows you want to create the folder %USERPROFILE%/.keras and put the JSON file there.

Alternatively, you can also set the environment variable KERAS_BACKEND:

KERAS_BACKEND=theano python mymodel.py