linux【ubuntu 14.04】下的【caffe】编译安装(CPU 配置)
来源:互联网 发布:js判断是不是在数组中 编辑:程序博客网 时间:2024/06/06 23:51
原文地址:https://www.zybuluo.com/hanxiaoyang/note/364737
特别鸣谢:七月在线 - 专注数据领域的在线教育:https://www.julyedu.com
(有部分修正)
caffe 是深度学习在图像领域广泛使用的框架,其 model zoo 有大量的预训练好的模型提供使用。图像相关应用会大量使用到caffe。
本文是关于Linux系统的,最好是centOS 7.0以上,或者Ubuntu 14.04以上,因为低版本的装不上兼容合适的 boost, opencv 等库。
1. 安装依赖的库
要确认一下,所有的库都装上了,否则编译出来可能不能使用。
其中 protobuf 是用来定义 layers 的,leveldb 是训练时存储图片数据的数据库,opencv 是图像处理库,boost 是通用 C++ 库,等……
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
sudo apt-get install libopenblas-dev python-numpy python-scipy python-matplotlib liblapack-dev libfreetype6-dev libpng12-dev
3. 安装其余依赖
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
4. 安装 git,拉取源码
sudo apt-get install git
git clone https://github.com/BVLC/caffe.git
克隆下来的文件夹 caffe 在主文件夹下
5. 安装 python 的 pip 和 easy_install,方便安装软件包
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.pysudo python ez_setup.py --insecure
wget https://bootstrap/pypa.io/get-pip.pysudo python get-pip.py
6. 安装 python 依赖(路径根据自己的目录可能要调整)
cd caffe/python
考虑到权限问题,切换到 root 用户:
sudo su执行:
for req in $(cat requirements.txt); do pip install $req; done
退出 root 用户权限:
exit
7. 编辑 caffe 所需的 Makefile 文件
cd caffesudo cp Makefile.config.example Makefile.configsudo gedit Makefile.config
Makefile.config 里面有依赖库的路径,以及各种编译配置,如果是没有GPU的情况,可以参照以下配置文件内容:
## 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# 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 := atlasBLAS := open# 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)/libBLAS_INCLUDE := /usr/include/openblas# 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)/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# 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/includeLIBRARY_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 := 1BUILD_DIR := buildDISTRIBUTE_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 ?= @
8. 编译 caffe
sudo make -j4
测试编译结果
sudo make test
sudo make runtest
9. 编译 pycaffe
sudo make pycaffe -j4将 caffe/python 添加到系统的 PYTHONPATH 环境变量中:
sudo gedit /etc/profile
export PYTHONPATH=$PYTHONPATH:/opt/caffe/python其中 /opt/caffe 是我的 caffe 路径 :( sudo mv caffe /opt )
source /etc/profile #使得对 profile 文件的修改生效或者重启计算机,使得对 profile 文件的修改生效
测试 caffe 的 python(2.7) 接口编译成功:
注意:
1) 大部分指令都需要加 sudo 赋予权限,否则可能会出现找不到文件等问题;
2) 我在编译过程中出现报错 fatal error: opencv2/core/core.hpp: No such file or directory. 虽然不知道问题出在什么地方,但是我重新安装了 libopencv-dev 就解决了这个问题:sudo apt-get install libopencv-dev
3) 目前仅完成配置和编译,所以可能还有其他问题,但是我不知道……
4) 换了台计算机试了一遍,缺少 scimage,需要加一个
sudo apt-get install python-scimage
0 0
- linux【ubuntu 14.04】下的【caffe】编译安装(CPU 配置)
- linux(ubuntu)下的caffe编译安装
- Ubuntu 16.04 下编译安装CPU版Caffe
- 虚拟机下Ubuntu安装CPU版本的caffe
- Ubuntu 16.04下CPU only模式的caffe安装
- 虚拟机环境下Ubuntu系统的Caffe安装 CPU-ONLY
- Ubuntu下配置caffe(CPU版本,无CUDA)
- ubuntu下深度学习框架caffe的安装(cpu模式下)
- ubuntu下opencv3.1.0+caffe安装教程(CPU-only)
- Ubuntu下安装Caffe(CPU Only)
- ubuntu 14.04下安装配置caffe
- Ubuntu-CPU-Caffe安装
- Windows与linux下caffe配置(仅CPU)
- caffe 安装与配置 (仅CPU版)以及Ubuntu 14.04 64位机上用Caffe+MNIST训练Lenet网络
- Ubuntu 14.04安装caffe only CPU
- Caffe:Windows(64位)+VS2013下的Caffe(CPU Only)安装配置
- caffe安装笔记(Ubuntu,CPU)
- Ubuntu 14.04 下 caffe 的安装
- java中判断字符是否是数字的几种方法
- pssh使用指南
- 在一张图片上实现截图功能
- [2016/12/15]perl程序勘误
- Hibernate依赖的JAR包用途
- linux【ubuntu 14.04】下的【caffe】编译安装(CPU 配置)
- PHP 5.2、5.3、5.4、5.5、5.6 版本对比及功能详解
- FMDB與SQLite 數據庫應用示範:打做一隻簡單的電影資料庫 App
- JS是按值传递还是按引用传递
- spring各jar包功能【整理】
- pip使用非默认地址更新&安装所需要的包
- mybatis和hibernate 解析
- lintcode,合并两个排序链表
- 【Linux】管道的Helloworld