Xavier安装caffe

Xavier 安装caffe

1.安装各种依赖包

  • sudo apt-get update
  • sudo apt-get install build-essential cmake git pkg-config``
  • sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler``
  • sudo apt-get install libatlas-base-dev``
  • sudo apt-get install libboost-all-dev``
  • sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev``
  • sudo apt-get install python-pip``
  • sudo apt-get install libopencv-dev
  • sudo apt-get install python-dev
  • sudo apt-get install python-numpy python-scipy
  • sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev

2.安装caffe

  • git clone https://github.com/BVLC/caffe.git //从github上git caffe

修改Makefile.conf配置文件

  • cd caffe
  • sudo cp Makefile.config.example Makefile.config
  • sudo gedit Makefile.config
  • 若使用cudnn,则将****# USE_CUDNN := 1**** 修改成: *USE_CUDNN := 1*
  • 若要使用python来编写layer,则需要将****# WITH_PYTHON_LAYER := 1**** 修改为 *WITH_PYTHON_LAYER := 1*
  • 若使用的opencv版本是3的,则将****# OPENCV_VERSION := 3**** 修改为: *OPENCV_VERSION := 3*

img

  • 重要的一项将****# Whatever else you find you need goes here.****下面的
  • *INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include*
  • *LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib*

*修改为:*

  • ***\*INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial\****
  • ***\*LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu/hdf5/serial\****

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

中的

​ -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 \

删除,如果不删除,对caffe进行编译时会报错。报错如下图:

img

修改Makefile文件

1
2
3
4
5
将Makefile文件中的
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
替换为NVCCFLAGS +=-D_FORCE_INLINES-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)将LIBRARIES+= glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
修改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5

修改host_config.h文件

  • sudo gedit /usr/local/cuda/include/crt/host_config.h
  • #error -- unsupported GNU version! gcc versions later than 7 are not supported! 注释掉

设置环境变量

  • sudo gedit ~/.bashrc
  • 在最后加入以下内容:

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

export PATH=$PATH:/usr/local/cuda-10.0/bin

export PATH=/usr/local/cuda-10.0/bin:$PATH

进入caffe目录进行编译

  • cd caffe
  • make all
  • make runtest
  • make pycaffe
  • 最后,终端输入python,然后再输入import caffe,如果无问题则安装成功。

img

如果在make runtest的时候出现如下错误,可能是CUDA_ARCH 的问题,但不影响后续的使用,可忽略。

img

updatedupdated2020-10-172020-10-17