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')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章