溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Ubuntu14.04 Caffe如何安裝

發(fā)布時間:2021-11-15 17:30:55 來源:億速云 閱讀:143 作者:小新 欄目:大數(shù)據(jù)

這篇文章將為大家詳細(xì)講解有關(guān)Ubuntu14.04 Caffe如何安裝,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

Caffe簡介

Caffe全稱Convolutional Architecture for Fast Feature Embedding,是一個計算CNN相關(guān)算法的框架。就目前來說是deeplearning最流行的開源的框架,所以使用的人也是最多的。
caffe網(wǎng)址:http://caffe.berkeleyvision.org/
github網(wǎng)址:https://github.com/BVLC/caffe/

安裝環(huán)境

系統(tǒng):Ubuntu14.04 Desktop x64(建議使用剛安裝好的系統(tǒng),同時不要更新,不然會影響后面的某些環(huán)節(jié))
顯卡:支持CUDA的顯卡,當(dāng)然這個不是必須的

依賴程序

基本包

安裝開發(fā)需要的一些基本包

sudo apt-get updatesudo apt-get install build-essentialsudo apt-get install gfortran ## python中安裝scipy需要依賴gfortran

:Ubuntu默認(rèn)環(huán)境雖然已經(jīng)有g(shù)cc,但并沒有提供C/C++的編譯環(huán)境,單獨(dú)安裝編譯環(huán)境比較復(fù)雜,所以提供了build-essential命令一鍵來構(gòu)建所需的編譯環(huán)境。

CUDA(可選)

cuda在caffe編譯和使用中不是必須的,如果實(shí)在沒有支持cuda的顯卡或者只想嘗試一下caffe,不需要用它來進(jìn)行復(fù)雜的訓(xùn)練,不安裝也可以。
安裝鏈接:http://blog.csdn.net/honyniu/article/details/46387429

CuDNN(可選)

這個庫是基于cuda,當(dāng)然也是可選的。
安裝鏈接:http://blog.csdn.net/honyniu/article/details/46388241

BLAS(必選)

這個庫提供了caffe需要的一些基本的矩陣和向量庫,這個是必選的。
安裝鏈接:http://blog.csdn.net/honyniu/article/details/46388915

OpenCV(必選)

OpenCV提供了圖像處理和計算機(jī)視覺的庫,在caffe使用中是必須的,同時最好自己編譯安裝。
安裝鏈接:http://blog.csdn.net/honyniu/article/details/46390097

其他依賴項

caffe需要一些特定的數(shù)據(jù)庫的操作, 因此需要安裝leveldb, lmdb, hdf5等庫。 此外, caffe采用了google的一些庫, 比如protobuf以及glog, 這些也需要安裝,命令如下。

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

Matlab和python

這兩個不是必須的,但是caffe提供了bash、matlab和python的接口,同時caffe許多的可視化接口都是通過python實(shí)現(xiàn)的,推薦安裝。
matlab在這里使用的是Matlab-R2014A,這里就不講怎么安裝得了,自己去百度教程,默認(rèn)安裝即可,安裝在’/usr/local/MATLAB’目錄下。
ubuntu默認(rèn)安裝的2.7的版本但是為了安裝Python開發(fā)環(huán)境,方便今后編譯其他擴(kuò)展庫,命令如下

sudo apt-get install python-dev

python是使用的虛擬環(huán)境,具體虛擬環(huán)境的構(gòu)建見http://blog.csdn.net/honyniu/article/details/46382929
激活虛擬環(huán)境

source ENV/bin/activate

安裝編譯pycaffe的依賴包, 進(jìn)入caffe安裝目錄中的python文件夾, 你會看到一個requirements.txt, 首先, 修改protobuf那一行為protobuf==2.5.0, 然后執(zhí)行下面命令:

for req in $(cat requirements.txt); do pip install $req; done

這里我們沒安裝caffe推薦的anaconda包, 因?yàn)榘惭b之后進(jìn)不去桌面。而且anaconda包只是一個自帶了requirements.txt中所有選項的python集合庫, 將上面的庫安裝好之后, 不裝anaconda沒有任何影響。

配置編譯

caffe程序

可以去上面的caffe的github網(wǎng)址把caffe最新代碼下載下來,也可以使用git命令獲取,如下

git clone https://github.com/BVLC/caffe.git

caffe配置

終于到了最后的一步了,如果安裝好了上面的所有的caffe的依賴,那么下面就可以對caffe進(jìn)行配置和編譯了。
首先拷貝生成所需要的’Makefile.config’文件,caffe安裝包下面給提供了example,注意直接拷貝下面的可能會報錯,因?yàn)槊恳恍忻畹暮竺娌荒苡锌瞻椎淖址?,有可能會?dǎo)致編譯不通過。

cp Makefile.config.example Makefile.config

然后對該’Makefile.config’文件根據(jù)自己的需求進(jìn)行修改,下面是我的配置以及一些注釋。

## Refer to http://caffe.berkeleyvision.org/installation.html# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).USE_CUDNN := 1   #如果沒有安裝cudnn的注掉# CPU-only switch (uncomment to build without GPU support).# CPU_ONLY := 1   #如果沒有安裝cuda,不是要GPU的設(shè)置開啟  # To customize your choice of compiler, uncomment and set the following.# N.B. the default for Linux is g++ and the default for OSX is clang++# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.CUDA_DIR := /usr/local/cuda   #cuda默認(rèn)安裝目錄(其實(shí)是軟鏈接),一般不需要修改,但如果沒有安裝cuda需要注掉# On Ubuntu 14.04, if cuda tools are installed via# "sudo apt-get install nvidia-cuda-toolkit"># CUDA_DIR := /usr# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 lines for compatibility.CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
                -gencode arch=compute_20,code=sm_21 \
                -gencode arch=compute_30,code=sm_30 \
                -gencode arch=compute_35,code=sm_35 \
                -gencode arch=compute_50,code=sm_50 \
                -gencode arch=compute_50,code=compute_50# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := mkl   #這里使用的是Intel MKL,如果使用的ATLAS,請自行修改# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!BLAS_INCLUDE := /opt/intel/mkl/include   #如果是atlas,這兩個路徑要注掉BLAS_LIB := /opt/intel/mkl/lib/intel64# This is required only if you will compile the matlab interface.# MATLAB directory should contain the mex binary in /bin.MATLAB_DIR := /usr/local/MATLAB/R2014a   #Matlab的路徑,沒安裝Matlab或者不需要編譯該接口可以注掉# MATLAB_DIR := /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.#設(shè)置是python庫的路徑,使用的是虛擬環(huán)境capy這里就是一直提到的ENV,有時候可能不起作用,還是會報錯,不知道為什么,那就設(shè)置下面的export,一般就沒問題了。PYTHON_INCLUDE := /home/huayong/capy/include/python2.7 \
                /home/huayong/capy/lib/python2.7/site-packages/numpy/core/include#If it doesn't work above, you can try this below.export CPLUS_INCLUDE_PATH=/home/huayong/capy/include/python2.7:/home/huayong/capy/lib/python2.7/site-packages/numpy/core/include# Anaconda Python distribution is quite popular. Include path:# Verify anaconda location, sometimes it's in root.# ANACONDA_HOME := /home/wenzheng/anaconda# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \# $(ANACONDA_HOME)/include/python2.7 \# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# We need to be able to find libpythonX.X.so or .dylib.PYTHON_LIB := /usr/lib/x86_64-linux-gnu# PYTHON_LIB := $(ANACONDA_HOME)/lib# Uncomment to support layers written in Python (will link against Python libs)WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.# INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include# LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib# Uncomment to use `pkg-config` to specify OpenCV library paths.# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)USE_PKG_CONFIG := 1BUILD_DIR := build
DISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.TEST_GPUID := 0# enable pretty build (comment to see full commands)Q ?= @

caffe編譯

基本的編譯,j代表是多線程編譯,一般前兩個命令不會出錯,最后一個可能會出錯,但有時候也不影響使用。

make all -j8
make alltest -j8
make runtest

編譯matlab和python接口,這個當(dāng)然不是必須的,看你自己的需求。

make pycaffe
make matcaffe

關(guān)于“Ubuntu14.04 Caffe如何安裝”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI