微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ubuntu14.04 安装caffe

安装matlab2015b

选择产品
MATLAB 8.6
Computer Vision System ToolBox 7.0
Image Acquisition ToolBox 4.10
Image Processing ToolBox 9.3
MATLAB Coder 3.0
MATLAB Compiler 6.1
MATLAB Compiler SDK 6.1
MATLAB Report Generator 4.2
Neural Network ToolBox 8.4
Statistics and Machine Learning ToolBox 10.1

安装caffe

caffe 需要的包

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install - -no-install-recommends libboost-all-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
from http://caffe.berkeleyvision.org/install_apt.html

如果遇到下面的错误

Some packages Could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:

重新编辑源/etc/apt/sources.list,我遇到好几次都是这个被改了,无法自动解决依赖关系
初步推测,可能是镜像站没有保留全部的依赖关系,导致了这个问题,因为我在家里14.04.5上,用163的源就有各种依赖问题,换成清华的就一步搞定了

安装OpenBLAS

参照 www.openblas.net 和 https://github.com/xianyi/OpenBLAS

git clone https://github.com/xianyI/OpenBLAS.git
cd OpenBLAS
make
make install

The default directory is /opt/OpenBLAS

cp Makefile.config.example Makefile.config
vim Makefile.config # 编辑 BLAS 和 python 路径
BLAS := open
BLAS_INCLUDE := /opt/OpenBLAS/include
BLAS_LIB := /opt/OpenBLAS/lib

安装python所需

cd caffe
for req in $(cat requirements.txt); do pip install $req; done

安装 CUDA 和 cuDNN

http://www.jb51.cc/article/p-trlnjlor-bqm.html

配置编译caffe

配置openblas 和 matlab的路径之后,配置
编译pycaffe前,需要修改 PYTHON_INCLUDE

PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include \ # 这个路径我没有找到,删不删除随意
        /usr/local/lib/python2.7/dist-packages/numpy/core/include # 如果不加这个路径,会发生下面的错误。这个路径用locate arrayobject.h 可以看到

不加会遇到下面的错误

touch python/caffe/proto/__init__.py
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
PROTOC (python) src/caffe/proto/caffe.proto
python/caffe/_caffe.cpp:10:31: Fatal error: numpy/arrayobject.h: No such file or directory
 #include <numpy/arrayobject.h>
                               ^
compilation terminated.
make: *** [python/caffe/_caffe.so] Error 1

make runtest如果遇到下面的错误

.build_release/test/test_all.testbin 0 --gtest_shuffle --gtest_filter="-*GPU*"
.build_release/test/test_all.testbin: error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory
make: *** [runtest] Error 127

参考
https://groups.google.com/forum/#!topic/caffe-users/J6Sw2eKeshY
解决办法有两个

# 1 在/usr/lib 下创建到/opt/OpenBLAS/lib/libopenblas.so.0 的符号链接
ln -s /opt/OpenBLAS/lib/libopenblas.so.0 /usr/lib/
# 2 export LD\_LIBRARY_PATH with OpenBLAS library path

如果显示 绿色的 PASSED,说明完成了。

Training LeNet on MNIST with Caffe

参考 http://caffe.berkeleyvision.org/gathered/examples/mnist.html

cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh

1080ti 花了大概10几秒,比cpu_ONLY 快了非常多

make matcaffe 提示

Warning: You are using gcc version '4.8.4'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '4.8.4-2ubuntu1~14.04.3)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.

想办法安装4.7的gcc,并替换4.8的符号链接

apt install -y gcc-4.7 g++-4.7
cd /usr/bin
mkdir gcc-link-bak
mv gcc g++ gcc-link-bak/
ln -s gcc-4.7 gcc
ln -s g++-4.7 g++

运行demo报错

Error using textscan
'BufSize' is no longer required and has been removed.

Error in read_cell (line 11)
fileLines = textscan(fid,'%s','delimiter',linesep,'BufSize',100000);

Error in matcaffe_batch_feat (line 28)
    list_im = read_cell(filename);

Error in demo (line 30)
[feat_test,list_im] = matcaffe_batch_feat(test_file_list,use_gpu,feat_len,model_def_file,model_file);

cvprw15这篇文章使用的是matlab2012,而15的接口已经变了
尝试删除 ‘BufSize’,100000 这两个参数后demo,发现找不到libopenblas.so.0,说明前面只能用符号链接这个库到/usr/lib了

原文地址:https://www.jb51.cc/ubuntu/352294.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐