×

caffe 安装(ubuntu14.04)

96
EchoIR
2017.06.23 22:12* 字数 2156

结合blog.csdn.net/ubunfans/article/details/47724341/

(1)Ubuntu安装后关闭自动更新(上一次安装caffe后用的很好,结果有一天晚上没关电脑,自己半夜更新了显卡驱动,然后...)

(2)安装开发所需的依赖包:

sudo apt-get install build-essential  # basic requirement
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler #required by caffe

可能会出现问题:E:未发现软件libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

原因:源出现问题,更新源:sudo apt-get update,可是不管用但是后来去王枫那里拷了sourses.list,再update还是两次不可用,但是手写输入软件包就可以了,也不知是格式问题还是王枫的管用了

CUDA7.5安装

CUDA:compute Unified Device Architecture,统一计算设备架构,并行计算平台和程序设计模型,使GPU除了显卡的图像计算之外,还可以更复杂的计算,包括并行计算等

后面我在没有卸载之前cuda7.5的基础上又安装了cuda8.0(按照官网教程),据说并不需要卸载之前的,主要看有没有冲突就是了,而且想用哪个,可以直接换一下后面的路径配置

注意:我的计算机只有一张显卡,应该不需要关闭lightdm服务,并且不需要升级gcc与g++,,还是4.8,主要还是去看官网的.pdf教程(我的网盘里面应该有)

(1)System Requirements

* CUDA-capable GPU:

lspci | grep -i nvidia

Verify You Have a Supported Version of Linux:

查看系统distribution and release number
$ uname -m && cat /etc/*release(uname,查看系统信息命令;-m(machine)显示主机的硬件(CPU)名)

Verify the System Has gcc Installed

gcc --version

Verify the System has the Correct Kernel Headers and Development Packages Installed

uname -r (–release,显示linux操作系统内核版本号)

(2)Choose an Installation Method(我用离线.deb安装:deb安装分离线和在线,我选择离线local)

      *$ md5sum

(3)Handle Conflicting Installation Methods(若之前没有安装过,此步骤没有必要)

(4)安装:

     * Install repository meta-data

        $ sudo dpkg -i cuda-repo-__.deb
        Eg: sudo dpkg -i我下载的deb包名

     * Update the Apt repository cache

       $ sudo apt-get update

     * Install CUDA

       $ sudo apt-get install cuda

(5)安装后期步骤

     *环境变量的设置

sudo gedit ~/.bashrc
export PATH=”/usr/local/cuda-7.5/bin:$PATH”
export LD_LIBRARY_PATH=”/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH”
source ~/.bashrc


注意两行中间不需要什么分隔符的,安装8.0只需要改一下这个路径就行,不需要去卸载7.5的,甚至这边路径都直接换成“cuda”,因为后面会在相同路径下生成一个”cuda”连接,指向最新的cuda

(6)安装列子

cd /usr/local/cuda/samples
sudo make all -j8
cd samples/bin/x86_64/linux/release
./deviceQuery #运行deviceQuery

如若出现显卡信息,则驱动以及显卡安装成功

...(此处省略,想看,网上很容易找到),比如:

NOTE:上边的显卡信息是从别的地方拷过来的,我的GTX650显卡不是这些信息,如果没有这些信息,那肯定是安装不成功,找原因吧!还得注意的是我在安装8.0的时候,运行这个总是报错FAIL,后面电脑重启就行了。

安装cudnn7.0_v4.0

注意V3.0的会出错,用作GPU加速,注意后面因为又安装了cuda8.0,现在我再安装cudnn8.0配置上去:/home/echo/personalfiles/files_tostall/cuda

tar -zxvf cudnn-7.0-linux-x64-v4.0-prod.tgz
cd cuda
sudo cp lib64/lib* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/
cd /usr/local/cuda/lib64/sudo rm -rf libcudnn.so libcudnn.so.4
sudo chmod u=rwx,g=rx,o=rx libcudnn.so.4.0.7
sudo ln -s libcudnn.so.4.0.7 libcudnn.so.4
sudo ln -s libcudnn.so.4 libcudnn.so
sudo ldconfig

安装Intel MKL或Atlas

用作基本的向量,矩阵运算,对intel cpu优化,速度极快

sudo apt-get install libatlas-base-dev

安装OpenCV

面又重新安装了一下,可能是之前没有进入2.4的目录直接执行了,这样安装的目录就会不一样了吧

cd Install-OpenCV-master/Ubuntu/2.4
sh ./opencv2_4_10.sh

安装Caffe所需要的Python环境

按caffe官网的推荐使用Anaconda

cd文件所在目录
bash anaconda2-4.1.1-linux-x86_64.sh

注意:我原来的python是python 2.7.6(default ,jun22...),现在重新打开终端就是python 2.7.12 | Anaconda4.1.1(64-bit) |...

添加环境变量(PATH在安装时添加过了在~/.bashrc中):

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/echo/anaconda2/lib"
source ~/.bashrc

安装python依赖库

cd ~/caffe-master/python
For req in $(cat requirements.txt);do pip install $req;done

编译Caffe

cd caffe-master
cp Makefile.config.example Makefile.config

修改Makefile.config,最后应该如下:

------------------------------------------Makefile.config---------------------------------------------

# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @

------------------------------------------END---------------------------------------------

-------------------------------------------补充make命令------------------------------------

Make all -j8 #估计就是make -j8
www.cnblogs.com/louyihang-loves-baiyan/archive/2016/03/10/5260863.html
这里关于make[target]做了一些解释

首先我们需要明白make做的事构建,对应的是我们IDE中的build,他并不是compile,是准备各种资源配置,为编译做准备,具体的编译还是交给了GCC这样的编译器。

------------------------------------------END---------------------------------------------

make all -j8
make test-j8
make runtest -j8 #make runtest中的测试就算不通过也不会耽误使用的,make runtest花的时间会比较长,因为他把所有的test文件都跑了一遍,当我们在make runtest之前,我们已经执行了make test,即会生成test相关的可执行文件。makefile里面有# Define buildtargets,关于all,test等targets的定义。

编译Python wrapper

make  pycaffe

结束~~~啦啦

Caffe
Web note ad 1