Caffe编译安装全记录

来源:互联网 发布:怎么ping网络通不通 编辑:程序博客网 时间:2024/05/02 01:16

Caffe是一个卷积神经网络深度学习框架。

编译安装的操作系统为CentOS7.0。


安装通用依赖:yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel atlas-devel

yum install cmake

yum install glibc-devel

yum install gcc-gfortran


安装gflags,glob和lmdb


1.gflags
wget https://github.com/schuhschuh/gflags/archive/master.zip 
unzip master.zip 
cd gflags-master 
mkdir build && cd build 
export CXXFLAGS="-fPIC"
cmake ..
make VERBOSE=1
make
make install


2.lmdb
克隆项目,git clone https://github.com/LMDB/lmdb 
cd lmdb/libraries/liblmdb 
make && make install


3.glog
csdn下载地址:http://download.csdn.net/detail/chenguangxing3/6661667
tar zxvf glog-0.3.3.tar.gz 
cd glog-0.3.3 
./configure
make 
make install


4.hdf5
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.0-patch1/src/hdf5-1.10.0-patch1.tar
tar -xvf hdf5-1.10.0-patch1.tar
cd hdf5-1.10.0-patch1
./configure --prefix=/usr/local/hdf5
make
make install


最后编译caffe
export LD_LIBRARY_PATH=/usr/local/lib
1.git clone https://github.com/bvlc/caffe.git
2.cp Makefile.config.example Makefile.config
3.vi Makefile.config
去掉CPU_ONLY := 1前的#(表示Caffe编译时仅支持CPU,不支持GPU)
4.make -j(多线程编译,利用所有CPU,加快编译速度)
5.make test
6.make runtest
7.如果期望用python,还可以make pycaffe

测试一下caffe:
sh data/mnist/get_mnist.sh
sh examples/mnist/create_mnist.sh
vi /root/caffe/examples/mnist/lenet_solver.prototxt将solve_mode:GPU改为CPU
sh examples/mnist/train_lenet.sh
在/root/caffe/examples/mnist下生成的以caffemodel为后缀的文件即为caffe训练生成的模型文件


问题解决:
1.如果make caffe时报hdf5相关文件找不到,则:
cd /usr/local/hdf5
cp include/* /usr/local/include/
cp lib/* /usr/local/lib


2.报#include "leveldb/db.h"有问题
需要安装google kv数据库leveldb
git clone https://github.com/google/leveldb.git
cd leveldb
make
cp --preserve=links out-shared/libleveldb.so* /usr/local/lib
cp -r include/leveldb/ /usr/local/include/


3.报错
/usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -latlas
安装blas和cblas
wget http://www.netlib.org/blas/blas-3.7.0.tgz
tar -zxvf blas-3.7.0.tgz
cd BLAS-3.7.0
gfortran -c  -O3    *.f 
ar rv libblas.a      *.o
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
tar -zxvf cblas.tgz
cd CBLAS
cp /root/BLAS-3.7.0/libblas.a  testing

mv Makefile.in Makefile.in.bak

cp Makefile.LINUX Makefile.in

make
cp include/cblas.h /usr/include/
cp lib/cblas_LINUX.a /usr/local/libcblas.a
cp testing/libblas.a /usr/local/lib
gcc -shared lib/cblas_LINUX.a testing/libblas.a -o libcblas.so
cp libcblas.so /usr/local/
cp /usr/local/libcblas.* /usr/local/lib/


ln -s /usr/lib64/atlas/libsatlas.so /usr/lib64/libatlas.so


1.cmd caffe的使用

把对应的路径加入path即可,如:

export PATH=$PATH:/root/caffe/build/tools

则可以使用caffe:


2.使用pycaffe:

安装需要的所有python第三方库:

Cython>=0.19.2
numpy>=1.7.1
scipy>=0.13.2
scikit-image>=0.9.3
matplotlib>=1.3.1
ipython>=3.0.0
h5py>=2.2.0
leveldb>=0.191
networkx>=1.8.1
nose>=1.3.0
pandas>=0.12.0
python-dateutil>=1.4,<2
protobuf>=2.5.0
python-gflags>=2.0
pyyaml>=3.10
Pillow>=2.3.0
six>=1.1.0

则可以直接在代码里使用pycaffe:


如果pycaffe编译保错:

a.安装python-devel, yum install python-devel

b.安装numpy,yum install numpy

0 0
原创粉丝点击