with tf.device(/cpu:0)
I don't write anything, let everything be as default. So since I install tensorflow in GPU version. It should assume default using GPU.
with tf.device(/gpu:0)
This undocumented trick works for me so far. However, since keras is a blackbox to me, while tensorflow is more structured and clear, I feel there should be an improvement for keras to better control the CPU/GPU device with in keras. I know we could just use keras as simplified tensorflow layer constructor. Thus it is possible to run everything under framework of tensorflow rather than living in the world of keras.
If you have alternative ways to force keras be used in CPU or GPU, please comment below and let everyone else know.
Best,
Shaowu
You can also set the environment variable: CUDA_VISIBLE_DEVICES to limit the number of gpus used. http://www.acceleware.com/blog/cudavisibledevices-masking-gpus
We use a task scheduler for our CUDA Servers and in the schell script we use this variable like this:
export CUDA_VISIBLE_DEVICES=$(getFreeGPU)
Put
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"] = ""
before tensorflow is imported.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '-1' works on windows 10 to force it to use CPU
work perfect for me (windows 10 and keras 2.2.4)
Thank !
work perfect for me (windows 10 and keras 2.2.4)
Thank !
when I did this in keras (with the backend of tensorflow in window 10), the program will occupy all the memories of GPUs, but it only runs on one GPU. Anyone has meet this problem before?
Most helpful comment
Put
before tensorflow is imported.
See also: http://stackoverflow.com/a/42750563/562769