服务器上安装caffe的过程记录

时间:2023-03-09 15:36:25
服务器上安装caffe的过程记录

1. 前言

因为新的实验室东西都是新的,所以在服务器上要自己重新配置CAFFE

这里假设所有依赖包学长们都安装好了,我是没有sudo权限的

服务器的配置:

CUDA 8.0

Ubuntu 16.04 LTS

Tesla K80


2. 安装Caffe

先从GITHUB上CLONE下CAFFE的安装包

git clone https://github.com/BVLC/caffe.git

复制编译配置文件:

cp Makefile.configure.example Makefile.configure

然后按照 http://caffe.berkeleyvision.org/installation.html#compilation 的指示:

  • For CPU & GPU accelerated Caffe, no changes are needed.
  • For cuDNN acceleration using NVIDIA’s proprietary cuDNN software, uncomment the USE_CUDNN := 1 switch in Makefile.config. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration.
  • For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.

To compile the Python and MATLAB wrappers do make pycaffe and make matcaffe respectively. Be sure to set your MATLAB and Python paths in Makefile.config first!

注释掉Makefile中相应行以适应自己的环境:

vi Makefile.configure

然后编译:

make all
make test
make runtest

如果想提高编译速度,可以使用:

make all -j16
make test -j16
make runtest -j16

原因参考:

Speed: for a faster build, compile in parallel by doing make all -j8 where 8 is the number of parallel threads for compilation (a good choice for the number of threads is the number of cores in your machine).

3. 编译过程中的问题与解决方法

在编译过程中如果遇到hdf5问题,参考如下:[1]

在make all这一步遇到了一些问题,首先是找不到hdf5.h,在Makefile.config中INCLUDE_DIRS后添加/usr/include/hdf5/serial即可继续编译。

src/caffe/layers/hdf5_data_layer.cpp:13:18: fatal error: hdf5.h: No such file or directory

但是此后又出现如下问题,

/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5

可以在LIBRARY_DIRS后添加/usr/lib/x86_64-linux-gnu/hdf5/serial/,最终Makefile.config文件对应部分修改如下,

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/

以上的操作保证Caffe编译过程中可以找到hdf5的头文件和共享库文件。


hdf5问题解决后,运行make test -j16

然后遇到很多人都会遇到的问题:

ffe.so.1.0.*** Aborted at  (unix time) try "date -d @1502862874" if you are using GNU date ***
PC: @ 0x7f9fd538c428 gsignal
*** SIGABRT (@0x42700005a63) received by PID (TID 0x7f9fdf310780) from PID ; stack trace: ***
@ 0x7f9fd57313e0 (unknown)
@ 0x7f9fd538c428 gsignal
@ 0x7f9fd538e02a abort
@ 0x7f9fd53ce7ea (unknown)
@ 0x7f9fd53d6e0a (unknown)
@ 0x7f9fd53da98c cfree
@ 0x6fa00b caffe::LayerFactoryTest_TestCreateLayer_Test<>::TestBody()
@ 0x9785b3 testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x971bca testing::Test::Run()
@ 0x971d18 testing::TestInfo::Run()
@ 0x971df5 testing::TestCase::Run()
@ 0x9730cf testing::internal::UnitTestImpl::RunAllTests()
@ 0x9733f3 testing::UnitTest::Run()
@ 0x4c5b4d main
@ 0x7f9fd5377830 __libc_start_main
@ 0x4cd8d9 _start
@ 0x0 (unknown)
Makefile:: recipe for target 'runtest' failed

找了很久也没找到适合的解决方法,但是学长说RUN TEST不通过也可以正常运行程序,好吧那就先这样,接下来

4. PYTHON接口

编译了PYTHON:

make pycaffe -j16

然后到此结束,下面是训练一下MNIST网络看看CAFFE能不能用:(注意目前是在CAFFE主文件夹下)

sh data/mnist/get_mnist.sh

sh examples/mnist/create_mnist.sh

sh examples/mnist/train_lenet.sh

等3分钟就会结束

服务器上安装caffe的过程记录

准确率为99.08%

5. Matlab接口

如果要编译Matlab的Caffe接口,需要首先在Makefile.config中修改MATLAB的路径使得路径下有/bin

具体来说,如下图中可以看到当前目录下有/bin文件夹,

服务器上安装caffe的过程记录

所以,在Makefile.configure中,Matlab的路径应该填写为

/opt/MATLAB/R2014b

然后运行

make matcaffe

以编译。

编译成功后如图:

服务器上安装caffe的过程记录

再运行

make mattest

来检查编译是否成功

检查成功后如图:

服务器上安装caffe的过程记录

如果找不到你自己的Matlab安装路径,可以使用:

find / -name matlab

然后就可以找到所有有Matlab名字的文件其所在位置


参考文献:

[1] http://blog.****.net/lkj345/article/details/51280369

[2] http://blog.****.net/solomon1558/article/details/52015754

[3] http://www.it610.com/article/4919314.htm