Search code examples
tensorflowanacondakerastheano

How to permanently set Tensorflow as Keras primary backend?


I have installed Tensorflow and Keras by Anaconda (Conda Forge's packages) on Windows. This kind of installation has set Theano as primary backend, so I have checked the keras.json file, surprisingly it has set Tensorflow as the main backend. Furthermore, if I try to remove Theano's installation, Keras stop working. I am supposing that each time I run Keras, it override the json file. How could I permanently set Tensorflow as primary backend?


Solution

  • In Windows, Try launching the Anaconda prompt from start -> Anaconda* -> Anaconda prompt

    *Anaconda followed by your version, for me it is Anaconda3 (64-bit)

    Check whether you can see the below as the first line

    set "KERAS_BACKEND=theano"

    In this case, by default you can go to the below directory (If you have set a custom install directory you might have to navigate there)

    C:\Users\yourusername\AppData\Local\Continuum\Anaconda3\etc\conda\activate.d

    and open the keras_activate batch file using notepad

    Inside the file edit the line saying

    set "KERAS_BACKEND=theano" to set "KERAS_BACKEND=tensorflow"

    You are set to use Keras with tensorflow backend.