Win10+VS2015+cuda8.0+theano+keras的配置过程

本blog记录了在windows10下配置theano的过程,以便以后有需要的情况下查找。

首先说明配置的环境:

1.win10 64bit

2.VS2015

3.Anaconda2 64bit

一、安装Anaconda

正常安装即可,我安装的是Anaconda2,对应的是python2,我自定义的路径是D:\software\Anaconda2

二、安装MinGw

1.打开cmd,进入命令行

2.输入conda install mingw libpython 。稍等片刻即可完成安装。此时有D:\software\Anaconda2\MinGW 路径。

注意:若下载较慢,且反复多次不成功时,可以添加conda 镜像,输入下面的命令:

conda config --add channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
conda config --set show_channel_urls yes
三、配置环境变量

1.编辑用户变量中的path变量(如果没有就新建一个,一般会有的),在后边追加D:\software\Anaconda2;D:\software\Anaconda2\Scripts; 不要漏掉分号,此处因为我的Anaconda的安装目录是C:\Anaconda,此处需要根据自己的安装目录填写。
2.在用户变量中新建变量pythonpath,变量值为C:\Anaconda\Lib\site-packages\theano; ,此处就是指明安装的theano的目录是哪,但是现在咱们还没有安装,所以不着急,先写完再说。
3.打开cmd,会看到窗口里边有个路径,我的是C:\Users\Locked>,根据自己的路径,找到对应的目录,在该目录下新建一个文本文档.theanorc.txt (注意有两个“.”),编辑它,写入以下内容: 

[global] 
openmp=False 
[blas] 
ldflags= 
[gcc] 
cxxflags=-ID:\software\Anaconda2\MinGW  
其中红体字部分是你安装的Anaconda的路径,一定不要弄错。否则找不到MinGw。
注意:凡是对环境变量进行修改的操作,都应该重启。

四、安装theano

1.打开CMD,方法和安装MinGw一样,不要进入python。
2.输入pip install theano,回车后就是赏心悦目的下载进度条,这个很小,所以安装的比较快。
3.在cmd中,输入python 进入到python环境下,然后先输入import theano回车,需要等一段时间。
五、配置GPU加速

1.安装VS2015

2.安装cuda8.0,默认路径

3.验证cuda8.0是否安装成功

参考:http://www.linuxidc.com/Linux/2016-12/138862.htm

4.配置.theanorc.txt,如下:

[global]  
openmp=False 
floatX=float32  
device=gpu
allow_input_downcast=True   
[gcc] 
cxxflags=-ID:\software\Anaconda2\MinGW 
[lib]  
cnmem=0.8  
[blas]  
ldflas=-lopenblas  
[nvcc]  
--flags=-LD:\software\Anaconda2\libs  
--compiler_bindir=D:\software\vs2015\VC\bin\amd64
fastmath=True  
flags=-D_FORCE_INLINES  
[cuda]  
root = -LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
5.测试theano,用以下代码:

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')

注意:

1.在cmd下进入python,然后import theano后,跑出一大串行号及C++代码,且提示如下:

{
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\crtdefs.h(10): 
fatal error C1083: Cannot open include file: 'corecrt.h': No such file or directory
}     

必须新增底下到系统的环境变量里,原因是他会用到Windows Kits里的函式,不只VS2015
所也必须宣告进去。
INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt
LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.14393.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64

参考http://www.gpuworld.cn/article/show/604.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值