ubuntu14.04在cpu上配置caffe以及py-faster-rcnn環境(可在odroid上實現)
阿新 • • 發佈:2019-01-24
一、安裝依賴項
安裝blas
$ sudo apt-get install libatlas-base-dev
安裝pip
sudo apt-get install python-pip
安裝其他依賴庫
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler liblmdb-dev libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo apt-get install python-dev
$ sudo apt-get install python-opencv
安裝python模組
$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn
python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython
二、安裝opencv
安裝過程不多說,網上教程很多,我習慣於下載好opencv,然後建立在opencv的主目錄建立一個build資料夾,終端cd到該資料夾直接
cmake ..
make
make install
三、下載配置caffe
從github上直接下載
$ git clone git://github.com/BVLC/caffe.git
用終端cd到caffe目錄下
cp Makefile.config.example Makefile.config
更改Makefile.config
的部分內容:
去掉CPU_ONLY :=1的註釋
註釋掉CUDA有關的行:
#CUDA_DIR := /usr/local/cuda
#CUDA_DIR := /usr
#CUDA_ARCH := ....
#TEST_GPUID := 0
去掉WITH_PYTHON_LAYER := 1的註釋
改正後:
make all
make test
make runtest
make pycaffe
都make成功後cd caffe/python
資料夾。開啟python直譯器, 若import caffe成功, 則安裝成功
三、安裝py-faster-rcnn
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
安裝cython
sudo pip install cython
cd到/py-faster-rcnn/lib
修改setup.py檔案,註釋掉GPU相關程式碼,如下:
#CUDA = locate_cuda()
#self.set_executable('compiler_so', CUDA['nvcc'])
# Extension('nms.gpu_nms',
# ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
# library_dirs=[CUDA['lib64']],
# libraries=['cudart'],
# language='c++',
# runtime_library_dirs=[CUDA['lib64']],
# this syntax is specific to this build system
# we're only going to use certain compiler args with nvcc and not with
# gcc the implementation of this trick is in customize_compiler() below extra_compile_args={'gcc': ["-Wno-unused-function"],
# 'nvcc': ['-arch=sm_35','--ptxas-options=-v','-c','--compiler-options',"'-fPIC'"]},
#include_dirs = [numpy_include, CUDA['include']]
#),
setup.py修改完成後,在lib目錄下執行
make
接下來要編譯caffe(專案自帶的caffe-fast-rcnn)
修改Makefile.config,和之前修改caffe一樣
cp Makefile.config.example Makefile.config
更改Makefile.config
的部分內容:
去掉CPU_ONLY :=1的註釋
註釋掉CUDA有關的行:
#CUDA_DIR := /usr/local/cuda
#CUDA_DIR := /usr
#CUDA_ARCH := ....
#TEST_GPUID := 0
去掉WITH_PYTHON_LAYER := 1的註釋
改正後:
make -j8 && make pycaffe
至此安裝完畢
還要修改/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py檔案部分內容
1.登出
#from nms.gpu_nms import gpu_nms
2.改引數
def nms(dets, thresh, force_cpu=True):
四、執行demo.py
cd到py-faster-rcnn資料夾,下載caffe訓練集以及所需要的檔案
./data/scripts/fetch_faster_rcnn_models.sh
cd到/py-faster-rcnn/tools,執行
./demo.py --cpu
之後可以看見系統已經訓練好的模型執行效果。
但是cpu還是比較慢的。且容易記憶體溢位。如果我們換成zf網路模型(預設為VGG16)需要
./demo.py --cpu --net zf