Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Keras backend (where's the json file)?

I have installed Keras, and wanted to switch the backend to Theano. I checked out this post, but still have no idea where to put the created json file. Also, below is the error I got when running import keras in Python Shell:

Using TensorFlow backend.

Traceback (most recent call last): File "", line 1, in import keras File "C:\Python27\lib\site-packages\keras__init__.py", line 2, in from . import backend File "C:\Python27\lib\site-packages\keras\backend__init__.py", line 64, in from .tensorflow_backend import * File "C:\Python27\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in import tensorflow as tf ImportError: No module named tensorflow

When running python -c "import keras; print(keras.__version__)" from Windows command line, I got:

Using TensorFlow backend. Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\keras__init__.py", line 2, in from . import backend File "C:\Python27\lib\site-packages\keras\backend__init__.py", line 64, in from .tensorflow_backend import * File "C:\Python27\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in import tensorflow as tf ImportError: No module named tensorflow

Can someone please help? Thanks!

like image 227
George Liu Avatar asked Oct 28 '16 17:10

George Liu


People also ask

Where is Keras JSON file located?

Once we execute keras, we could see the configuration file is located at your home directory inside and go to . keras/keras. json.

Where is the Keras configuration file stored?

keras/datasets/ , and cached model weights files from Keras Applications are stored by default in $HOME/. keras/models/ .

What is the Keras backend?

What is a "backend"? Keras is a model-level library, providing high-level building blocks for developing deep learning models. It does not handle itself low-level operations such as tensor products, convolutions and so on.


2 Answers

In case of Ubuntu,the following worked for me:

The '.keras' folder is present in your home directory,but is hidden.So,you need to unhide the hidden files in your home directory. You can see the hidden files in Ubuntu by

  • View-> show hidden files or
  • pressing ctrl+H.

You can now see the '.keras' folder in your home directory.Inside that folder,you will see the 'keras.json' file which you can modify to switch the keras backend to theano according to the official documentation https://keras.io/backend/

like image 36
rojan sudev Avatar answered Sep 21 '22 15:09

rojan sudev


After looking at keras sources (this place):

Start up your python-binary and do the following

import os print(os.path.expanduser('~')) # >>> C:\\Users\\Sascha'  # will look different for different OS 
  • This should be the base-directory
  • Keras will build an folder .keras there where keras.json resides (if it was already created). If it's not there, create it there
  • Example: C:\\Users\\Sascha\\.keras\\keras.json'
like image 116
sascha Avatar answered Sep 24 '22 15:09

sascha