Ubuntu18.04下安装配置Caffe-SSD-GPU版本

文章目录

      • 1. 安装依赖项
      • 2. Clone Caffe-SSD源码
      • 3. 文件配置
      • 4. 编译Caffe-SSD
      • 5. 配置环境变量
      • 6. 测试


  • 系统版本:Ubuntu18.04
  • 系统环境:OpenCV3.4.1,Python2
  • OpenCV3.4.1安装:Ubuntu18.04 下安装OpenCV3.4.1

1. 安装依赖项

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

2. Clone Caffe-SSD源码

git clone https://github.com/weiliu89/caffe.git caffe-ssd
cd caffe
git checkout ssd

这里需出现分支成功的提示方可继续:

Branch ssd set up to track remote branch ssd from origin.
Switched to a new branch ‘ssd’

3. 文件配置

cd caffe-ssd
cp Makefile.config.example Makefile.config
  • 修改Makefile.config文件
1.若使用Cudnn
  将# USE_CUDNN := 1 前的注释取消
  即:USE_CUDNN := 1

2.若使用opencv3.x
  取消 # OPENCV_VERSION := 3 前的注释
  即:OPENCV_VERSION := 3
 
3.若是用Python编程
  取消 # WITH_PYTHON_LAYER := 1 前的注释
  即:WITH_PYTHON_LAYER := 1 
 
4.加入hdf5的目录:
  将
	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/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

5. 如果使用的是Cuda>8.0,则将
    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_61,code=sm_61
    修改为:
	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_61,code=sm_61
  • 修改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)
LIBRARIES += boost_thread stdc++后加boost_regex
 
修改为:
 
LIBRARIES += boost_thread stdc++ boost_regex

4. 编译Caffe-SSD

make -j16
make py
make runtest -j16
make test -j16

编译过程可能会出现如下错误:

  • 错误1:Caffe-ssd编译错误.
Makefile:570: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

解决方法:Caffe-ssd编译错误:Makefile:570: recipe for target ‘.build_release/lib/libcaffe.so.1.0.0-rc3’ failed

  • 错误2:
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail_106501::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail_106501::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
collect2: error: ld returned 1 exit status
······

解决方法:Caffe-SSD错误:.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail_106501::cpp_reg

5. 配置环境变量

首先,打开配置文件

vim ~/.bashrc

在文件的最后一行添加以下路径

export PYTHONPATH=~/caffe-ssd/python:$PYTHONPATH

让配置文件生效

source ~/.bashrc

6. 测试

XXX@XXX:~$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>

如果不报错,则配置成功!


在import caffe的时候可以会遇到以下问题:

  • 错误1:ImportError: No module named skimage.io. 详细如下:
>>> import caffe
Traceback (most recent call last):
  File "", line 1, in <module>
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/pycaffe.py", line 15, in <module>
    import caffe.io
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/io.py", line 2, in <module>
    import skimage.io
ImportError: No module named skimage.io
  • 错误2: ImportError: No module named google.protobuf.internal. 详细如下:
>>> import caffe
Traceback (most recent call last):
  File "", line 1, in <module>
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/pycaffe.py", line 15, in <module>
    import caffe.io
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/io.py", line 8, in <module>
    from caffe.proto import caffe_pb2
  File "/home/liguangyao/Programming/caffe-ssd/python/caffe/proto/caffe_pb2.py", line 6, in <module>
    from google.protobuf.internal import enum_type_wrapper
ImportError: No module named google.protobuf.internal

解决方法见:Caffe-SSD导入错误:ImportError: No module named skimage.io

你可能感兴趣的:(Caffe)