参考文章:https://blog.csdn.net/Jesse_Mx/article/details/52769272
1. 获取ssd版caffe
说明:SSD采用的是在caffe文件夹中内嵌例程的方式,作者改动了原版caffe,所以你需要把原来的caffe文件夹移除,git命令会新建一个带有SSD程序的caffe文件夹,当然,这个新的caffe要重新编译一次。
git clone https://github.com/weiliu89/caffe.git
cd caffe
git checkout ssd
这里需出现分支成功的提示方可继续:
Branch ssd set up to track remote branch ssd from origin.
Switched to a new branch 'ssd'
2. 编译caffe
cd caffe
cp Makefile.config.example Makefile.config
根据自己需求修改Makefile.config,注意如果你用的是opencv3.x,请注释掉# OPENCV_VERSION := 3(默认即是注释的)
make -j8 #8线程
make py
make test -j8
make runtest -j8 #貌似不是必须的,跑一遍用了10多分钟
之前没装各种库的时候会报各种错
① make: protoc: Command not found 需要安装protoc-c
sudo apt-get install protobuf-c-compiler protobuf-compiler
② ./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: No such file or directory
sudo apt-get install libgflags-dev
一堆错,还是先装好各种库吧
sudo apt-get install git
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev
sudo apt-get install libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
然后make clean一下,再重新make
3. 编译过程的问题解决:
① ./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory
解决:在Makefile.config找到以下行,后面分别添加一个hdf5的目录:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-Linux-gnu/hdf5/serial
② 快编译完成时报错
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
这说明链接器找不到hdf5_hl和hdf5这两个库,没法进行链接。
我的解决方案是更改makefile:在makefile中找到:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
将其注释掉,并添加:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
③ 又双叒叕报错:
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so
/usr/bin/ld: cannot find -lopenblas
collect2: ld devolvió el estado de salida 1
make: *** [.build_release/lib/libcaffe.so] Error 1
再安装库:
sudo apt install liblapack-dev liblapack3 libopenblas-base libopenblas-dev
④ 又踏马报错:
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
解决:使用cmake
mkdir build
cd build
cmake ..
make all -j8
make py -j8
⑤ 尽管这样暂时没有报错,但是到编译make test又报错,以及除了根目录可以import caffe ,其他位置import caffe一直提示没有caffe module,因此又找了一天的解决办法。最后看到https://github.com/rbgirshick/fast-rcnn/issues/52,暂时解决编译的报错问题。解决办法:
首先,将anaconda的Python3.6.5屏蔽了(将~/.bashrc的环境变量注释掉anaconda的Python路径即可)。切换到系统的Python3.5,可参考https://blog.csdn.net/lukaslong/article/details/81197617,然后进行以下操作:
Makefile中266行,在LIBRARIES += boost_thread stdc++后加boost_regex,即:
line263: LIBRARIES += boost_thread stdc++ boost_regex
继续make py
make test
make runtest
4. import caffe出错
错误提示ImportError: No module named 'numpy'
应该是切换了Python版本后,没有安装numpy的问题,因此需要安装numpy
pip install numpy
这里可能会报错,找不着pip指令,需要安装pip:
sudo apt-get install python3-pip