Linux下caffe的安装
下载caffe并保存到一个目录下(推荐放到 /home 目录)
安装依赖项:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compilersudo apt-get install --no-install-recommends libboost-all-devsudo apt-get install libatlas-base-devsudo apt-get install python-devsudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-devsudo apt-get install python-lmdbsudo apt-get install python-pip
5.下载Caffe:
sudo apt-get install git
git clone https://github.com/BVLC/caffe.git
并修改配置文件
cd caffe
备份文件
cp Makefile.config.example Makefile.config
修改需编译的选项(针对ubuntu15.04以及之后的版本,之前的版本不用修改,用于解决无法找到hdf5.h等文件),还有
gedit Makefile.config
# Whatever else you find you need goes here.INCLUDE_DIRS := $(Python_INCLUDE) /usr/local/includeLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib 修改为# Whatever else you find you need goes here.INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /usr/local/cuda-7.5/targets/x86_64-linux/ LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib/ /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/cuda-7.5/targets/x86_64-linux/ LIBRARIES += glog gflags protobuf leveldb snappy lmdb boost_system hdf5_hl hdf5 m opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs编译caffe:make all -j4make test -j4make runtestmake all时有cublas_v2.h: No such file or directory的错误原以为是caffe编译时没有正确编译CPU版本,或者caffe/util/device_alternate.hpp里未能正确判断,但查看源文件发现此处正常,原来是我的项目中,在编译时需要指定CPU_ONLY选项,即在我的项目Makefile里添加下面一句即可CXXFLAGS += -DCPU_ONLY=1如果只时使用CPU,打开注释CPU_ONLY=1即可
参考链接:https://blog.csdn.net/qq_38451119/article/details/81126692
去掉CPU—only选项前的注释,使之生效,若需Python layer,则还需去掉WITH_PYTHON_LAYER :=1前的注释
如需编译MATLAB接口,则需修改MATLAB_DIR,改成当前系统下的MATLAB路径
编译python接口
sudo pip install -r python/requirements.txtmake pycaffe
编译matlab接口
make matcaffegedit ~/.bashrc
最后面添加:export PYTHONPATH=/home/francis/caffe/python
rm *~ 可考虑删除因修改而自动生成的备份文件
以上可成功配置好cpu_only
安装GPU版本
应先装好CUDA,条件允许可以可加入cudnn,用于加速卷积运算
CUDA安装步骤待后续完善
注释掉CPU-only,其他与前面相同
CUDA安装推荐链接:
https://blog.csdn.net/wanzhen4330/article/details/81699769
赞 (0)