@HarryUp
2017-03-22T02:36:08.000000Z
字数 1471
阅读 841
深度学习
环境配置
2017.03.18
因为是GPU版本,所以CUDA和cuDNN是必需的;Theano是python库,所以python是必需的,建议安装Anaconda3(默认python3.6编译器),然后创建一个python3.5环境(现在的tensorflow和Theano库都不支持python3.6的GPU加速版本,另外theano的GPU加速版本支持window下的python2.7)。同时推荐安装tensorflow和Theano的上层库keras,直接pip就行。
在C:\Users\Harry(每个人用户名不一样,改!)文件夹下创建.theanorc.txt,并添加以下内容:
[global]
floatX = float32
device = gpu
[nvcc]
flags=-LE:\Anaconda3\envs\tensorflow\libs #此为anaconda路径,改!
compiler_bindir=C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin #此为VS路径,改!
打开IDE,选择编译器为所创环境下的python.exe,并用以下代码验证:
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
另外,因为theano 0.9版本刚发布,conda装的是0.8,对cuDNN5.1支持没新版本好,有需要的可以在命令行升级
pip install --upgrade --no-deps git+https://github.com/Theano/Theano.git#egg=Theano
深度学习框架theano至此全部安装完毕,而上层库keras无需配置GPU版,自动使用tensorflow(优先)或者Theano的backend。
Have fun! :)