Caffe學習(1):Ubuntu16.04上Caffe配置安裝(Only CPU)
阿新 • • 發佈:2019-02-20
常說天作孽猶可違,人作孽不可活啊,那為了畢設,我就是作死啊。沒辦法自己從三月份辭掉實習開始斷斷續續學習深度學習,才明白入坑雖淺,基情不斷啊。為了能夠完成畢設,便選了Caffe,也到處都是坑啊。沒辦法,為了祭奠我那糟糕透頂的記憶腦細胞,用我這糟糕的文筆稍微記錄一下吧。
首先想吐槽一下,我的電腦沒有Nvidia,沒有Nvidia,沒有Nvidia,重要的事情說三篇。在這上面就耽誤了好幾天。
安裝依賴包
1.安裝protobuf,leveldb,snappy,opencv,hdf5, protobuf compiler andboost:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
2.安裝gflags,glogs ,lmdb andatlas.
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev
git clone git://github.com/BVLC/caffe.git
編譯Caffe
1.切換到Caffe所在目錄
cp Makefile.config.example Makefile.config
2.配置Makefile.config
1)CPU_ONLY := 1
2)配置一些引用檔案(增加部分主要是解決新版本下,HDF5的路徑問題)
1)INCLUDE_DIRS := $(PYTHON_INCLUDE)
/usr/local/include
/usr/lib/x86_64-linux-gnu/hdf5/serial/include
2)LIBRARY_DIRS := $(PYTHON_LIB)
/usr/local/lib
/usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
3)BLAS := atlas
計算能力 mkl > openlas >atlas
3.Make Caffe
make all -j8
make test -j8
make runtest -j8
4.編譯成功,否則執行 make clean 多執行以下,否則多google吧
編譯python介面
1.Caffe擁有python\C++\shell介面,在Caffe使用python特別方便,在例項中都有介面的說明。
1)確保pip已經安裝
sudo apt-get install python-pip
2)新建shell檔案並執行安裝依賴
for req in $(cat requirements.txt); do pip install $req; done
3)編譯python介面
make pycaffe
當出現下面錯誤的時候修改
fatal error: numpy/arrayobject.h: No such file or directory.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include This is where our error is. So by changing this line to:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Our problem is gone.
2.執行python結構
import sys
sys.path.append("~/Documents/caffe/python")
'''
import caffe If the last import caffe doesn't pop out any error, congratulations, now you can use python to play with caffe!
'''
在Mnist執行Lenet
1.獲取資料來源
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
2.因為是CPU執行,所以修改在examples檔案下的Mnist下的lenet_solver.prototxt中的solver_mode:CPU
solver_mode: CPU
3.訓練模型
./examples/mnist/train_lenet.sh
終於寫完了,該吃飯去了。
參考