Technology- Caffe 使用

Caffe 安装和使用。

安装

OSX 系统

安装流程。

配置环境:

1
2
3
4
5
sudo mkdir ~/caffe_python 
sudo cp -r ./python/caffe ~/caffe_python
vi ~/.bash_profile
export PYTHONPATH=~/caffe_python:$PYTHONPATH
source ~/.bash_profile

CentOS 系统

1
2
3
4
5
6
7
8
9
sudo yum install -y protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
sudo yum install -y gflags-devel glog-devel lmdb-devel
sudo yum install -y atlas-devel python-devel
git clone https://github.com/BVLC/caffe.git
cd caffe
修改 MAKEFILE
make all
make test
make runtest

Ubuntu 系统

1
2
3
4
5
6
7
8
9
10
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y python-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest

配置环境

1
2
#编辑 rc.local 文件,添加
source /etc/profile

测试运行时间

1
2
3
4
cd  $CAFFE_ROOT
./data/cifar10/get_cifar10.sh
./examples/cifar10/create_cifar10.sh
./build/tools/caffe time --model=examples/cifar10/cifar10_full_sigmoid_train_test_bn.prototxt -iterations 1000

报错

问题1

1
Fatal error: hdf5.h: 没有那个文件或目录

解决:

1
2
3
4
5
6
7
8
9
Makefile.config 中:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

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

问题2

1
2
.build_release/lib/libcaffe.so:对‘boost::re_detail_106200::get_default_error_string(boost::regex_constants::error_type)’未定义的引用
.build_release/lib/libcaffe.so:对‘cv::VideoWriter::write(cv::Mat const&)’未定义的引用

解决:

1
2
3
在 Makefile 中添加:

LIBRARIES += boost_regex opencv_videoio

问题3

1
2
Undefined symbols for architecture x86_64:
"boost::re_detail_106500::get_mem_block()", referenced from:

解决:

1
2
3
4
Makefile.config中:

INCLUDE_DIRS 加上 /usr/local/opt/boost/include/boost
LIBRARY_DIRS 加上 /usr/local/opt/boost/lib

问题4

1
src/caffe/test/test_proposal_layer.cpp:28:26: error: no template named 'GPUDevice'; did you mean 'CPUDevice'?

解决:

1
删除该文件

问题5

1
cannot find -lboost_python3

解决:

1
2
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libboost_python-py36.so libboost_python3.so

问题6

1
2
3
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.

解决:

1
export OpenCV_DIR=/usr/local/Cellar/opencv@2/2.4.13.2_2/share/OpenCV

问题7

1
libdc1394 error: Failed to initialize libdc1394

解决:

1
sudo ln /dev/null /dev/raw1394

问题8

1
vec.lib not found4

解决:

1
2
#修改 CMakeCache.txt 
vecLib_INCLUDE_DIR:PATH=/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers

问题9

1
ld: library not found for -lboost_thread-my

解决:

1
2
3
4
#编辑 Makefile 文件
-lboost_thread-my
替换为:
-lboost_thread-mt