简体   繁体   English

CPU 与 GPU 在 Keras 中的使用情况(Tensorflow 2.1)

[英]CPU vs GPU usage in Keras (Tensorflow 2.1)

I have successfully set up TensorFlow 2.1.0 with access to my GPU:我已经成功设置了TensorFlow 2.1.0 ,可以访问我的 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?如果我使用 Keras( from tensorflow import keras )来适应一些Sequential model(就像这里的例子),默认情况下会使用 GPU 还是 CPU? Is there some command to see which one is in use by Keras and can I somehow set this up myself?是否有一些命令可以查看 Keras 正在使用哪个,我可以自己设置吗? 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.我真的很想看到一些非常基本的 Keras model 在 GPU 与 CPU 上进行训练,以便更好地了解性能差异。

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 .由于 TensorFlow 2.1、GPU 和 CPU 包都在同一个tensorflow中,不像以前的版本那样有单独的 CPU 和 GPU 版本: tensorflowtensorflow-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:或者你可以让你的视频卡对 TensorFlow 可见,方法是像上面一样允许默认配置,或者通过以下方式强制它:

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

Note that in the above setting, if you had 4 GPUs for example, you would set:请注意,在上面的设置中,如果您有 4 个 GPU,您将设置:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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