Change keras backend from theano to tensorflow?

Can someone explain how to replace theano with tensorflow as the keras backend?
I have searched the forum and can find no clear explanation.

Here is the current contents of my ~/.keras/keras.json file:
“floatx”: “float32”,
“epsilon”: 1e-07,
“backend”: “tensorflow”,
“image_data_format”: “channels_last”
“image_dim_ordering”: “tf”

But when I try to import keras, I get an error and it says (among other things)
“Using theano backend”

Many thanks!


1 Like

Are you using conda environment?

Yes using conda

In your folder where envs are stored, go to your environment and find the folder etc/conda/activate.d. Go to the file and change the back end appropriately.

1 Like

Thanks for your reply @srib

I cannot find the file


Could you please explain:
How can I find the folder where envs are stored?
What does it mean to ‘go to your environment’?


Answering my own question to @srib , so that it might be clearer to anyone with the same issue:

To find where conda stores environments,
conda info --envs

And the command returned

conda environments:

fastai * /home/paperspace/anaconda3/envs/fastai
root /home/paperspace/anaconda3

cd into /home/paperspace/anaconda3/envs/fastai

cd into etc/conda

As @srib said, this directory contains the the activate.d folder
which contains the

Edit the line that sets the keras backend to read:


This worked.

Thanks again, @srib!