
Keras installation and configuration
At this point, the environment is ready for Keras installation. If all the dependencies and the backend engine have been correctly installed, we can proceed. Actually, the work that remains to be done is very simple and immediate.
There are two ways to install Keras as follows:
The first step involves the use of the Python Package Index (PyPI).
This is a repository of software for the Python programming language. PyPI helps you find and install software developed and shared by the Python community. This is the recommended option.
After installing the PyPI package, simply type the following command:
$ sudo pip install keras
If you are using a virtualenv, you may want to avoid using sudo:
$ pip install keras
Alternatively, we can install Keras from the GitHub source. To do this, we first need to clone Keras using git:
$ git clone https://github.com/keras-team/keras.git
Then, add cd to the keras folder and run the install command:
cd keras
sudo python setup.py install
We have the Keras environment available to implement our deep learning models. Let us look at some more information about the configuration. As we have already mentioned, Keras uses TensorFlow as the default backend. If we want to use the other two options, Theano and CNTK, we must modify the Keras configuration file. This is a file with the .json extension, and is named keras.json..
The file's position depends on the operating system that is in use in our PC:
$ HOME/.keras/keras.json
We can use the following command for Unix-like OSes:
%USERPROFILE%/.Keras/keras.json
And, for Windows OS, the contents of the configuration file are of the following type:
{
"image_data_format": "channels_last",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
The parameters have the following meaning:
- image_data_format: String, either channels_last or channels_first. It specifies which data format convention Keras will follow.
- epsilon: Float, a numeric fuzzing constant used to avoid dividing by zero in some operations.
- floatx: String, float16, float32, or float64. Default float precision.
- backend: String, tensorflow, theano, or cntk.
Switching from one backend to another is very fast. Simply change the field backend to theano, tensorflow, or cntk, and Keras will use the new configuration the next time you run any Keras code.