好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

在Python中使用Tensorflow后端的Keras可以随意使用CPU或GPU吗?

我在Keras上安装了Tensorflow后端和CUDA.我想有时需要强迫Keras使用CPU.这可以在没有在虚拟环境中安装单独的CPU Tensorflow的情况下完成吗?如果是这样的话?如果后端是Theano,可以设置标志,但我还没有听说过可通过Keras访问的Tensorflow标志. 如果你想强迫Keras使用CPU

方式1

import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"   # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"] = ""

在导入Keras / Tensorflow之前.

方式2

运行您的脚本

$CUDA_VISIBLE_DEVICES="" ./your_keras_code.py

也可以看看

> https://github测试数据/keras-team/keras/issues/152 > https://github测试数据/fchollet/keras/issues/4613

查看更多关于在Python中使用Tensorflow后端的Keras可以随意使用CPU或GPU吗?的详细内容...

  阅读:20次