简体   繁体   中英

CPU vs GPU usage in Keras (Tensorflow 2.1)

I have successfully set up TensorFlow 2.1.0 with access to my GPU:

在此处输入图像描述

If I use Keras ( from tensorflow import keras ) to fit some Sequential model (like in example here ), will by default be used GPU or CPU for that? Is there some command to see which one is in use by Keras and can I somehow set this up myself? I would really like to see some very basic Keras model trained on GPU vs CPU to have a better feeling about the difference in performance.

Since TensorFlow 2.1, GPU and CPU packages are together in the same package, tensorflow , not like in previous versions which had separate versions for CPU and GPU: tensorflow and tensorflow-gpu .

You can test to have a better feeling in this way:

   #Use only CPU
   import os 
   os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

Or you can make your video card visible to TensorFlow by either allowing the default configurations just like above, or to force it via:

os.environ['CUDA_VISIBLE_DEVICES'] = '0'

Note that in the above setting, if you had 4 GPUs for example, you would set:

 os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2,3'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM