How to force Keras with TensorFlow back-end to run using either CPU or GPU in Python

The Keras module within TensorFlow will default to using any resources that are available. Specifying the device as CPU or GPU before running deep-learning code allows users to control whether Keras will run on CPU or GPU.

Solution for How to force Keras with TensorFlow back-end to run using either CPU or GPU in Python : You can use tf.device() to force Keras with TensorFlow back-end to run using either CPU or GPU Use tf.device(device_name) where device_name is a the name of the device to use within the desired context. For example, when device_name is “gpu:0”, the GPU core mapped to 0 will be used.


how-to-force-keras-with-tensorflow-back-end-to-run-using-either-cpu-or-gpu-in-python