Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable GPU in keras with tensorflow?

I want to compare processing time of my code with and without gpu. My backend of keras is Tensorflow. So it uses a GPU automatically. I use a model of keras/examples/mnist_mlp.py for comparing.

I checked the processing time like below. Then, how do I disable my GPU? Should ~/.keras/keras.json be modified?

$ 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
like image 289
jef Avatar asked Mar 28 '17 13:03

jef


2 Answers

$ CUDA_VISIBLE_DEVICES=-1 time python mnist_mlp.py

seems to be a) either the new way, or b) a way that works on both Windows and Linux.

like image 32
Jonas Byström Avatar answered Nov 12 '22 01:11

Jonas Byström


Have you tried something like this? :

$ CUDA_VISIBLE_DEVICES='' time python mnist_mlp.py 

CUDA_VISIBLE_DEVICES is usually used to hide some GPU's to cuda. Here you hide them all as you don't put any visible device.

like image 169
Nassim Ben Avatar answered Nov 11 '22 23:11

Nassim Ben