共計 1623 個字符,預(yù)計需要花費 5 分鐘才能閱讀完成。
這篇文章主要介紹“ubuntu 如何安裝 theano 和 keras”,在日常操作中,相信很多人在 ubuntu 如何安裝 theano 和 keras 問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”ubuntu 如何安裝 theano 和 keras”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學(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)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>