我的操作系统是UBUNTU,安装过程如下:
sudo su #然后输入密码
安装依赖包:
apt-get install git
apt-get install libprotobuf-devlibleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
apt-get install --no-install-recommends libboost-all-dev
apt-get install libatlas-base-dev
apt-get install python-dev
apt-get install libgflags-devlibgoogle-glog-dev liblmdb-dev
下载Caffe源代码:
git clone https://github.com/bvlc/caffe.git
cd caffe/
mv Makefile.config.example Makefile.config
修改Makefile.config,打开CPU_ONLY选项,即把前面的”#”去掉 然后保存
最后编译
make -j
上面是大体的过程,但是在编译中报错了,一共有三个错误
(1)Makefile:563: recipe fortarget'.build_release/src/caffe/layers/hdf5_data_layer.o' failed
解决方案:
解决方案:修改Makefile.config,将include和lib改为:
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/
(2)卡住了,显示out of memory
不要用make -j 多线程编程
改为 make
(3)..CXX/LD -o.build_release/tools/convert_imageset.bin .build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)’ .build_release/lib/libcaffe.so: undefinedreference tocv::imencode(cv::String const&, cv::_InputArrayconst&, std::vector >&, std::vector >const&)’ .build_release/lib/libcaffe.so: undefined reference to`cv::imdecode(cv::_InputArray const&, int)’ collect2: error: ldreturned 1 exit status make: * [.build_release/tools/convert_imageset.bin]Error 1
出现上面的错误,应该是opencv_imgcodecs链接的问题,比较有效的解决方案是,把opencv需要的lib添加到Makefile文件中,找到LIBRARIES(在PYTHON_LIBRARIES :=boost_python python2.7 前一行)并修改为:
LIBRARIES +=glog gflags protobuf leveldb snappy lmdbboost_system hdf5_hl hdf5 opencv_core opencv_highguiopencv_imgproc opencv_imgcodecs
此博客参考了两个博客整理而成
链接:https://www.jianshu.com/p/8335e5f229e1
https://blog.youkuaiyun.com/dym755833564/article/details/77965966