ubuntu系統(tǒng)theano和keras的安裝方法
說(shuō)明:系統(tǒng)是unbuntu14.04LTS,32位的操作系統(tǒng),以前安裝了python3.4,現(xiàn)在想要安裝theano和keras。步驟如下:
1,安裝pip
sudo apt-get install python3-setuptools sudo easy_install3 pip
2,安裝g++
sudo apt-get install g++
采用上述命令安裝g++,安裝完成后可用g++ -version查看是否安裝完成。注意,如果沒(méi)有安裝g++,在import theano時(shí)會(huì)出現(xiàn)以下錯(cuò)誤:
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.
搜了一下是因?yàn)閠heano采用g++編譯的話速度比較快,在網(wǎng)上找到的大部分解決方案都是基于Anaconda安裝的,解決方法是:
conda install mingw libpython
3,安裝theano
sudo pip3 install theano
該命令會(huì)自動(dòng)下載theano所需要的依賴,包括numpy,scipy等等。
4,安裝keras
sudo pip3 install keras
最后需要注意的是,keras默認(rèn)的backend是tensorflow,我們需要的是theano,所以需要修改下設(shè)置。(而且tensorflow用pip3安裝,在32位系統(tǒng)上沒(méi)有對(duì)應(yīng)的版本!用源文件安裝又很復(fù)雜)
vim ~/.keras/keras.json
{
"image_dim_ordering":"tf",
"epsilon":1e-07,
"floatx":"float32",
"backend":"theano"
}
5,測(cè)試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(), ))
總結(jié)
以上所述是小編給大家介紹的ubuntu系統(tǒng)theano和keras的安裝方法,希望對(duì)大家有所幫助!
相關(guān)文章
xshell5使用ssh連接阿里云服務(wù)器的實(shí)現(xiàn)步驟
本文主要介紹了xshell5使用ssh連接阿里云服務(wù)器的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
CentOS 7.2安裝Nginx 1.10.2的詳細(xì)教程
最近公司要切換VPS,所以打算使用最新的系統(tǒng)進(jìn)行搭建LNMP,這篇文章是為CentOS 7.2安裝Nginx 1.10.2的安裝記錄,記錄下以便下次或者有需要的朋友們參考使用。下面跟著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2016-11-11
ssh遠(yuǎn)程無(wú)法訪問(wèn)linux的問(wèn)題及解決
這篇文章主要介紹了ssh遠(yuǎn)程無(wú)法訪問(wèn)linux的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
詳解Centos7源碼編譯安裝 php7.2之生產(chǎn)篇
這篇文章主要介紹了詳解Centos7源碼編譯安裝 php7.2之生產(chǎn)篇,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
Centos環(huán)境下安裝Zend optimizer 3.3.9的方法
這篇文章主要介紹了Centos環(huán)境下安裝Zend optimizer 3.3.9的方法,簡(jiǎn)單說(shuō)明了CentOS服務(wù)器環(huán)境下安裝Zend optimizer 3.3.9的相關(guān)下載、解壓、安裝、配置等操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2018-03-03
Linux多線程環(huán)境下 關(guān)于進(jìn)程線程終止函數(shù)總結(jié)
下面小編就為大家?guī)?lái)一篇Linux多線程環(huán)境下 關(guān)于進(jìn)程線程終止函數(shù)總結(jié)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01
Linux Windows下設(shè)置定時(shí)執(zhí)行任務(wù)的方法
這篇文章主要介紹了Linux、windows下 設(shè)置定時(shí)執(zhí)行任務(wù)的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09

