Caffe安装教程(原创)

转载请注明地址html

说明:本文档参考自Caffe官网的安装说明,http://caffe.berkeleyvision.org/installation.htmlpython

若是对安装过程当中,须要用到的依赖不明,请自行百度其做用。Ubuntu系统的安装请自行百度。 linux

1.安装环境git

硬件:Intel E3 CPUNVIDIA  GTX960 GPU; 操做系统:Ubuntu14.04github

2.依赖安装bash

接下来的安装所有使用linux命令行操做网络

(1)通用依赖 架构

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 

(2)CUDA安装app

可使用apt-get方式,或者去官网下载linux系统下的.run包进行离线安装。因为apt-get指令拿到的软件包一般不是最新的,官网推荐使用.run包的方式进行离线安装。工具

对于没有GPU的同窗来讲,能够跳过这一步以后在编译源码时配置CPU-ONLY)。

1)下载CUDA.run

地址:https://developer.nvidia.com/cuda-downloads 

根据本身的OSCPU架构选择.run包并下载

2)退出桌面环境

使用键盘Ctrl+Alt+F1,系统退出桌面版,进入命令行模式。

注意:此时有些系统会遇到黑屏问题。解决方法:切回桌面版本(Ctrl+Alt+F7),修改/etc/default/grub文件中GRUB_CMDLINE_LINUX_DEFAULT的值为nomodeset,更新grub(sudo update-grub),重启电脑(或者重启电脑,在启动时进入grub设置中,将倒数第2行的roquiet splash 后面空格添加nomodesetF10启动系统,而后再按ctrl+alt+F1发现能够正常进入字符界面了)。

(安装时遇到这个问题,我经过后一种方式解决) 

3)退出X Windows桌面环境

sudo stop lightdm

4)安装CUDA .run

.run包加上可执行权限:

chmod +x cuda_7.5.18_linux.run

执行.run包:

./cuda_7.5.18_linux.run 

5)返回X Windows桌面环境

sudo start lightdm
Ctrl+Alt+F7

6)cuDNN 安装(可选)

若是使用 cuDNN 优化神经网络, 须要安装 cudnn-v5.0 以上版本。 该软件的安装很是简单。

tar -xzvf cudnn-7.5-linux-x64-v5.0-ga.tgz
cd cudnn-7.5-linux-x64-v5.0
sudo cp lib* /usr/local/cuda/lib64/
sudo cp cudnn.h /usr/local/cuda/include/

(3)BLAS

sudo apt-get install libatlas-base-dev

(4)Python

若是使用默认Python的方式进行Caffe开发,则须要安装python开发包。

sudo apt-get install python-dev

(5)兼容性说明 

操做系统

版本

兼容性说明

Ubuntu

16.04

CUDA8是被须要的

14.04

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

12.04

须要手动安装依赖(以下)

 

若是是Ubuntu12.04,须要手动安装兼容性依赖,以下:

wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make && make install
# gflags
wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make && make install
# lmdb
git clone https://github.com/LMDB/lmdb
cd lmdb/libraries/liblmdb
make && make install

3.编译Caffe源代码并安装

Caffe源码支持make编译,或者CMake方式进行编译。编译前请确认已经安装好了gcc工具链(sudo apt-get install build-essential),若是使用CMake构建工程,请确认安装好CMake

(1)下载Caffe源码

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

或者在github官网搜索Caffe,选择须要的分支而后Zip打包下载。

(2)Make编译源码

说明1

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 

说明2

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 Caffes GPU acceleration.

For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config. 

(3)CMake方式构建工程并编译

根据须要能够配置Makefile.config

mkdir build
cd build
cmake ..
make all
make install
make runtest 

若是编译没有报Error,在runtest时一切OK,那么说明安装完成。能够开始Caffe的第一个小例子MNIST

相关文章
相关标签/搜索