Caffe 编译安装_ubuntu12.04默认的cmake版本-程序员宅基地

技术标签: linux基础知识  caffe配置  深度学习 deep learning  

From: http://caffe.berkeleyvision.org/installation.html

安装

安装前,最好阅读下面的安装指导并注意和你的系统平台相关的细节问题。我们已经在 Ubuntu 14.04, Ubuntu 12.04, OS X 10.9,和OS X 10.8系统上成功的编译安装了Caffe。

Prerequisites

Caffe 依赖于很多的软件包。

  • CUDA 依赖库,版本 6.5 (推荐), 6.0, 5.5, 或 5.0,以及他们最新版本的驱动,  CUDA 5使用319.*(不要使用 331.*)。
  • BLAS (通过 ATLAS, MKL,或 OpenBLAS提供).
  • OpenCV.
  • Boost (>= 1.55,  只有1.55和1.56测试过)
  • glog, gflags, protobuf, leveldb,snappy,hdf5,lmdb
  • Python
    • Python 2.7, numpy (>= 1.7), boost-provided boost.python
  • MATLAB
    • 有mex编译器的MATLAB .

cuDNN Caffe: Caffe通过drop-in integration of NVIDIA cuDNN的加速方式来达到最快的执行速度。要加速你的Caffe模型, 请安装 cuDNN 然后在Makefile.config 文件中解注释USE_CUDNN := 1,这样安装Caffe后,就会自动加速.

CPU-only Caffe:  对于cold-brewed 只有CPU模式的Caffe,请在文件Makefile.config中,解注释CPU_ONLY := 1,然后以无CUDA的方式编译Caffe.这有助于云和集群方式的部署。

CUDA以及BLAS

Caffe 需要 CUDA nvcc 编译器来编译GPU 代码 ,需要CUDA驱动来操作GPU. 要安装 CUDA, 请参照NVIDIA CUDA 网站和网站上的安装说明.分别安装依赖库和最新的驱动; 和依赖库绑定的驱动通常版本比较老.警告 331.* CUDA 系列驱动有严重的性能问题: 不要使用.

为了达到最好的性能, Caffe 可以通过NVIDIA cuDNN加速.  cuDNN 网站注册是免费的, 安装完后继续下面的安装说明. 要使用cuDNN编译请在你的Makefile.config种设置USE_CUDNN := 1 .

Caffe 需要 BLAS作为矩阵和向量计算的后端( backend).有很多这个库的移植版本.可以自己根据情况选择:

  • ATLAS: 免费,开源代码,Caffe的默认依赖.
    • Ubuntu: sudo apt-get install libatlas-base-dev
    • CentOS/RHEL/Fedora: sudo yum install atlas-devel
    • OS X: 已经安装为 Accelerate / vecLib Framework.
  • Intel MKL: 商业版并且针对Intel的CPU做了优化, 可以免费试用,并且有学生版本.
    1. 安装 MKL.
    2. Makefile.config文件中设置 BLAS := mkl
  • OpenBLAS: 免费的并且开源; 优化的可并行的 BLAS, 虽然安装需要花点时间,但是确实可以提速 .
    1. 安装 OpenBLAS
    2. Makefile.config文件中设置 BLAS := open

Python 以及/或者 MATLAB 包 (可选)

Python

主要的依赖为 numpyboost.python (通过 boost提供). pandas 也是有用的并且是一些例子的依赖。

可以通过以下命令安装依赖:

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

但是我们强烈推荐首先安装提供了大部分需要的的依赖包和hdf5依赖库的 Anaconda Python distribution。

Ubuntu, 如果你的系统中使用的是默认的 Python,你需要通过 sudo apt-get 安装python-dev 包来安装Python 头文件。

Fedora,如果你的系统中使用的是默认的 Python,你需要通过 sudo yum 安装 python-devel包来安装Python 头文件。

OS X, Anaconda is the preferred Python. If you decide against it, please use Homebrew – but beware of potential linking errors!

安装完成后,如果要导入 caffe的Python模块,需要通过 export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH或者类似的方法添加模块路径到你的环境变量$PYTHONPATH .不可以在caffe/python/caffe路径中导入!

Caffe’的 Python 接口支持 Python 2.7. Python 3 或者更早的 Pythons.

MATLAB

安装MATLAB, 确保Matalab的 mex在你的环境变量 $PATH中.

Caffe的 MATLAB接口兼容于版本 2012b, 2013a/b, 和 2014a.

剩余的依赖

Linux

Ubuntu系统, 大部分的依赖可以通过下面的命令安装

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev

对于 Ubuntu 14.04剩余的依赖可以通过下面的命令安装

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

继续往下读,可以找到在Ubuntu 12.04如何手工编译和安装Google flags library, Google logging library 和 LMDB 的说明.

 CentOS / RHEL / Fedora, 大部分的依赖可以通过下面的命令安装

sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel

Google flags library, Google logging library 和 LMDB  已经有了CentOS / RHEL / Fedora上的新版本 所以最好先使用yum尝试安装这些库

sudo yum install gflags-devel glog-devel lmdb-devel

最后, 万一在你的系统源里找不到上面说的这些扩展库, 下面的命令教你如何在Ubuntu 12.04 / CentOS / RHEL / Fedora手工编译安装 (安装的时候可能需要root权限)

# glog
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 git://gitorious.org/mdb/mdb.git
cd mdb/libraries/liblmdb
make && make install

Note that glog does not compile with the most recent gflags version (2.1), so before that is resolved you will need to build with glog first.

OS X

OS X系统中, 极力推荐使用 Homebrew 软件管理器, 并且最好从一个干净的系统开始安装(或者  wiped/usr/local) 防止软件冲突.接下来,假设你使用的是Anaconda Python 和 Homebrew.

要安装 OpenCV,我们需要提供一个附加源给 Homebrew:

brew tap homebrew/science

如果使用的是Anaconda Python, 需要修改下 OpenCV的 配置. Do brew edit opencv and 修改和下面两行相似的两行位下面的两行.

  -DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib
  -DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7

备注: We find that everything compiles successfully if $LD_LIBRARY_PATH is not set at all, and$DYLD_FALLBACK_LIBRARY_PATH is set to to provide CUDA, Python, and other relevant libraries (e.g./usr/local/cuda/lib:$HOME/anaconda/lib:/usr/local/lib:/usr/lib).In otherENV settings, things may not work as expected.

NOTE: There is currently a conflict between boost 1.56 and CUDA in some configurations. Check theconflict description and try downgrading to 1.55.

10.8-specific Instructions

运行下面的指令:

brew install --build-from-source boost boost-python
brew install --with-python protobuf
for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew install $x; done

Building boost from source is needed to link against your local Python (exceptions might be raised during some OS X installs, butignore these and continue). If you do not need the Python wrapper, simply doingbrew install boost is fine.

Note that the HDF5 dependency is provided by Anaconda Python in this case.If you’re not using Anaconda, includehdf5 in the list above.

10.9-specific Instructions

在 OS X 10.9中, clang++ 是默认的 C++编译器,使用 libc++ 作为标准库. 但是, NVIDIA CUDA (甚至 6.0版) 但前只链接libstdc++. 这样就需要对每一个依赖改变编译设置.

在安装任何软件包前通过修改 Homebrew 的配置(formulae)实现编译设置 .确保Homebrew之前不安装任何软件依赖;所有的软件包都必须链接到libstdc++.

先前 Homebrew的配置为

boost snappy leveldb protobuf gflags glog szip lmdb homebrew/science/opencv

对每一个配置 brew edit FORMULA, 并且添加ENV 定义按照下面所示:

  def install
      # ADD THE FOLLOWING:
      ENV.append "CXXFLAGS", "-stdlib=libstdc++"
      ENV.append "CFLAGS", "-stdlib=libstdc++"
      ENV.append "LDFLAGS", "-stdlib=libstdc++ -lstdc++"
      # The following is necessary because libtool likes to strip LDFLAGS:
      ENV["CXX"] = "/usr/bin/clang++ -stdlib=libstdc++"
      ...

按照顺序修改配置, 运行

for x in snappy leveldb protobuf gflags glog szip boost boost-python lmdb homebrew/science/opencv; do brew edit $x; done

然后,运行

for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew uninstall $x; brew install --build-from-source --fresh -vd $x; done
brew uninstall protobuf; brew install --build-from-source --with-python --fresh -vd protobuf
brew install --build-from-source --fresh -vd boost boost-python

Note that brew install --build-from-source --fresh -vd boost is fine if you do not need the Caffe Python wrapper.

Note that the HDF5 dependency is provided by Anaconda Python in this case.If you’re not using Anaconda, includehdf5 in the list above.

Note that in order to build the Caffe Python wrappers you must installboost andboost-python:

brew install --build-from-source --fresh -vd boost boost-python

Note that Homebrew maintains itself as a separate git repository and making the abovebrew edit FORMULA changes will change files in your local copy of homebrew’s master branch. By default, this will prevent you from updating Homebrew usingbrew update, as you will get an error message like the following:

$ brew update
error: Your local changes to the following files would be overwritten by merge:
  Library/Formula/lmdb.rb
Please, commit your changes or stash them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

One solution is to commit your changes to a separate Homebrew branch, run brew update, and rebase your changes onto the updated master. You’ll have to do this both for the main Homebrew repository in/usr/local/ and the Homebrew science repository that contains OpenCV in/usr/local/Library/Taps/homebrew/homebrew-science, as follows:

cd /usr/local
git checkout -b caffe
git add .
git commit -m "Update Caffe dependencies to use libstdc++"
cd /usr/local/Library/Taps/homebrew/homebrew-science
git checkout -b caffe
git add .
git commit -m "Update Caffe dependencies"

然后,任何时候想要更新你自己的代码, 转回master分支, 进行update, rebase caffe 分支到master, 修正所有的conflicts:

# Switch batch to homebrew master branches
cd /usr/local
git checkout master
cd /usr/local/Library/Taps/homebrew/homebrew-science
git checkout master

# Update homebrew; hopefully this works without errors!
brew update

# Switch back to the caffe branches with the forumlae that you modified earlier
cd /usr/local
git rebase master caffe
# Fix any merge conflicts and commit to caffe branch
cd /usr/local/Library/Taps/homebrew/homebrew-science
git rebase master caffe
# Fix any merge conflicts and commit to caffe branch

# Done!            

At this point, you should be running the latest Homebrew packages and your Caffe-related modifications will remain in place.

Windows

There is an unofficial Windows port of Caffe at niuzhiheng/caffe:windows. Thanks @niuzhiheng!

编译

现在已经具备了所有的依赖条件, 编辑你的配置文件 Makefile.config,改变你的安装路径 (you should especially uncomment and setBLAS_LIB accordingly on distributions likeCentOS / RHEL / Fedora where ATLAS is installed under/usr/lib[64]/atlas),默认的配置是可以的,但是如果你使用的是Anaconda Python,请解注释相关的行。

cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python)
make all
make test
make runtest

编译的时候如果要引入cuDNN加速,你需要在文件Makefile.config中解注释USE_CUDNN := 1。

如果你的电脑上没有 GPU,你应该使用CPU-only模式的Caffe,请在文件Makefile.config中解注释CPU_ONLY := 1 。

要编译 Python 和 MATLAB 包,请独立的执行make pycaffe和make matcaffe . 请务必首先在Makefile.config中配置你的MATLAB 和 Python路径!

Distribution: 运行 make distribute来创建一个包含所有的Caffe 头文件, 编译好的依赖库,二进制文件等的分布式路径,用于其他机器的配置.

Speed: 如果要快速的编译,请通过make all -j8的方式并行编译,其中8是并行编译的线程的数量(并行线程的数量最好等于你机器CPU核的数量).

到目前为止,你已经安装了Caffe, 请参照 MNIST tutorial reference ImageNet model tutorial进行进一步的操作.

使用CMake (beta)编译

通过手工编辑Makefile.config的方式告诉 Caffe 寻找依赖的的位置, Caffe 也提供了一个基于 CMake的编译系统 (currently in “beta”).要求CMake 版本 >= 2.8.8. 基本的安装步骤如下:

mkdir build
cd build
cmake ..
make all
make runtest
Ubuntu 12.04

注意,在  Ubuntu 12.04中, Aptitude默认安装的CMake版本为2.8.7, 不能满足编译Caffe的CMake 版本需求 (版本至少为 2.8.8) ,如果你使用的系统是Ubuntu 12.04,可以尝试下面的安装步骤安装CMake 2.8.9或者升级到这个版本 :

sudo add-apt-repository ppa:ubuntu-sdk-team/ppa -y
sudo apt-get -y update
sudo apt-get install cmake

硬件问题

Laboratory Tested Hardware: Berkeley Vision runs Caffe with K40s, K20s, and Titans including models at ImageNet/ILSVRC scale. We also run on GTX series cards and GPU-equipped MacBook Pros. We have not encountered any trouble in-house with devices with CUDA capability >= 3.0. All reported hardware issues thus-far have been due to GPU configuration, overheating, and the like.

CUDA compute capability: 如果设备的运算能力 <= 2.0, 受限于设备的性能, 可能需要减少 CUDA的线程数量 和 批处理的 大小(sizes). 你的吞吐量可能会发生变化.

安装后, 参照我们的 reference performance numbers 确保所有的配置是正确的.

工程问题请参照  hardware/compatibility.

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/hdanbang/article/details/44961563

智能推荐

c# 调用c++ lib静态库_c#调用lib-程序员宅基地

文章浏览阅读2w次,点赞7次,收藏51次。四个步骤1.创建C++ Win32项目动态库dll 2.在Win32项目动态库中添加 外部依赖项 lib头文件和lib库3.导出C接口4.c#调用c++动态库开始你的表演...①创建一个空白的解决方案,在解决方案中添加 Visual C++ , Win32 项目空白解决方案的创建:添加Visual C++ , Win32 项目这......_c#调用lib

deepin/ubuntu安装苹方字体-程序员宅基地

文章浏览阅读4.6k次。苹方字体是苹果系统上的黑体,挺好看的。注重颜值的网站都会使用,例如知乎:font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, W..._ubuntu pingfang

html表单常见操作汇总_html表单的处理程序有那些-程序员宅基地

文章浏览阅读159次。表单表单概述表单标签表单域按钮控件demo表单标签表单标签基本语法结构<form action="处理数据程序的url地址“ method=”get|post“ name="表单名称”></form><!--action,当提交表单时,向何处发送表单中的数据,地址可以是相对地址也可以是绝对地址--><!--method将表单中的数据传送给服务器处理,get方式直接显示在url地址中,数据可以被缓存,且长度有限制;而post方式数据隐藏传输,_html表单的处理程序有那些

PHP设置谷歌验证器(Google Authenticator)实现操作二步验证_php otp 验证器-程序员宅基地

文章浏览阅读1.2k次。使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。下载谷歌验证类库文件放到项目合适位置(我这边放在项目Vender下面)https://github.com/PHPGangsta/GoogleAuthenticatorPHP代码示例://引入谷_php otp 验证器

【Python】matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距-程序员宅基地

文章浏览阅读4.3k次,点赞5次,收藏11次。matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距

docker — 容器存储_docker 保存容器-程序员宅基地

文章浏览阅读2.2k次。①Storage driver 处理各镜像层及容器层的处理细节,实现了多层数据的堆叠,为用户 提供了多层数据合并后的统一视图②所有 Storage driver 都使用可堆叠图像层和写时复制(CoW)策略③docker info 命令可查看当系统上的 storage driver主要用于测试目的,不建议用于生成环境。_docker 保存容器

随便推点

网络拓扑结构_网络拓扑csdn-程序员宅基地

文章浏览阅读834次,点赞27次,收藏13次。网络拓扑结构是指计算机网络中各组件(如计算机、服务器、打印机、路由器、交换机等设备)及其连接线路在物理布局或逻辑构型上的排列形式。这种布局不仅描述了设备间的实际物理连接方式,也决定了数据在网络中流动的路径和方式。不同的网络拓扑结构影响着网络的性能、可靠性、可扩展性及管理维护的难易程度。_网络拓扑csdn

JS重写Date函数,兼容IOS系统_date.prototype 将所有 ios-程序员宅基地

文章浏览阅读1.8k次,点赞5次,收藏8次。IOS系统Date的坑要创建一个指定时间的new Date对象时,通常的做法是:new Date("2020-09-21 11:11:00")这行代码在 PC 端和安卓端都是正常的,而在 iOS 端则会提示 Invalid Date 无效日期。在IOS年月日中间的横岗许换成斜杠,也就是new Date("2020/09/21 11:11:00")通常为了兼容IOS的这个坑,需要做一些额外的特殊处理,笔者在开发的时候经常会忘了兼容IOS系统。所以就想试着重写Date函数,一劳永逸,避免每次ne_date.prototype 将所有 ios

如何将EXCEL表导入plsql数据库中-程序员宅基地

文章浏览阅读5.3k次。方法一:用PLSQL Developer工具。 1 在PLSQL Developer的sql window里输入select * from test for update; 2 按F8执行 3 打开锁, 再按一下加号. 鼠标点到第一列的列头,使全列成选中状态,然后粘贴,最后commit提交即可。(前提..._excel导入pl/sql

Git常用命令速查手册-程序员宅基地

文章浏览阅读83次。Git常用命令速查手册1、初始化仓库git init2、将文件添加到仓库git add 文件名 # 将工作区的某个文件添加到暂存区 git add -u # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,不处理untracked的文件git add -A # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,包括untracked的文件...

分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120-程序员宅基地

文章浏览阅读202次。分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120

【C++缺省函数】 空类默认产生的6个类成员函数_空类默认产生哪些类成员函数-程序员宅基地

文章浏览阅读1.8k次。版权声明:转载请注明出处 http://blog.csdn.net/irean_lau。目录(?)[+]1、缺省构造函数。2、缺省拷贝构造函数。3、 缺省析构函数。4、缺省赋值运算符。5、缺省取址运算符。6、 缺省取址运算符 const。[cpp] view plain copy_空类默认产生哪些类成员函数

推荐文章

热门文章

相关标签