使用Anaconda虚拟环境编译caffe-gpu pycaffe
1. 前提:
安装前服务器情况,已经安装好了:
CUDNN=7.3.0
CUDA=10.0.130
Opencv 2.4.13
相应命令为:
cuda 版本
cat /usr/local/cuda/version.txt
cudnn 版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
opencv版本
pkg-config opencv --modversion
2. 准备caffe, python环境
- 从
https://github.com/BVLC/caffe
下载caffe, 用unzip命令解压. - python我使用的是Anaconda虚拟环境, 最后附上environment_caffe_27.yml文件, 如果需要可以直接使用下面的命令安装,或者手动安装.
```
conda env create -f environment_caffe_27.yml
```
environment_caffe_27.yml文件内容如下,复制重命名即可:
name: caffe_27
channels:
- defaults
dependencies:
- backports=1.0=py27_1
- backports.functools_lru_cache=1.5=py27_1
- backports.shutil_get_terminal_size=1.0.0=py27_2
- backports_abc=0.5=py27_0
- blas=1.0=mkl
- ca-certificates=2019.1.23=0
- certifi=2019.3.9=py27_0
- cloudpickle=0.8.0=py27_0
- cycler=0.10.0=py27_0
- cytoolz=0.9.0.1=py27h14c3975_1
- dask-core=1.1.5=py_0
- dbus=1.13.6=h746ee38_0
- decorator=4.4.0=py27_1
- enum34=1.1.6=py27_1
- expat=2.2.6=he6710b0_0
- fontconfig=2.13.0=h9420a91_0
- freetype=2.9.1=h8a8886c_1
- functools32=3.2.3.2=py27_1
- futures=3.2.0=py27_0
- glib=2.56.2=hd408876_0
- gst-plugins-base=1.14.0=hbbd80ab_1
- gstreamer=1.14.0=hb453b48_1
- h5py=2.9.0=py27h7918eee_0
- hdf5=1.10.4=hb1b8bf9_0
- icu=58.2=h9c2bf20_1
- imageio=2.5.0=py27_0
- intel-openmp=2019.3=199
- ipython=5.8.0=py27_0
- ipython_genutils=0.2.0=py27_0
- jpeg=9b=h024ee3a_2
- kiwisolver=1.0.1=py27hf484d3e_0
- leveldb=1.20=hf484d3e_1
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=8.2.0=hdf63c60_1
- libgfortran-ng=7.3.0=hdf63c60_0
- libpng=1.6.36=hbc83047_0
- libprotobuf=3.2.0=0
- libstdcxx-ng=8.2.0=hdf63c60_1
- libtiff=4.0.10=h2733197_2
- libuuid=1.0.3=h1bed415_2
- libxcb=1.13=h1bed415_1
- libxml2=2.9.9=he19cac6_0
- linecache2=1.0.0=py27_0
- matplotlib=2.2.3=py27hb69df0a_0
- mkl=2019.3=199
- mkl_fft=1.0.10=py27ha843d7b_0
- mkl_random=1.0.2=py27hd81dba3_0
- ncurses=6.1=he6710b0_1
- networkx=2.2=py27_1
- nose=1.3.7=py27_2
- numpy=1.16.2=py27h7e9f1db_0
- numpy-base=1.16.2=py27hde5b4d6_0
- olefile=0.46=py27_0
- openssl=1.1.1b=h7b6447c_1
- pandas=0.24.2=py27he6710b0_0
- pathlib2=2.3.3=py27_0
- pcre=8.43=he6710b0_0
- pexpect=4.6.0=py27_0
- pickleshare=0.7.5=py27_0
- pillow=5.4.1=py27h34e0f95_0
- pip=19.0.3=py27_0
- prompt_toolkit=1.0.15=py27_0
- protobuf=3.2.0=py27_0
- ptyprocess=0.6.0=py27_0
- pygments=2.3.1=py27_0
- pyparsing=2.3.1=py27_0
- pyqt=5.9.2=py27h05f1152_2
- python=2.7.16=h9bab390_0
- python-dateutil=2.8.0=py27_0
- python-gflags=3.1.2=py27_0
- pytz=2018.9=py27_0
- pywavelets=1.0.2=py27hdd07704_0
- pyyaml=5.1=py27h7b6447c_0
- qt=5.9.7=h5867ecd_1
- readline=7.0=h7b6447c_5
- scandir=1.10.0=py27h7b6447c_0
- scikit-image=0.14.2=py27he6710b0_0
- scipy=1.2.1=py27h7c811a0_0
- setuptools=40.8.0=py27_0
- simplegeneric=0.8.1=py27_2
- singledispatch=3.4.0.3=py27_0
- sip=4.19.8=py27hf484d3e_0
- six=1.12.0=py27_0
- snappy=1.1.7=hbae5bb6_3
- sqlite=3.27.2=h7b6447c_0
- subprocess32=3.5.3=py27h7b6447c_0
- tk=8.6.8=hbc83047_0
- toolz=0.9.0=py27_0
- tornado=5.1.1=py27h7b6447c_0
- traceback2=1.4.0=py27_0
- traitlets=4.3.2=py27_0
- unittest2=1.1.0=py27_0
- wcwidth=0.1.7=py27_0
- wheel=0.33.1=py27_0
- xz=5.2.4=h14c3975_4
- yaml=0.1.7=had09818_2
- zlib=1.2.11=h7b6447c_3
- zstd=1.3.7=h0b5b093_0
- pip:
- cython==0.29.6
- dask==1.1.5
prefix: /opt/anaconda/envs/caffe_27
关于环境需要说明一下:
- 在下载的caffe-master中, 有requirements.txt, 也可以先新建虚拟环境, 然后激活后使用
pip install -r python/requirements.txt
安装包. - protobuf版本在requirements.txt中值写了最小值,实测最新版的protobuf不知此, 建议安装3.2版本, 即使用
conda install protobuf=3.2
- requirements.txt中,要求
python-dateutil>=1.4,<2
, 但是这个版本太老了找不到, 我安装的了2.8版本,实测编译通过,调用正常.
3. 复制修改Makefileconfig文件
cp Makefile.config.example Makefile.config
`vim Makefileconfig.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). #使用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
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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, 我的版本是2
OPENCV_VERSION := 2
# 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-10.0
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility. # 此处我使用的是cuda10
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_37,code=sm_37 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50 \
-gencode arch=compute_61,code=compute_61 \
-gencode arch=compute_70,code=compute_70 \
-gencode arch=compute_75,code=compute_75
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := 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 := /opt/OpenBLAS/include
BLAS_LIB := /opt/OpenBLAS/lib
# 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.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 := /opt/anaconda/envs/caffe/caffe_27
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/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 := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
# 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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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
# N.B. both build and distribute dirs are cleared on `make clean`
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 ?= @
4. 虚拟环境添加到环境变量,不然报错(亲自踩坑,但是不解)
参考链接找不到了, 但是店家内容如下:
export PATH="/opt/anaconda/envs/bin:$PATH"
5. 开始编译
make all –j8
make test –j8
make runtest –j8
make pycaffe -j8
详细参考博文: Ubuntu16.04 14.04安装配置Caffe(GPU版), 解释很详细,如果用我的python环境,不需要按照博文再安装其他的包,直接编译即可.
6. 测试
source activate caffe_27
, 其中caffe_27是我的虚拟环境名称, 然后输入python
:
再输入import caffe
导入成功~,,,(折腾了一天,心累)
使用Anaconda虚拟环境编译caffe-gpu pycaffe的更多相关文章
- (原)Ubuntu16中编译caffe
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5797526.html 参考网址: http://caffe.berkeleyvision.org/in ...
- caffe安装教程(Ubuntu14+GPU+pycaffe+anaconda2)
caffe安装教程 本文所使用的底层环境配置:cuda8.cudnn6.OpenCV2.4.5.anaconda2(Python2.7).如使用其他版本的环境,如cuda,可安装自己的版本,但须在相应 ...
- caffe-安装anaconda后重新编译caffe报错
ks@ks-go:~/caffe-master$ make -j16 CXX/LD -o .build_release/tools/convert_imageset.bin CXX/LD -o .bu ...
- Ubuntu16.04安装编译caffe以及一些问题记录
前期准备: 最好是python虚拟环境 [anaconda的创建虚拟环境] 创建 conda create -n caffeEnv(虚拟环境名字) python=3.6 激活环境 source act ...
- ubuntu14.04下安装cudnn5.1.3,opencv3.0,编译caffe及配置matlab和python接口过程记录
已有条件: ubuntu14.04+cuda7.5+anaconda2(即python2.7)+matlabR2014a 上述已经装好了,开始搭建caffe环境. 1. 装cudnn5.1.3,参照: ...
- win10+caffe+GPU
由于学习需要,决定安装caffe,之前用的都是基于theano的keras.听说win下caffe很难配置,经过一个下午和晚上的配置终于成功,以此记录. 我的电脑:win10 64位,N卡GTX950 ...
- Ubuntu16.04 faster-rcnn+caffe+gpu运行环境配置以及解决各种bug
https://blog.csdn.net/flygeda/article/details/78638824 本文主要是对近期参考的网上各位大神的博客的总结,其中,从安装系统到跑通程序过程中遇到的各种 ...
- vs2015编译caffe
有些时候,需要在python3的环境下import caffe,需要用vs2015在python3的环境下,编译pycaffe. microsoft的windows版本的caffe,依赖的库Nuget ...
- 【Caffe】Ubuntu 安装 Caffe gpu版
安装环境:Ubuntu 16.04lts 64位, gcc5.4 gpu1050ti,cuda8.0,cudnn5.1.10 1. 安装依赖库 sudo apt-get install libprot ...
随机推荐
- flask 基础语法学习
回顾 #6行flask from flask import Flask app = Flask(__name__) @app.route("/") def index(): ret ...
- 网络&协议目录
HTTP [基础] HTTP入门学习 网络基础 数据传输 网站架构演化 连接管理 缓存 [组成] URL 报文起始行 报文首部 [结构] Web服务器 代理 网关.隧道和中继 [安全] Web攻击技术 ...
- 开放源代码的设计层面框架Spring——day04
spring第四天 一.Spirng中的JdbcTemplate 1.1JbdcTemplate概述 他是spring框架中提供的一个对象,是对原始Jd ...
- Python——一个简单的类的创建和应用
1.创建类,设置属性和给属性设定默认值,设置方法并访问类的属性: 2.利用类创建多个实例,以及调用类的方法的两种办法: 3.设置更新属性的函数,并更新实例的属性. class dog(object): ...
- kaldi chain模型的序列鉴别性训练代码分析
chainbin/nnet3-chain-train.cc int main(int argc, char *argv[]) { ... Nnet nnet; ReadKaldiObject(nnet ...
- web前端效率提升-nginx+nodejs搭建本地生态
1.起因 编写的项目是一个偏向于后台管理的web系统,使用了angular框架,在绑定数据的时候就依赖于后台的接口格式. 以前是后台写好接口后,我在绑定,在这之前一些逻辑是没法做的,有时候后台接口给的 ...
- 【interview——Ali】project interview_18 summer
完全没有准备的一次面试……意外 两部分:Word2vec + 中位数 (还有聊对科研的想法和自己研究能力的评价? word2vec //解释模型 原本是one-hot,存在缺点:稀疏和无法表现语义,词 ...
- C# 文件下载工具类FileDownHelper
using System; using System.IO; using System.Threading; using System.Web; namespace 落地页测试代码 { public ...
- !!!css如何让img图片居中?css的display属性实现图片居中(代码实例)
在我们开发前端页面的时候,为了让页面效果美观,会让图片呈现居中效果.那么css怎么让img图片居中显示呢?本篇文章给大家带来css如何让img图片居中?css的display属性实现图片居中(代码实例 ...
- javascript 总结(常用工具类的封装)
1. type 类型判断 isString (o) { //是否字符串 return Object.prototype.toString.call(o).slice(8, -1) === 'Strin ...