Keras and TensorFlow forced to use CPU__CPU

Source: Internet
Author: User
Tags call back theano keras

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.