ObiWan
ObiWan

Reputation: 196

How do I use TensorFlow backend in keras without changing keras.json?

Well, I am working on a GPU server. All other users are using keras with Theano backend.

I have installed TensorFlow using virtualenv and later I installed keras using usual pip command. When I try to run keras in this virtual environment, it is using Theano backend because of the /home/user/.keras/keras.json file. I know I can use TensorFlow by making changes in the json file but for some reason other users are not allowing this.

I would like to know if there is a way to use keras with TensorFlow installed in my virtual environment other than the globally installed "Theano".

NOTE: The other users still should be able to use Theano

OS: Ubuntu 16.04

Upvotes: 1

Views: 3063

Answers (2)

ObiWan
ObiWan

Reputation: 196

Using @GPhilo documentation reference;

I successfully used TensorFlow backend by adding following lines at the starting of my code:

import os
os.environ['KERAS_BACKEND'] = 'tensorflow'
# rest of the code

Make sure you have activated your virtual environment.

Upvotes: 2

GPhilo
GPhilo

Reputation: 19123

From Keras' documentation:

You can also define the environment variable KERAS_BACKEND and this will override what is defined in your config file :

KERAS_BACKEND=tensorflow python -c "from keras import backend" Using TensorFlow backend.

Upvotes: 1

Related Questions