如何使用tensorflow在keras中禁用GPU?
How to disable GPU in keras with tensorflow?
我想比较使用和不使用 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。在这里你将它们全部隐藏,因为你没有放置任何可见的设备。
$ CUDA_VISIBLE_DEVICES=-1 time python mnist_mlp.py
似乎是 a) 新方法,或 b) 一种适用于 Windows 和 Linux 的方法。
我想比较使用和不使用 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。在这里你将它们全部隐藏,因为你没有放置任何可见的设备。
$ CUDA_VISIBLE_DEVICES=-1 time python mnist_mlp.py
似乎是 a) 新方法,或 b) 一种适用于 Windows 和 Linux 的方法。