您好,登錄后才能下訂單哦!
這篇文章主要介紹“ubuntu如何安裝theano和keras”,在日常操作中,相信很多人在ubuntu如何安裝theano和keras問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”ubuntu如何安裝theano和keras”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
1,安裝pip
sudo apt-get install python3-setuptools sudo easy_install3 pip
2,安裝g++
sudo apt-get install g++
采用上述命令安裝g++,安裝完成后可用g++ -version查看是否安裝完成。注意,如果沒有安裝g++,在import theano時會出現(xiàn)以下錯誤:
warning (theano.configdefaults): g++ not detected ! theano will be unable to execute optimized c-implementations (for both cpu and gpu) and will default to python implementations. performance will be severely degraded. to remove this warning, set theano flags cxx to an empty string.
搜了一下是因為theano采用g++編譯的話速度比較快,在網(wǎng)上找到的大部分解決方案都是基于anaconda安裝的,解決方法是:
conda install mingw libpython
3,安裝theano
sudo pip3 install theano
該命令會自動下載theano所需要的依賴,包括numpy,scipy等等。
4,安裝keras
sudo pip3 install keras
最后需要注意的是,keras默認(rèn)的backend是tensorflow,我們需要的是theano,所以需要修改下設(shè)置。(而且tensorflow用pip3安裝,在32位系統(tǒng)上沒有對應(yīng)的版本!用源文件安裝又很復(fù)雜)
vim ~/.keras/keras.json { "image_dim_ordering":"tf", "epsilon":1e-07, "floatx":"float32", "backend":"theano" }
5,測試theano
import numpy as np import time import theano a = np.random.rand(1000,10000).astype(theano.config.floatx) b = np.random.rand(10000,1000).astype(theano.config.floatx) np_start = time.time() ab = a.dot(b) np_end = time.time() x,y = theano.tensor.matrices('xy') mf = theano.function([x,y],x.dot(y)) t_start = time.time() tab = mf(a,b) t_end = time.time() print("np time: %f[s], theano time: %f[s] (times should be close when run on cpu!)" %( np_end-np_start, t_end-t_start)) print("result difference: %f" % (np.abs(ab-tab).max(), ))
到此,關(guān)于“ubuntu如何安裝theano和keras”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。