首页 > 学院 > 开发设计 > 正文

Keras 切换GPU

2019-11-08 02:53:01
字体:
来源:转载
供稿:网友

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.py

The 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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表