General dependencieshtml
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.python
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.linux
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.shell
先按照官网的步骤把环境安装一下(我这里安装仅供CPU使用,跳过CUDA):bash
具体命令以下:app
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目录下:ui
for req in $(cat requirements.txt); do pip install $req; done
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.spa
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
USE_CUDNN := 1
switch in Makefile.config
. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration.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!.net
Distribution: run make distribute
to create a distribute
directory with all the Caffe headers, compiled libraries, binaries, etc. needed for distribution to other machines.code
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了