事先声明该博客是无图版的(懒癌晚期,懒得去截图),但是真的可以帮你解决问题
论文的代码是基于theano的深度学习框架,所以被迫将电脑的深度学习环境改为基于py2.7,theano。自己搭配了N+1天,终于成功跑了起来。吐血?简直是丧命经历好吗。。
步骤:
1.安装Anaconda-2.1.0-Windows-x86_64 .exe 地址https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
安装这个版本是因为它自带mingW,你就不需要再去配很多环境变量,容错率高
推荐安装all users
2.安装完之后,打开cmd
pip install theano==xx
xx是你需要装的版本,切记用pip安装,如果用conda口令会提示你更新很多东西,那么好了,恭喜你进坑了
ps,你也不要换你的conda下载源,问题同上
2.1配置theanorc
打开cmd,会看到窗口里边有个路径,我的是C:\Users\Locked>,根据自己的路径,找到对应的目录,在该目录下新建一个文本文档,命名为 .theanorc(注意有个“.”),编辑它,写入以下内容:
[global]
openmp=False
[blas]
ldflags=
[gcc]
cxxflags=-IC:\Anaconda\MinGW
其中粗体字部分是你安装的Anaconda的路径,一定不要弄错。否则找不到MinGw。
3.做完这几步,你在cmd输入import theano,没什么特殊情况的话就能导入进来了
这时候cpu版本的theano已经装好了,想装gpu的咱们继续
4.安装vs
我装的是vs2012版本的,完美兼容
ps,如果想节省空间的话,你只需要在安装时选择c++的那部分工具
5.安装cuda
cuda历史版本下载地址(https://developer.nvidia.com/cuda-toolkit-archive)
别用最新的了,根据自己电脑实际情况来
我用的是cuda8
5.1测试cuda是否装好
打开cmd控制台命令行,输入命令nvcc –V回车(注意是大写V)就可以查看版本信息,如果安装正确会显示Cuda的版本号
6.安装cudnn
https://developer.nvidia.com/rdp/cudnn-archive
这个东西还是很好装的,下载下来,去cuda的安装文件夹里替换相应的文件即可
一定要记住要对照着cuda的版本来安装cudnn!!!
7.配置.theanorc.txt,如下:
[global]
openmp=False
device = gpu
floatX = float32
allow_input_downcast=True
[blas]
ldflags=
[gcc]
cxxflags=-IE:\Anaconda\MinGW
[nvcc]
flags = -LE:\Anaconda\libs #此处是Anaconda的路径
compiler_bindir = E:\VS2012\VC\bin #此处一定要和你安装的VS的路径保持一致,如果是默认安装的,应该是C:\Program
fastmath = True
附测试代码
from theano import function, config, shared, sandbox
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' % iters, t1 - t0, 'seconds')
print ('Result is', 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')
如果输出的是Used the gpu,那就大功告成了。
bingo!