Ubuntu14.04 Caffe安装

Wesley13
• 阅读 562

Caffe简介

Caffe全称Convolutional Architecture for Fast Feature Embedding,是一个计算CNN相关算法的框架。就目前来说是deeplearning最流行的开源的框架,所以使用的人也是最多的。
caffe网址:http://caffe.berkeleyvision.org/
github网址:https://github.com/BVLC/caffe/

安装环境

系统:Ubuntu14.04 Desktop x64(建议使用刚安装好的系统,同时不要更新,不然会影响后面的某些环节)
显卡:支持CUDA的显卡,当然这个不是必须的

依赖程序

基本包

安装开发需要的一些基本包

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install gfortran ## python中安装scipy需要依赖gfortran

:Ubuntu默认环境虽然已经有gcc,但并没有提供C/C++的编译环境,单独安装编译环境比较复杂,所以提供了build-essential命令一键来构建所需的编译环境。

CUDA(可选)

cuda在caffe编译和使用中不是必须的,如果实在没有支持cuda的显卡或者只想尝试一下caffe,不需要用它来进行复杂的训练,不安装也可以。
安装链接:http://blog.csdn.net/honyniu/article/details/46387429

CuDNN(可选)

这个库是基于cuda,当然也是可选的。
安装链接:http://blog.csdn.net/honyniu/article/details/46388241

BLAS(必选)

这个库提供了caffe需要的一些基本的矩阵和向量库,这个是必选的。
安装链接:http://blog.csdn.net/honyniu/article/details/46388915

OpenCV(必选)

OpenCV提供了图像处理和计算机视觉的库,在caffe使用中是必须的,同时最好自己编译安装。
安装链接:http://blog.csdn.net/honyniu/article/details/46390097

其他依赖项

caffe需要一些特定的数据库的操作, 因此需要安装leveldb, lmdb, hdf5等库。 此外, caffe采用了google的一些库, 比如protobuf以及glog, 这些也需要安装,命令如下。

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

Matlab和python

这两个不是必须的,但是caffe提供了bash、matlab和python的接口,同时caffe许多的可视化接口都是通过python实现的,推荐安装。
matlab在这里使用的是Matlab-R2014A,这里就不讲怎么安装得了,自己去百度教程,默认安装即可,安装在’/usr/local/MATLAB’目录下。
ubuntu默认安装的2.7的版本但是为了安装Python开发环境,方便今后编译其他扩展库,命令如下

sudo apt-get install python-dev

python是使用的虚拟环境,具体虚拟环境的构建见http://blog.csdn.net/honyniu/article/details/46382929
激活虚拟环境

source ENV/bin/activate

安装编译pycaffe的依赖包, 进入caffe安装目录中的python文件夹, 你会看到一个requirements.txt, 首先, 修改protobuf那一行为protobuf==2.5.0, 然后执行下面命令:

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

这里我们没安装caffe推荐的anaconda包, 因为安装之后进不去桌面。而且anaconda包只是一个自带了requirements.txt中所有选项的python集合库, 将上面的库安装好之后, 不装anaconda没有任何影响。

配置编译

caffe程序

可以去上面的caffe的github网址把caffe最新代码下载下来,也可以使用git命令获取,如下

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

caffe配置

终于到了最后的一步了,如果安装好了上面的所有的caffe的依赖,那么下面就可以对caffe进行配置和编译了。
首先拷贝生成所需要的’Makefile.config’文件,caffe安装包下面给提供了example,注意直接拷贝下面的可能会报错,因为每一行命令的后面不能有空白的字符串,有可能会导致编译不通过。

cp Makefile.config.example Makefile.config

然后对该’Makefile.config’文件根据自己的需求进行修改,下面是我的配置以及一些注释。

## 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 := 1   #如果没有安装cudnn的注掉

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1   #如果没有安装cuda,不是要GPU的设置开启  

# 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   #cuda默认安装目录(其实是软链接),一般不需要修改,但如果没有安装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 := mkl   #这里使用的是Intel MKL,如果使用的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 := /opt/intel/mkl/include   #如果是atlas,这两个路径要注掉
BLAS_LIB := /opt/intel/mkl/lib/intel64

# 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/R2014a   #Matlab的路径,没安装Matlab或者不需要编译该接口可以注掉
# 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库的路径,使用的是虚拟环境capy这里就是一直提到的ENV,有时候可能不起作用,还是会报错,不知道为什么,那就设置下面的export,一般就没问题了。
PYTHON_INCLUDE := /home/huayong/capy/include/python2.7 \
                /home/huayong/capy/lib/python2.7/site-packages/numpy/core/include

#If it doesn't work above, you can try this below.
export CPLUS_INCLUDE_PATH=/home/huayong/capy/include/python2.7:/home/huayong/capy/lib/python2.7/site-packages/numpy/core/include

# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := /home/wenzheng/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
                # $(ANACONDA_HOME)/include/python2.7 \
                # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib/x86_64-linux-gnu
# PYTHON_LIB := $(ANACONDA_HOME)/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

# 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

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 ?= @

caffe编译

基本的编译,j代表是多线程编译,一般前两个命令不会出错,最后一个可能会出错,但有时候也不影响使用。

make all -j8
make alltest -j8
make runtest

编译matlab和python接口,这个当然不是必须的,看你自己的需求。

make pycaffe
make matcaffe

结束语

到这来我们就成功编译好了caffe,那么下面就要开始真正的caffe使用之旅了。下面有时间会把自己学习使用caffe的一些过程写下来,包括训练测试caffe提供的examples,caffe的可视化,运行一些caffe经典的例子(如R-CNN)。

本文同步分享在 博客“无比机智的永哥”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
2年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
待兔 待兔
2个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Wesley13 Wesley13
2年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
7个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这