ubuntu下安装caffe笔记

General dependencies

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

CUDA: Install by apt-get or the NVIDIA .run package. The NVIDIA package tends to follow more recent library and driver versions, but the installation is more manual. If installing from packages, install the library and latest driver separately; the driver bundled with the library is usually out-of-date. This can be skipped for CPU-only installation.

BLAS: install ATLAS by sudo apt-get install libatlas-base-dev or install OpenBLAS by sudo apt-get install libopenblas-dev or MKL for better CPU performance.

Python (optional): if you use the default Python you will need to sudo apt-get install the python-dev package to have the Python headers for building the pycaffe interface.

 

先按照官网的步骤把环境安装一下(我这里安装仅供CPU使用,跳过CUDA):

具体命令如下:

   

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 libatlas-base-dev

进入源码的python目录下:

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

 

Compilation with Make

Configure the build by copying and modifying the example Makefile.config for your setup. The defaults should work, but uncomment the relevant lines if using Anaconda Python.

cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest
  • 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!

Distribution: run make distribute to create a distribute directory with all the Caffe headers, compiled libraries, binaries, etc. needed for distribution to other machines.

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).

Now that you have installed Caffe, check out the MNIST tutorial and the reference ImageNet model tutorial.

 

我这里使用make编译:

按如上步骤编译主要有两个问题:

  

1.fatal error: hdf5.h: No such file or directory
2./usr/bin/ld: cannot find -lhdf5_hl  
 /usr/bin/ld: cannot find -lhdf5


主要是Makefile.config中的INCLUDE_DIRS,LIBRARY_DIRS两个变量找不到之前安装的
libhdf5-serial-dev,把相应的路径添加进去就可以啦
添加之后是这样的:

  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

 

然后再按照官网的流程就可以啦

 

参考帖子: http://blog.csdn.net/lkj345/article/details/51280369

 


顺便装下pycaffe

在源码根目录下运行如下命令:

  make pycaffe

错误如下:

‘numpy/arrayobject.h' file not found

找不到numpy

在python shell 运行如下命令查看numpy的目录:  

>>> import numpy as np
>>> np.get_include()

将此路径追加在之前的Makefile.config文件中PYTHON_INCLUDE变量后面,再次make pycaffe就编译ok

然后就是将caffe/python目录添加到环境变量中的问题了

~/.bashrc添加如下代码于最后一行:

  export PYTHONPATH={your path}:$PYTHONPATH

再source ~/.bashrc 一下,至此就ok了

 

 

 


 

 

posted @ 2017-06-04 19:20  rw_rongwei  阅读(315)  评论(0编辑  收藏  举报