本来实在windows 10上尝试安装caffe,装了一天没装上,放弃; 改在windows上装ubuntu的双系统,装了一个下午,不小心windows的系统盘被锁死了,也不会unlock?只好含泪卸掉了windows10,只装ubuntu 15.10。过程真是让人揩一把辛酸泪。。。不过又在ubuntu中用错了一个命令,系统崩溃,重新安装win8.1 + ubuntu 14.04, 成功,继续安装caffe。。。

安装:

ubuntu 14  .04,

1. 安装开发所需依赖包:

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

2. 安装CUDA 7.5:

根据Nvidia官方文档http://developer.download.nvidia.com/compute/cuda/7.5/Prod/docs/sidebar/CUDA_Installation_Guide_Linux.pdf一步一步安装

  1) 确定GPU支持CUDA

lspci | grep -i nvidia

  结果显示:

  

http://developer.nvidia.com/cuda-gpus去验证,发现支持CUDA

  2) 确定linux版本支持CUDA:

uname -m && cat /etc/*release

  结果显示:

  

  3) 确定系统已经安装了gcc:

gcc --version

  结果显示:

  

  4) 确定系统已经安装了正确的Kernel Headers和开发包:

  查看系统正在运行的kernel版本:

uname -r

  结果:4.2.0-35-generic,这个是必须安装的kernel headers和开发包的版本

  安装对应的kernels header和开发包:

sudo apt-get install linux-headers-$(uname -r)

  5) 安装CUDA:下载对应版本的cuda,从https://developer.nvidia.com/cuda-downloads,下载deb(network)版

  首先进行md5校验:

md5sum cuda-repo-ubuntu1404_7.-18_amd64.deb

  对比相同,然后使用deb文件进行安装:

sudo dpkg -i cuda-repo-ubuntu1404_7.-18_amd64.deb
sudo apt-get update
sudo apt-get install cuda

  重启,完成cuda安装

3. 安装cuDNN

下载从https://developer.nvidia.com/rdp/cudnn-download cuDNN,版本为cudnn-7.0-linux-x64-v3.0-prod.tgz

tar -zxvf cudnn-7.0-linux-x64-v3.0-prod.tgz
cd cuda
sudo cp lib64/* /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.7.0
sudo ln -s libcudnn.so.7.0.6 libcudnn.so.7.0
sudo ln -s libcudnn.so.7.0 libcudnn.so

4. 设置环境变量:

在/etc/profile中添加CUDA 环境变量

sudo gedit /etc/profile,在打开的文件中加入如下两句话

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

保存后,使环境变量立即生效:source /etc/profile

5. 安装cuda samples

进入/usr/local/cuda/samples,执行下面的命令来build samples

sudo make all -j4

全部编译完成后,进入 samples/bin/x86_64/linux/release, 运行deviceQuery: ./deviceQuery

如果出现显卡信息,则驱动及显卡安装成功,结果如下:

安装成功!

6. 安装Intel MKL,openBlas 或Atlas:

我选择的是Atlas,为caffe默认使用的,不要额外配置,安装命令

sudo apt-get install libatlas-base-dev

7. 安装opencv:

首先安装必须的包

sudo apt-get install cmake git libgtk2.-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

从opencv官网下载最新版本opencv,opencv-3.1.0.zip

解压unzip opencv-3.1.0.zip

编译

cd  opencv-3.1.
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

测试是否安装成功:

 mkdir ~/opencv-workshop
cd ~/opencv-workshop/
gedit DisplayImage.cpp
gedit CMakeLists.txt
cmake .
make

其中 Display.cpp的代码为

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv; int main(int argc, char** argv)
{
Mat image;
image = imread(argv[], );
if (!image.data)
{
printf("No image data\n");
return -;
}
namedWindow("display", WINDOW_AUTOSIZE);
imshow("display", image);
waitKey();
return ;
}

其中 CMakeList.txt的内容是

cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
find_package(OpenCV REQUIRED)
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})

脚本运行后,运行可执行文件,看是否能正确显示图片,能,则成功

./DisplayImage ~/图片/--\ \:\:01屏幕截图.png 

8. 安装caffe所需要的Python环境Anaconda:

按caffe推荐,python环境使用Anaconda,去官网下载安装包http://conda.pydata.org/miniconda.html,

下载Anaconda2-4.0.0-Linux-x86_64.sh,切换到文件所在路径,执行

bash Anaconda2-4.0.-Linux-x86_64.sh

按照提示进行安装。

安装好后,在/etc/ld.so.conf中添加一下路径:/home/wm/anaconda2/lib

在~/.bashrc最后添加下面一句:

export LD_LIBRARY_PATH="/home/wm/anaconda2/lib:$LD_LIBRARY_PATH"

9. 安装python依赖库

下载caffe源码,解压后进入caffe-master下的python目录,

(首先要安装python-pip

sudo apt-get install python-pip

)执行如下命令

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

10. 编译Caffe

进入caffe-master目录,复制一份Makefile.config.examples

cp Makefile.config.example Makefile.config 

修改Makefile.config中的路径,只需要将默认的Python路径注释掉,去掉对Anaconda路径的注释,并且开启CuDNN和Opencv3的支持即可,修改好的如下:

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome! # cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := # CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := # uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV :=
# USE_LEVELDB :=
# USE_LMDB := # 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 := # Uncomment if you're using OpenCV 3
OPENCV_VERSION := # 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. \
# /usr/lib/python2./dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2. \
$(ANACONDA_HOME)/lib/python2./site-packages/numpy/core/include \ # Uncomment to use Python (default is Python )
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3./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 := # 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 := BUILD_DIR := build
DISTRIBUTE_DIR := distribute # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := # The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := # enable pretty build (comment to see full commands)
Q ?= @

保存退出,编译

make all
make test
make runtest

没有报错,成功。

11. 使用MNIST数据集进行测试

1) 数据预处理:

sh data/mnist/get_mnist.sh 

2) 重建lmdb/leveldb文件,命令

sh examples/mnist/create_mnist.sh 

3) 训练mnist,命令

sh examples/mnist/train_lenet.sh

这是可以看到caffe的训练过程,至此caffe配置已成功:

接下来会学习caffe的使用。。。 加油

Ubuntu 14.04上安装caffe的更多相关文章

  1. 翻译:在Ubuntu 14.04上安装FTP服务器的方法

    说明: 1.原文地址:http://www.krizna.com/ubuntu/setup-ftp-server-on-ubuntu-14-04-vsftpd/ 2.今天要做一个网络日志的迁移程序,搬 ...

  2. Ubuntu 14.04 上安装 Gurobi

    参考: Installing Gurobi 7 on Linux Ubuntu 14.04 上安装 Gurobi 1.在gurobi上创建一个账户,并登陆: 2.从gurobi optimizer上下 ...

  3. 在Ubuntu 14.04 上安装 FTP 服务

    1. sudo apt-get update 2. sudo apt-get install vsftpd 3. adduser sammy Assign a password when prompt ...

  4. 如何在 Ubuntu 14.04 上安装 Elasticsearch,Logstash 和 Kibana

    介绍 在本教程中,我们将去的 Elasticsearch 麋鹿堆栈安装 Ubuntu 14.04 — — 那就是,Elasticsearch 5.2.x,Logstash 2.2.x 和 Kibana ...

  5. 在Ubuntu 14.04 上安装网易云音乐

    之前因为电脑有网络的原因,一直使用网页网易云音乐听歌,最近电脑没网络使用,才发现网易云音乐有linux版本,果断下载. 在Chrome浏览器中,登陆官网下载Linux版本中的Ubuntu 14.04 ...

  6. ubuntu 14.04 上安装有道词典

    Ubuntu 14.04用户在安装前要更新系统,即update&dist-upgrade. 下载地址:32/64bits http://codown.youdao.com/cidian/lin ...

  7. 在ubuntu 14.04上安装2.6的内核

    1.到http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.tar.bz2这里下载最新的稳定版内核: 2.根据各自系统,安装如下软件:l b ...

  8. 在 Ubuntu 14.04 上安装 Ubuntu Tweak 0.8.8

    转自:http://linux.cn/article-3335-1.html 关于 Ubuntu Tweak,Ubuntu 老用户再熟悉不过了,Ubuntu tweak 相当于 windows 的优化 ...

  9. Ubuntu 14.04上安装Riak

    一.安装riak   1. 安装包:riak_2.0.2-1_amd64.deb    路    径:~/software/riak_2.0.2-1_amd64.deb 2. 安装riak     $ ...

随机推荐

  1. linux 第一题 计算题

    #!/bin/bash echo "输入第一个数字" read A b= ]] do && [[ ${A} != *[!]* ]] then echo " ...

  2. iOS进阶_地图上定位的标志——大头针

    一.添加大头针 地图使用的框架是MapKit 大头针走的是MKAnnotation协议 /* 注意:因为是满足协议MKAnnotation,所以没有MKAnnotation的系统大头针类,必须自定义大 ...

  3. javascript基础知识-函数

    1.javascript中函数有两种定义方式: 函数语句定义和表达式定义 //函数有定义 function test(){ console.log("This is a function&q ...

  4. Drupal 7 安装时的数据库问题

    在安装D7时,需要用PhpMyAdmin创建数据库,不建议使用ROOT帐号而需要建立一个新的帐号.一般,建立一个新的账号,如foo,并同时建一个同名的数据库,选择localhost(如果是本地).但是 ...

  5. (原创)巩固理解基于DS18B20的1-wire协议(MCU,经验)

    1.Abstract     如前篇随笔所写,将以前遇到最难懂的两个部分重拾一下.前一篇写的是I2C协议(http://www.cnblogs.com/hechengfei/p/4117840.htm ...

  6. leetcode sort List

    Sort a linked list in O(n log n) time using constant space complexity. /** * Definition for singly-l ...

  7. PeerConnection

    Example(摘) /*When two peers decide they are going to set up a connection to each other, they both go ...

  8. markdown语法记录

    换行:在结尾加两个空格后回车. 缩进:将输入法切换到全角,两个空格就是两个汉字的大小.

  9. 【TextBox】重写右键菜单

    参考资料 http://bbs.csdn.net/topics/390324356 http://www.cnblogs.com/ycxy/archive/2012/10/09/2716852.htm ...

  10. Hello Raspberry Pi

    Raspberry Pi 入手好一段时间了,原意是想撸 linux,但是后来一整年都在忙孩子房子户口本子的事,这玩意也就搁了一年尘. 最近终于被生活折腾到了尾声,开始找一些东西来折腾折腾. 一.什么是 ...