RoboMaster

标题: 【分享帖】教程 || 在秒算上配置caffe [打印本页]

作者: XJTU DJI CLUB    时间: 2017-4-19 19:53
标题: 【分享帖】教程 || 在秒算上配置caffe
本文作者:钢蛋,权利归属原作者所有,未获得授权禁止转载!


妙算上面可以安装caffe,已测试成功.写个教程帮助后面想要安装的同学.

百度云链接:http://pan.baidu.com/share/init?shareid=3221400738&uk=1647165732密码:v037

相关安装包在“妙算”文件夹中

1.    首先是cuda的安装.

       妙算中是一块TK1.cuda6.5的离线安装包已上传至百度云,请下载之后,用下列命令安装:

       sudodpkg -i cuda-repo-l4t-r21.3-6-5-prod_6.5-42_armhf.deb

       sudoapt-get update

       sudoapt-get install cuda-toolkit-6-5

添加环境变量

[attach]12144[/attach]

运行下列命令测试是否安装成功


    nvcc -V

[attach]12141[/attach]
                                     

2.    opencv4tegra的安装

       在百度云下载安装包,使用如下命令安装:

       sudodpkg -i libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.deb

       sudoapt-get update

       sudoapt-get install libopencv4tegra libopencv4tegra-dev libopencv4tegra-python

3.    接下来是caffe需要的各种依赖库,参考caffe官方Installation.

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

整理如下:

       sudo apt-get install libprotobuf-dev libleveldb-devlibsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

    sudo apt-get install--no-install-recommends libboost-all-dev

   sudoapt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

4.安装openBLAS.这个直接下载下来make,make install,然后需要更新一下ubuntu/etc/ld.so.conf.d中的文件(我在文件夹中添加了一个opencv.conf),openBLASlib路径(默认是/opt/OpenBLAS/lib)写在opencv.conf末尾,然后在终端运行

sudo ldconfig使改动生效

5.解压caffe,然后复制Makefile.config.example并重命名为Makefile.config.打开Makefile.config

1)  找到

  
# 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.
  
  
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_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
  


然后把最后三行注释掉.变成下面这样:


  
#  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.
  
  
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_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
  

2)  修改BLAS的值为open

并修改BLAS_INCLUDEBLAS_LIB的路径

BLAS_INCLUDE:=/opt/OpenBLAS/include

BLAS_LIB:=/opt/OpenBLAS/lib

6.cd caffe的目录下,编译

make all

make test

make runtest



作者: XJTU DJI CLUB    时间: 2017-4-19 19:53
本帖最后由 XJTU DJI CLUB 于 2017-4-20 16:42 编辑

7.(可选)pycaffe的编译。如果想支持python接口,那么需要编译pycaffe。

1) 首先,需要apt-get安装numpy和scipy。

sudoapt-get install python-numpy

sudoapt-get install python-scipy

2) 然后需要用到pip。(没有pip的话先安装pip:sudo apt-get install python-pip)

cd到caffe-master/python目录下,在终端执行下面的命令:

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

如果权限不够,需要sudo,请执行

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

3) cd 到caffe-master下,make pycaffe.

4) 更新PYTHONPATH环境变量,把caffe-master/python添加进PYTHONPATH,这样才能在import的时候检索到相应的目录

sudo gedit ~/.bashrc

在文件的末尾添加如下代码:

#add caffe to PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/home/ubuntu/Downloads/caffe-master/python

保存文件之后,在终端执行:

source~/.bashrc

5) 这时候可以在python中import caffe试一下。没有什么提示就是成功了


[attach]12143[/attach]



PS:由于是安装后总结,也许会有疏漏,遇到error请google,baidu,bing...
作者: XJTU DJI CLUB    时间: 2017-4-19 20:00
那个……不知道为什么有几句突然成了表情,rio尴尬……晚一点修复
作者: Snail    时间: 2017-4-19 20:01
XJTU DJI CLUB 发表于 2017-4-19 20:00
那个……不知道为什么有几句突然成了表情,rio尴尬……晚一点修复

感谢分享   
作者: 琪琪心里苦    时间: 2017-4-19 20:11
钢蛋我们是视觉组的dalao~
作者: dasuda2015    时间: 2017-4-19 20:33
本帖最后由 dasuda2015 于 2017-4-19 20:45 编辑

厉害!!!之前装过opencv3.1,可以直接用吗,还是需要换回opencv4tegra版本?
作者: XJTU DJI CLUB    时间: 2017-4-20 17:13
dasuda2015 发表于 2017-4-19 20:33
厉害!!!之前装过opencv3.1,可以直接用吗,还是需要换回opencv4tegra版本?

我去特地问了大佬XD
[attach]12193[/attach]


作者: dugujuan    时间: 2018-8-19 11:22
66666666666666666666666666666666666666666666666666666666
作者: 梅川酷子    时间: 2019-1-19 21:47
感谢分享 感谢分享
作者: 墨雪流年K    时间: 2020-8-27 15:37
感谢大佬分享!




欢迎光临 RoboMaster (https://bbs.robomaster.com/) Powered by Discuz! X3.2