. 前提:

安装前服务器情况,已经安装好了:

  1. CUDNN=7.3.0

  2. CUDA=10.0.130

  3. 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

-----------------------------------------以上是别人的前提条件,我的电脑这些都已安装好,下面是我的前提环境

准备caffe, python环境

https://github.com/BVLC/caffe下载caffe, 用unzip命令解压

python我使用的是Anaconda3虚拟环境, 最后附上environment_caffe_27.yml文件, 如果需要可以直接使用下面的命令安装,或者手动安装.

conda env create -f environment_caffe_27.yml

我是手动在caffe文件下创建的

具体内容如下:我创建的虚拟环境名称是caffe_27,   python2.7

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: /home/zhai/anaconda3/envs/caffe_27

接下来就是在caffe路径下,打开命令界面,并进入刚才创建的虚拟环境caffe_27并激活

然后在caffe路径下有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版本,实测编译通过,调用正常.我也是直接执行上面的命令,后面没有报错。

复制修改Makefileconfig文件,修改Make文件

cp Makefile.config.example 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  #!!!!!!!!!!!!!!!!!!!!!# 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
# 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.
CUDA_ARCH := -gencode arch=compute_50,code=sm_50 \-gencode arch=compute_52,code=sm_52 \-gencode arch=compute_60,code=sm_60 \-gencode arch=compute_61,code=sm_61 \-gencode arch=compute_61,code=compute_61
# !!!!!!!!!!!!!!!!!!!!!!!!
# 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 := /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.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)/anaconda3/envs/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 /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 ?= @

修改Makefile文件,下面是我修改后的。

修改 caffe 目录下的 Makefile 文件(这两个不改都会报错,编译类型错误等等。)

将:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

将:NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

makefile上面两个可以不改,但是下面这个的改,亲测,不改会出错,因为编译时会出现下面的错误

ImportError: No module named google.protobuf.internal

解决方法:

首先查看 protobuf 信息

whereis protoc  #查看那些路径下安装了protobuf
which protoc  #查看默认选用的protobuf
protoc --version  #查看当前默认的protobuf的版本(配置caffe时很重要

我一开始改为我的虚拟环境caffe_27下的protoc,失败,还是老老实实的改为系统环境的,问题解决了(但是就是不知道为啥改为自己虚拟环境的就不行)

接下来虚拟环境添加到环境变量,不然报错

gedit ~/.bashrc

export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH(注意:path/to是自己caffe的路径) ,如下我的

export PYTHONPATH=/home/zhai/caffe/python:$PYTHONPATH

保存, 生效

source ~/.bashrc 

开始编译

make all –j8
make test –j8
make runtest –j8
make pycaffe  -j8

我是把能避免的坑到都考虑了,这里尽量没有坑。按照我的这个步骤现在是没坑的 ,放一个编译测试成功的图

当执行最后一个命令时,我的又出现问题了

Makefile:517: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

查了一下 原因是Makefile.config里python路径没有配置对
解决方法:
1.打开终端,输入python,输入以下命令得到python2.7的地址

2.在Makefile.config中找到PYTHON_INCLUDE := /usr/include/python2.7 \这一行,修改下面一行的地址为刚刚得到的地址,再次编译即可。说白了,就是由于我的粗心,把这个位置的三行都要取消注释,我只取消一行,太粗心了。

测试

在这个虚拟环境下

输入python:
再输入import caffe 导入成功

如下

看看时间已经凌晨3点,希望明天能睡个早觉!

参考:https://www.cnblogs.com/geoffreyone/p/10696045.html

https://blog.csdn.net/qq_33431368/article/details/84717053

ubuntu16.04+anaconda3+python2.7虚拟环境+caffe配置过程及踩坑经历相关推荐

  1. ubuntu16.04+cuda8.0+cudnn5.1+caffe 安装(基于独立主机集成显卡GTX1080Ti)

    最近开始配置自己的深度学习主机,由于之前只在笔记本上和单显卡主机上安装过,所以可以说是zero经验,以至于很多问题不了解都当成了bug,故为了方便以后的自己以及大众,特在此写下post一篇.(由于可能 ...

  2. 几乎完美安装! NVIDIA Jetson Nano B01 Ubuntu 18.04.3 LTS 的 ROS 安装和菜鸟的踩坑记录【会继续完善】

    几乎完美安装! NVIDIA Jetson Nano B01 Ubuntu 18.04.3 LTS 的 ROS 安装和菜鸟的踩坑记录 NVIDIA Jetson Nano B01技术规格 Ubuntu ...

  3. 为Jupyter notebook配置R kernel过程及踩坑记录

    为Jupyter notebook配置R kernel过程及踩坑记录 注意:本文为作者安装过程及折腾的过程,内容比较冗杂,如果读者想直接创建一个属于自己的子环境则参考: 如下文章: anaconda下 ...

  4. ubuntu16.04+Virtualenv+python2.7+Caffe安装(CPU版本,无opencv)

    环境: Ubuntu16.04 AMD 64位 双核 python 2.7.12 虚拟环境:Virtualenv 虚拟环境路径如下: (python2.7) appleyuchi@ubuntu:~/. ...

  5. Ubuntu16.04 +cuda8.0+cudnn+opencv+caffe+theano+tensorflow配置明细

    本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.c ...

  6. Ubuntu16.04+GT720M + Cuda8.0+py-faster-rcnn(caffe)

    Ubuntu16.04 + GT 720M + Cuda8.0+ Py-faster-rcnn(caffe) Cuda8.0 安装 cuda 的安装其实挺简单的,有两种安装方法,一种使用deb文件,另 ...

  7. ubuntu16.04+nvidia gt740m+cuda7.5+caffe安装、测试经历

    首先说明,这是在笔记本上的安装测试经历,首先安装的win10,然后安装ubuntu16.04双系统,显卡为nvidia gt740m win10上没有装nvidia gt740m驱动,也就是用的集显, ...

  8. 复现STGCN CPU版 (ubuntu16.04+pytorch0.4.0+openpose+caffe)

    前提:ubuntu下将python3.5.2设为默认(百度) 一.下载stgcn (gitbub上fork后导入到gitee快些):  st-gcn: Spatial Temporal Graph C ...

  9. caffe搭建--caffe在invidia+cpu 酷睿2Q9300 + ubuntu16.04.2上面的安装和编译过程

    本文原创,转载请注明出处. ------------------------------------------------分割线-------------------------------- 概要 ...

最新文章

  1. AutoCAD VBA:过三点创建一个圆
  2. js运动动画的八个知识点
  3. XCTF-高手进阶区:php_rce
  4. linux中的mysql使用_Linux下安装和使用MySQL(二)
  5. gc java root_深入理解Java中的Garbage Collection
  6. 新书预告<******笔记>快赏
  7. linux svn服务的维护,Linux服务器搭建svn环境方法详解_网站服务器运行维护,Linux,svn...
  8. 悟空CRM客户关系管理系统测试
  9. php微信卡券创建、生成二维码等
  10. BOCHS 模拟器和我的启动代码
  11. Fast Walsh-Hadamard Transform (快速沃尔什变换)
  12. jpress连接不上mysql_JPress安装部署超详细文档
  13. Debussy 快速上手教程
  14. 软件质量之道:PCLint之中的一个
  15. Java 的 IDEA 神级插件!
  16. 【电脑运用及修理】Internet Explorer 浏览器
  17. 烤仔TVの尚书房 | 听博闻聊聊中心化交易所的那些八卦
  18. 解决ubuntu下kazam录制视频无法在windows播放问题
  19. 第二章 操作系统的硬件环境
  20. 华为鲁勇:自己做的降落伞自己先跳 华为云这样赢得客户信赖

热门文章

  1. border(元素边框详解)
  2. 科技云报道:东数西算不止于“算”,更需“新存储”
  3. 数据结构实验3、单链表的基本操作实现
  4. 梅科尔工作室-张黎娜-鸿蒙笔记2
  5. axios拦截器 config_axios拦截器
  6. Axios拦截器(Interceptors)
  7. hive踩坑笔记 —— 开窗函数为聚合函数时,加order by 与不加 order by的区别
  8. 【译】Spring Boot Features
  9. 如何和业务方建立良好的合作关系
  10. 如何清洁Mac键盘,显示器等