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了