Keras If you are using the Theano back end, you should automatically do not use the GPU only CPU, start the GPU using Theano internal command.
For the TensorFlow back end Keras and TensorFlow will automatically use the visible GPU, and I need it to run only on the CPU. Three methods were found on the web, and the last one was useful to me, but the following records were also made for three: using TensorFlow with Tf.device ('/cpu:0 '): function. The simple operation is to put all the commands in the domain described above. To declare a session's parameters using TensorFlow:
For some of the parameter settings in the session in TensorFlow, and Keras how to set the session of the tensorflow that it calls, see Keras set GPU usage memory size (TensorFlow backend).
For TensorFlow, add device_count={' GPU ': 0} When declaring session, the code is as follows:
Import TensorFlow as tf
sess = tf. Session (CONFIG=TF. Configproto (device_count={' GPU ': 0}))
For Keras, call back-end functions, and set them to use the session as defined above, with the following code:
Import TensorFlow as TF
import keras.backend.tensorflow_backend as KTF
ktf.set_session (TF. Session (CONFIG=TF. Configproto (device_count={' GPU ': 0}))
For multithreading and GPU memory settings, see Keras set GPU Use memory size (TensorFlow backend); see TensorFlow website for more details.
3. The third is to use the Cuda_visible_devices command-line arguments, the following code:
Cuda_visible_devices= "" Python3 train.py