What is Keras backend?

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 enginesThe 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.

Switching Keras backend

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
keras.json file path

The configuration file looks like this:

{
"image_data_format": "channels_last",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
keras.json file content

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.

Details of 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".

Functions supported by backend

The set_epsilon() function

This function sets the fuzz factor valueA small value used to prevent computational unstability. used in numeric expressions.

from keras import backend as K
K.epsilon()
K.set_epsilon(1e-02)
print(K.epsilon())

The set_floatx() function

This function sets the floating-point precision for tensor computations. It specifies the data type of floating-point numbers.

from keras import backend as K
K.set_floatx('float16')
print(K.floatx())

The backend()function

 This 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 K
print(K.backend())

Conclusion

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:

Keras vs. TensorFlow

How to use Keras in Anaconda

How to install Keras in Anaconda

How to merge two different models in Keras

How to perform one-hot ezoding using Keras

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved