Keras is a model-level library that offers high-level building blocks helpful in developing deep-learning models. It handles low-level operations indirectly. For these tasks, Keras relies on well-specialized and highly optimized backend engines. The problems are addressed through modules by adding several backend engines to Keras.
The following are three widely used backend implementations:
TensorFlow: An open-source deep learning framework developed by Google. You can learn about Tensorflow here.
Theano: A numerical computation library developed by the University of Montreal.
CNTK: An open-source deep learning toolkit developed by Microsoft.
By default, Keras is configured with a TensorFlow backend. You can locate and inspect the Keras configuration file to check the backend being used.
$~/.keras/keras.json
The configuration file looks like this:
{"image_data_format": "channels_last","epsilon": 1e-07,"floatx": "float32","backend": "tensorflow"}
To change the Keras backend, you can modify the backend
field in the configuration file to either "theano"
, "tensorflow"
, or "cntk"
. Keras will then use the updated configuration while running any code.
keras.json
file: image_data_format
: This determines the data format convention followed by Keras. It is a string that takes one of the two values: "channels_last"
or "channels_first"
.
epsilon
: This refers to a float, a numeric constant that avoids zero division in some operations.
floatx
: This is a string, which can take values: "float16"
, "float32"
, or "float64"
.
backend
: This is a string, "tensorflow"
, "theano"
, or "cntk"
.
set_epsilon()
functionThis function sets the
from keras import backend as KK.epsilon()K.set_epsilon(1e-02)print(K.epsilon())
set_floatx()
functionThis function sets the floating-point precision for tensor computations. It specifies the data type of floating-point numbers.
from keras import backend as KK.set_floatx('float16')print(K.floatx())
backend()
functionThis function is used to return an instance of the current backend being used for the execution of the low-level operations and computations required for training and running deep learning models.
from keras import backend as Kprint(K.backend())
In Keras, the backend refers to the computational engine executing operations and computations in deep learning models. The backend configuration determines which computational engine runs numeric expressions in Keras, providing flexibility and compatibility with different frameworks.
Note: For further information on Keras, take a look at these resources:
How to install Keras in Anaconda
Free Resources