Keras: Is it possible to set CPU / GPU usage without knowing the backend?

Created on 1 Jul 2016  路  4Comments  路  Source: keras-team/keras

In other words, I don't know if the Keras install will use Theano or TensorFlow, but I'd still like to have control over whether the CPU or GPU is being used. Is this possible? Could we add a flag to ~/.keras/keras.json for this purpose otherwise?

stale

Most helpful comment

Yeah, sure, but it feels like that should be a function provided by Keras, especially as more backends are eventually added. User code should be backend agnostic.

All 4 comments

You could automatically check ~/.keras/keras.json at the beginning of your script:

  • if the backend is Theano then with os.environ you can set THEANO_FLAGS to device=gpu (and/or openmp=True for multi-CPU usage) and then import theano.
  • if the backend is TensorFlow then it will automatically use the GPU. If needed you could then try to prevent tf to use the GPU with something like this.

Yeah, sure, but it feels like that should be a function provided by Keras, especially as more backends are eventually added. User code should be backend agnostic.

I always get gpu errors like "c:\tf_jenkins\home" etc. and can't simply switch to cpu (using tensorflow).
There is only a CPU version of Tensorflow available for my environment (Win7/64)!
I have NVIDIA GPU Computing installed, but it's not used (double trouble).

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.

Was this page helpful?
0 / 5 - 0 ratings