您的位置:首页 > 其它

在window10下安装theano GPU版本+keras1.2

2017-07-28 00:00 225 查看
因为业务需要,需要安装一个theanoGPU版本+keras1.2环境来运行代码。经过百度搜索和多次实验,终于成功地完成安装和测试。

1、首先要安装好Anaconda。

接下来创建一个虚拟环境keras12

2、condacreate–nkeras12python=2.7

3、激活keras12虚拟环境

activatekeras12


4、使用conda命令安装theanogpu版本
condainstalltheanopygpu

5、下载keras1.22版本并安装

https://github.com/fchollet/keras/releases

下载1.2.2版本

解压到硬盘的某个目录下,使用pythonsetup.pyinstall

安装Keras1.22版本

6、把keras默认后台配置修改成theano

在C:\Users\Administrator\.keras目录下

修改keras.json。把里面的tensorflow相关的信息换成theano的。

{

"floatx":"float32",

"backend":"theano",

"epsilon":1e-07,

"image_dim_ordering":"th"

}

修改C:\Users\Administrator\.theanorc.txt。把device选项设置成gpu

[global]

device=gpu

#device=cpu

floatX=float32

openmp=False

allow_input_downcast=True

#optimizer_including=cudnn

[blas]

ldflags=

[gcc]

remcxxflags=-IE:\common\mingw-w64\i686\mingw32\i686-w64-mingw32\include

[nvcc]

fastmath=True

flags=-LE:\Anaconda2\envs\keras1\libs

compiler_bindir=F:/ProgramFiles(x86)/MicrosoftVisualStudio13/VC/bin/x86_amd64

[lib]

cnmem=0.8

如何配置CUDNN:

https://stackoverflow.com/questions/36248056/how-to-setup-cudnn-with-theano-on-windows-7-64-bit/36464973

7、测试。

进入python环境,importkeras

如果一切正常,那就安装好了。我自己跑了一个使用GPU加速的程序:

fromtheanoimportfunction,config,shared,tensor
importnumpy
importtime

vlen=10*30*768#10x#coresx#threadspercore
iters=1000

rng=numpy.random.RandomState(22)
x=shared(numpy.asarray(rng.rand(vlen),config.floatX))
f=function([],tensor.exp(x))
print(f.maker.fgraph.toposort())
t0=time.time()
foriinrange(iters):
r=f()
t1=time.time()
print("Looping%dtimestook%fseconds"%(iters,t1-t0))
print("Resultis%s"%(r,))
ifnumpy.any([isinstance(x.op,tensor.Elemwise)and
('Gpu'notintype(x.op).__name__)
forxinf.maker.fgraph.toposort()]):
print('Usedthecpu')
else:
print('Usedthegpu')
只用CPU,程序要跑12秒多。使用GPU加速,只需要0.25秒。还行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Theano Keras win10 GPU