Keras: How to programing Keras code to run on GPU?

Created on 3 Dec 2015  路  7Comments  路  Source: keras-team/keras

i do not clear how to let my Keras code run on GPU mode? or Keras default to run on GPU?

Most helpful comment

write things below to a ".theanorc" file and put it in your home dir in Linux
"
[global]
floatX = float32
device = gpu0

[nvcc]
fastmath = True
"
OR
in Windows, well i use WinPython
put the .theanorc file in the setting dir.

AND
the Keras will auto use Theano in GPU mode.

All 7 comments

write things below to a ".theanorc" file and put it in your home dir in Linux
"
[global]
floatX = float32
device = gpu0

[nvcc]
fastmath = True
"
OR
in Windows, well i use WinPython
put the .theanorc file in the setting dir.

AND
the Keras will auto use Theano in GPU mode.

@suixudongi8 on mac osx i can not create .theanorc file in /home/
how can i solve this problem?

1.You must have a Nvidia GPU card. Does mac have one?
2.Install CUDA.
3.Then the .theanorc file.
http://deeplearning.net/software/theano/install.html#gpu-macos

I just add this at the start of my python files

import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=gpu,floatX=float32"
import theano
import keras

@lqchn On a Mac, the correct location of the file is /Users/replace this by your username/.theanorc

thanks for everyone, I solve this problem through Theano document

THEANO_FLAGS=device=gpu0, floatX=float32 python keras_OBJ_RECOG.py
I ran my python code in GPU using the above method...
It threw the following error:
rval = import(module_name, {}, {}, [module_name])
RuntimeError: ('The following error happened while compiling the node', GpuDnnConv{algo='small', inplace=True}(GpuContiguous.0, GpuContiguous.0, GpuAllocEmpty.0, GpuDnnConvDesc{border_mode='full', subsample=(1, 1), conv_mode='conv'}.0, Constant{1.0}, Constant{0.0}), 'n', 'could not create cuDNN handle: CUDNN_STATUS_NOT_INITIALIZED', "[GpuDnnConv{algo='small', inplace=True}(

can anyone help me with this???
Did I miss some module???

Was this page helpful?
0 / 5 - 0 ratings