windows下机器学习工具theano、caffe、tensorflow对比及theano的安装

windows下机器学习工具theano、caffe、tensorflow对比及theano的安装

2016年是人工智能、智能驾驶、智能家居等等一系列元年的开端,我自然也没什么能力去定义什么元年,更没什么眼界去畅想什么未来,我只想谈谈这一年以来自己的所闻所感。
自从google在2015年开放Tensorflow开源代码以来,机器学习库的开源之路得到蓬勃发展。但tensorflow一开始只支持linux和osx系统,2016年底开始支持windows系统,但只包括win7和win10,由于机器学习在gpu加速下性能提升显著,所以一般要配合nvidia的cuda和cudnn使用,由于cuda自7.0之后就只有64位系统的了,所以32位系统的用户要不使用cuda6.5以前的版本,要不换64位系统。
除了tensorflow之外比较知名的机器学习库由theano、caffe、torch、mxnet等等,caffe跟清华颇有渊源(在此不细说),上课时老师推荐过,theano应该是新手入门跨多平台比较好用的工具,torch和mxnet可能都比较专业,我并没有接触过。在windows平台下caffe和theano都比较容易安装成功,个人选择的是theano的深度学习工具,今天就讲讲windows下theano的安装
系统配置策略:windows7 64位系统+cuda 8.0+visual studio 2013+anaconda3.5 64位
以上配置策略较为简单,在nvida的cuda和cudnn官网都可以找到。在我的其他博客中有提到cuda的安装方法。如果你是32位系统那么久比较尴尬,可以使用以下方法。
系统配置策略:windows7 32位系统+cuda 6.5+visual studio 2013+anaconda2 32位
博客上已经有比较不错的安装教程,我主要是参考
http://blog.csdn.net/m624197265/article/details/45700619
http://blog.sina.com.cn/s/blog_96b836170102vq22.html
http://www.cnblogs.com/tec-vegetables/p/5113119.html
两篇文章,关键遇到的几个问题就是
1,一般选取anaconda2.由于在以前使用opencv的时候选择的是python2的版本,所以这里直接使用的anaconda2的版本。连接如下
https://www.continuum.io/downloads#windows
2.cuda 6.5,由于系统一直是32位,所以不太想换64位系统,cuda自7.0之后只支持4位系统,所以只能用6.5以前的版本,可以去官方下载:
https://developer.nvidia.com/cuda-toolkit-65
3.vs是windows 下的c\c++编译平台,无论是caffe或者是theano都需要安装.建议安装vs2010以上的版本,
4.安装步骤为
1.anaconda下载安装,解压缩即可
2.mingw的安装,cmd输入:conda install mingw libpython
3.(.theanorc.txt)文件的生成:在cmd的home下生成这个文件
4.theano的安装,cmd输入 pip install theano
5.GPU加速:cuda 6.5安装,具体见http://blog.csdn.net/m624197265/article/details/45700619
其实不需要格外添加环境变量。大家可以尝试一下。
6.测试
这里写图片描述

附录

.theanorc.txt文件格式:

[global]
openmp = False
device = gpu
floatX = float32
allow_input_downcast=True
[blas]
ldflags =
[gcc]
cxxflags = -IC:\Anaconda2\MinGW\include
[nvcc]
flags = -LC:\Anaconda2\libs   
compiler_bindir = H:\Program Files\Microsoft Visual Studio 12.0\VC\bin
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')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章