Keras: Keras only lets me use Theano backend

Created on 10 Jun 2017  路  14Comments  路  Source: keras-team/keras

Despite that in the keras.jason file the backend is set to tensorflow, each time that I activate my tensorflow environment the backend is set to theano.

C:UsersUrielAnaconda3Scripts>activate tensorflow

(tensorflow) C:UsersUrielAnaconda3envstensorflowetccondaactivate.d>set "KERAS_BACKEND=theano"

writing set "KERAS_BACKEND=tensorflow" does nothing.

Please, help me to set the backend to tensorflow.

Most helpful comment

@gitathrun I encounted exactly same problem.

"deleting files in <your_conda_path>/envs/<your_env>/etc/activate.d" really pulls me out.

All 14 comments

Keras Backend documentation shows you how change backend.
In your $HOME/.keras/keras.json file got "backend": "theano" section. If you change theano with tensorflow, your problem will fixed.

In the keras.json file the backend is already set to "tensorflow", so this doesn't fix the issue.

Run KERAS_BACKEND=tensorflow python command with Terminal. After run import keras; keras.backend.backend(). You must see tensorflow?

Can you use TensorFlow with python? Are you sure you install TensorFlow right?

I can use tensorflow and as I mentioned in the original message the command "set KERAS_BACKEND=tensorflow" doesn't fix this either.

I got that problem as well, I just delete the file in the activate.d folder, and everything back to normal. It seems if you want to run another keras session under the same env, the env will automatically change your setting in the activate.d folder, not sure why, but that is what I have encountered.

@gitathrun I encounted exactly same problem.

"deleting files in <your_conda_path>/envs/<your_env>/etc/activate.d" really pulls me out.

I edited the file /home/user/anaconda2/envs/tfpy36/etc/conda/activate.d/keras_activate.sh and changed theano to tensorflow. When I reactivated the env and imported Keras was using Tensorflow as backend

I've got the same problem, which I'm able to fix typing KERAS_BACKEND=tensorflow.
I'd love to fix it once and forever, but I can't even find any activate.d directory or a keras_activate.sh file :(

So I just export KERAS_BACKEND=tensorflow in my .bashrc and I can work.

import tensorflow
KERAS_BACKEND=tensorflow
import keras

??

worked for me

As said by @gitathurn, go to your conda environment and change activate.d file. In my case
~/anaconda2/envs/keras35/etc/conda/activate.d/keras_activate.sh
Within that change the export KERAS_BACKEND=tensorflow also for the linux.

To those that are still struggling with this I found the "activate.d" folder at /envs/etccondaactivate.d
There was only one .bat file which only had one command in it: Exactly the one that was setting the backend whenever I activated my Anaconda environment. Deleting that bat file resolved the issue for me.

Closing as this is resolved

what i i did was conda remove tensorflow , conda remove keras and then conda install -c conda-forge keras

Was this page helpful?
0 / 5 - 0 ratings