https://keras.io/getting-started/faq/ 查看Keras 官方文檔
If you are running on the TensorFlow backend, your code will automatically run on GPU if any available GPU is detected.If you are running on the Theano backend, you can use one of the following methods:
Method 1: use Theano flags.
THEANO_FLAGS=device=gpu,floatX=float32 python my_keras_script.pyThe name 'gpu' might have to be changed depending on your device's identifier (e.g.gpu0, gpu1, etc).
Method 2: set up your .theanorc: Instructions
Method 3: manually set theano.config.device, theano.config.floatX at the beginning of your code:
import theanotheano.config.device = 'gpu'theano.config.floatX = 'float32'因為在服務器上跑CNN,在$HOME 下我使用的vim ~.theanorc, 添加
[global]floatX = float32device = gpu0[lib]cnmem = 1之后keras就會使用GPU而不是CPU跑網絡。運行成功,會打印
Using Theano backend.Using gpu device 0: GeForce GTX 1080
新聞熱點
疑難解答