Ubuntu 18.04 源码安装 caffe 步骤 【自用】

安装环境

  1. OS: Ubuntu 18.04 64 bit
  2. 显卡: NVidia RTX 2080Ti
  3. CUDA: 10.1
  4. cuDNN: 7.5
  5. Python: 3.6

安装 OpenCV

  1. OpenCV 安装步骤

安装依赖

$ sudo apt install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
$ sudo apt install -y --no-install-recommends libboost-all-dev
$ sudo apt install -y libatlas-base-dev
$ sudo apt install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

下载源码

$ git clone https://github.com/BVLC/caffe.git
$ cd caffe
$ cp Makefile.config.example Makefile.config

修改配置

  1. 修改 Makefile.config 如下:
...
USE_CUDNN := 1
...
OPENCV_VERSION := 3
...
CUDA_DIR := /usr/local/cuda-10.1
...
CUDA_ARCH :=    \
                -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
...
MATLAB_DIR := /usr/local/MATLAB/MATLAB_Production_Server/R2015a
...
# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_INCLUDE :={$HOME}/.virtualenvs/py3caffe/include/python3.6m \
            {$HOME}/.virtualenvs/py3caffe/lib/python3.6/site-packages
...
WITH_PYTHON_LAYER := 1
...
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /usr/local/cuda/include /usr/local/include/opencv2
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

编译

$ make -j8
$ make pycaffe
$ make matcaffe

测试 pycaffe

$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
  1. 缺什么库则使用 pip 安装。

测试 matcaffe

$ make mattest
  1. 若遇到类似问题:
Invalid MEX-file ‘**/caffe.mexa64’
/usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version CXXABI_1.3.8 not found (required by /usr/lib/x86_64-linux-gnu/libgflags.so.2)
  1. 解决方案:
sudo ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin/glnxa64/libstdc++.so.6

你可能感兴趣的:(环境安装)