tensorflow - 如何使用Tensorflow在Keras中禁用GPU?

标签 tensorflow keras deep-learning gpu nvidia

我想比较使用和不使用gpu的代码的处理时间。我对keras的后端是Tensorflow。因此它会自动使用GPU。我使用keras/examples/mnist_mlp.py模型进行比较。

我检查了如下处理时间。然后,如何禁用我的GPU?是否应该修改~/.keras/keras.json

$ time python mnist_mlp.py 
Test loss: 0.109761892007
Test accuracy: 0.9832
python mnist_mlp.py  38.22s user 3.18s system 162% cpu 25.543 total

最佳答案

你尝试过这样的事情吗? :

$ CUDA_VISIBLE_DEVICES='' time python mnist_mlp.py 
CUDA_VISIBLE_DEVICES通常用于将某些GPU隐藏到cuda中。在这里,您将它们全部隐藏起来,因为您没有放置任何可见的设备。

关于tensorflow - 如何使用Tensorflow在Keras中禁用GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43070568/

相关文章:

python - 使用 TensorFlow 进行验证和测试

tensorflow - 属性错误 : module 'tensorflow' has no attribute 'unpack'

python - Tensorflow无法使用所有可见的GPU

python - 导入 keras 和 tensorflow 时出错

tensorflow - Keras 报告的准确性与 model.predict() 不符

python - 使用文件夹结构在 Keras 中进行预测时如何获得正确的标签?

python - 如何最有效地可视化一维卷积?

python-3.x - 使用 KerasClassifier randomsearchcv 进行超参数优化,TypeError : 'list' object cannot be interpreted as an integer

machine-learning - 如何重置迁移学习的特定层权重?

machine-learning - 神经网络 - 深度自动编码器和堆叠自动编码器之间的区别