How to install and run keras on GPU

来源:互联网 发布:最好的java讲师 知乎 编辑:程序博客网 时间:2024/05/18 12:29

install

http://keras-cn.readthedocs.io/en/latest/getting_started/install/

gpu run

first way

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

second way

THEANO_FLAGS=device=gpu,floatX=float32 python xxx.py

test

cpu方式运行:python mnist_cnn.py
cpu方式运行
gpu方式运行:THEANO_FLAGS=device=gpu,floatX=float32 python mnist_cnn.py
默认模式,即mode=FAST_COMPILE,gpu快的太多了!
gpu方式运行

reference

http://buptldy.github.io/2016/04/09/2016-04-09-Deepin%20CUDA%E5%AE%89%E8%A3%85%E5%8F%8AKeras%E4%BD%BF%E7%94%A8GPU%E6%A8%A1%E5%BC%8F%E8%BF%90%E8%A1%8C/

0 0