深度学习-theano-windows -cuda-环境搭建

本文将具体介绍深度学习之cuda的环境搭建

工具:支持CUDA的显卡(安装cuda6.5),VS2013。Anaconda。

步骤:

1.安装cuda6.5

这个不具体介绍,网上有很多文章。注意选择你相应的系统(我的是windows8.1 64位版,Desktop是台式机,Notebook是笔记本。事实上选错了你也安装不上)

下载cuda6.5官方网址 https://developer.nvidia.com/cuda-toolkit-65

cuda6.5是傻瓜安装,最好不要改动它的默认文件路径。

完毕后打开命令提示符输入nvcc -V然后回车,如图。

在WindowsVista, Windows 7, Windows 8, Windows Server 2003, and Windows Server2008平台上:能够打开下列.exe文件查看是否安装完毕。

C:ProgramDataNVIDIA CorporationCUDA Samplesv6.5inwin64Release

假设CUDA安装正确。则全部案例都是可以执行的

完毕安装后重新启动一下电脑

2.安装Anaconda

我选的版本号是1.8,由于最新的版本号没有MinGW目录

Anaconda百度云链接:http://pan.baidu.com/s/1qWN06qK password:44st

或者去官方网址https://repo.continuum.io/archive/index.html。找到Anaconda-1.8.0-Windows-x86_64.exe

(依据自己的系统选择对应的版本号下载)

下载完毕后安装,傻瓜式安装。

下载theano的zip文件:https://github.com/Theano/Theano 。网址打开后右边有个Download Zip选项,

下载完毕后解压将里面的theno文件拷贝到D:deepAnacondaLibsite-packages下(这一步是看网上弄的。以下要把theano这个目录删掉,不知道需不须要,以防万一还是做一遍吧)

加入环境变量path(注意是英文的分号:D:deepAnacondaMinGWin;

                               D:deepAnacondaMinGWx86_64-w64-mingw32lib;

新建环境变量:  PYTHONPATH:

D:deepAnacondaLibsite-packages heano

4.配置.theanorc.txt文件

在Home文件夹(不知道能够打开命令提示符,如我的Home文件夹是C盘->用户->Xu)


新建一个名为.theanorc的txt文件,里面输入

[blas]
ldflags =
[gcc]
cxxflags = -ID:AnacondaMinGW
[nvcc]
fastmath = True
flags=-LD:Anacondalibs
compiler-bindir=C:Program Files (x86)Microsoft Visual Studio 11.0VCin
base_compiledir=path_to_a_directory_without_such_characters
[global]
floatX = float32
device = gpu
保存

加入环境变量Path:D:deepAnacondaScripts

5.安装theano

将上一步的theano目录(即D:deepAnacondaLibsite-packages heano)删除。
打开命令提示符。输入pip install theano回车(注意空格),然后它会自己主动安装,注意保持网络畅通

稍等片刻就可以自己主动安装上最新版的Theano深度学习框架。这时可到D:deepAnacondaLibsite-packages下查看是否已经有theano和Theano-0.7.0-py2.7.egg-info两个目录,若有则表明已经成功安装。普通情况下,这一步不会出错。非常easy操作。

6.改动.theanorc.txt文件

终于版.theanorc.txt文件百度云链接:http://pan.baidu.com/s/1kDzyu password:5ubd


或者将下面内容复制粘贴,我也不知道里面是些啥东西。

[blas]
ldflags=

[gcc]
cxxflags = -ID:deepAnacondaMinGW(注意选择自己的路径)

[nvcc]
fastmath = True
flags=-LD:deepAnacondalibs(注意选择自己的路径)
compiler_bindir=D:vs2013VCin(注意选择自己的路径。你的可能是C:Program Files (x86)Microsoft Visual Studio 12.0VCin
flags =  -arch=sm_30
base_compiledir=path_to_a_directory_without_such_characters

[global]
openmp = False
floatX = float32
device = gpu
allow_input_downcast=True

7.測试

检查theano是否配置成功,打开命令提示符,输入python回车。再输入import theano回车,

若没有其它错误信息输出这表明theano配置正确。例如以下图所看到的。


在Anaconda目录下会有一个名为Spyder的软件,它长这样,假设没有能够搜索。


在里面输入

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 = 10000
 
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 xrange(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'

配置成功后会显演示样例如以下



最终完了,接下来要学习深度学习的人脸识别方面内容。希望有这方面学习资料的朋友告诉在下一下。



參考文档:

http://blog.csdn.net/m624197265/article/details/45700619

http://blog.csdn.net/baigoocn/article/details/36188029

https://github.com/zzbased/memo/blob/master/anaconda+theano+cuda+vs2012%E7%BC%96%E7%A8%8B%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md



原文地址:https://www.cnblogs.com/yjbjingcha/p/7290240.html