Install Caffe - AD-EYE/AD-EYE_Core GitHub Wiki

Install SSDCAFE

NOTE: Everything including caffe itself is packaged in Ubuntu 17.04 and higher versions, that can be install with sudo apt install caffe-cuda libcaffe-cuda-dev

However, we use a forked version of ssd caffe, that supports VGG DNN; so we can not use the standard packages, don't install them and proceed to the following steps to install ssd caffe manually:

  1. Complete the pre-requisites. Make sure the version of OpenCV that you've installed is at least 2.4.10. Basically, it's just about installing the following packages:
sudo apt install liblapack-dev liblapack3 libopenblas-base libopenblas-dev libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt install --no-install-recommends libboost-all-dev

NOTE: From this step, you can download a script to automatically install ssdCaffe. This script is located in the dev branch, in the Helper Script folder.

WARNING: For it to work, you have to have installed cuDNN (see previously) and openCV must be version 2. If you have version 3, this is not a big issue as you can modify a file to take this into account (see the script for further information). If the installation doesnt work, it may be because of the line make distribute which can be responsible for some bugs (especially when opencv version 2.x is installed). You should comment out this particular line if the installation doesnt work.

  1. Clone the SSD Caffe fork in your home directory (CMake files will be looking for it there).
git clone -b ssd https://github.com/weiliu89/caffe.git ssdcaffe
cd ssdcaffe
git checkout 4817bf8b4200b35ada8ed0dc378dceaf38c539e4
  1. Rename Makefile.config.example to Makefile.config

  2. Delete out -gencode arch=compute_20,code=sm_20 \ and -gencode arch=compute_20,code=sm_21 \ in Makefile.config and add -gencode arch=compute_75,code=sm_75 \ if using a RTX 2080 (the codes matching different GPU achitectures can be found here). Append /usr/include/hdf5/serial/ to INCLUDE_DIRS at line 92 in Makefile.config.

--- INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
+++ INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

Modify hdf5_hl and hdf5 to hdf5_serial_hl and hdf5_serial at line 181 in Makefile

--- LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5
+++ LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial
  1. Follow the authors' instructions to complete the pre-requisites for compilation: http://caffe.berkeleyvision.org/installation.html#compilation

  2. Compile Caffe:

make -j8 && make distribute
  1. Add the following line to the ~/.bashrc file:
export LD_LIBRARY_PATH=/home/adeye/ssdcaffe/build/lib:$LD_LIBRARY_PATH

Source: http://caffe.berkeleyvision.org/installation.html#compilation

https://web.archive.org/web/20190703125543/http://caffe.berkeleyvision.org/installation.html

Notes

Remember to modify the deploy.prototxt to use the FULL PATH to the VOC label prototxt file.

Open the file $SSDCAFFEPATH/models/VGGNet/VOC0712/SSD_512x512/deploy.prototxt

Change line 1803 to point to the full path of the labelmap_voc.prototxt file.

Source: https://github.com/autowarefoundation/autoware/blob/master/ros/src/computing/perception/detection/vision_detector/packages/vision_ssd_detect/README.md

Make: protoc issue:

Problem:

make: protoc: Command not found

Solution: sudo apt-get install protobuf-compiler

Fix hdf5 naming problem

Your machine may report the following error when compiling Caffe even though libhdf5-serial-dev package has been already installed in it.

./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory

This is because of change of default path and name of hdf5 head files and libraries in Ubuntu 15.10. To solve this problem, we can simply modify Makefile files.

Append /usr/include/hdf5/serial/ to INCLUDE_DIRS at line 92 in Makefile.config.

--- INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
+++ INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

Modify hdf5_hl and hdf5 to hdf5_serial_hl and hdf5_serial at line 181 in Makefile

--- LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5
+++ LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial

Source: https://gist.github.com/wangruohui/679b05fcd1466bb0937f#fix-hdf5-naming-problem

Fix "undefined reference to boost:: ..."

Just add boost_regex to the LIBRARY line (line 181) in Makefile.

--- LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial
+++ LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial

Source: https://github.com/rbgirshick/fast-rcnn/issues/52

Fix "undefined reference to cv2:: ..."

Make sure to have a compatible version of cv2 installed. In my case, the problem has been solved by installing the 2.4.13 and note that the 2.4.9 doesn't seem to work.

Fix "undefined reference to cv::VideoCapture::... / cv::VideoWriter::..."

This occurs when some libopencv are not included as libraries.

Solution : Edit the Makefile as follows. Go to the line 204, after some conditional statements, just before
"PYTHON_LIBRARIES ?= boost_python python2.7"
And add the following line : LIBRARIES += opencv_videoio opencv_imgcodecs

Note : By adding only opencv_videoio without opencv_imgcodecs, you will have a
undefined reference to symbol '_ZN2cv6imreadERKNS_6StringEi' error.
Which can be fixed by adding opencv_imgcodecs to the LIBRARIES

Fix "numpy/arrayobject.h: No such file or directory"

Add to Makefile.config the path where numpy is installed line 64. In my case, I had to do the following change:

--- PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include \
+++ PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include \
                /usr/local/lib/python2.7/dist-packages/numpy/core/include

Fix "[vision_ssd_detect-18] process has died..."

I do not know if these two fixes effectively resolve the bug but I did that and it worked afterwards.

First, add -gencode arch=compute_XX,code=sm_XX to the CUDA_ARCH line 35 by replacing XX by the correct number (e.g. 75 for RTX GPU).

In some cases, the library libcaffe.so.1.0.0-rc3 is not found at execution time. To solve it:

In the bashrc file, in addition to the CUDA path in the LD_LIBRARY_PATH variable, add the path to the file libcaffe.so.1.0.0-rc3 and separate the two paths with a colon. For me, it was:

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/home/adeye/ssdcaffe/build/lib:$LD_LIBRARY_PATH

Fix Gflags/glog issues

Error : In files included from src/caffe/net.cpp ./include/caffe/common.hpp:_numberofline_:_numberofline_ fatal error: gflags/gflags.h **OR** glog/logging.h: No such file or directory compilation terminated recipe for target build_release/src/caffe/net.o failed

Fix : sudo apt-get install libgflags-dev and sudo apt install libgoogle-glob-dev

Fix opencv_imgcodecs opencv_videoio issues:

Error : /usr/bin/ld: cannot find -lopencv_imgcodecs /usr/bin/ld: cannot find -lopencv_videoio collect2: error: ld returned 1 exit status Makefile:_numberofline_: recipe for target .build_release/lib/libcaffe.so.1.0.0-rc5 failed make: *** [.build_release/lib/libcaffe.so.1.0.0-rc5] Error 1

Fix : Open the Makefile with your favorite text editor and locate the following line: LIBRARIES += glog gflags .... and add opencv_imgcodecs to it

Issue about the new models

https://github.com/autowarefoundation/autoware/issues/1020

Autoware details

Run the node

Click to expand Once compiled, run from the terminal, or launch from RunTimeManager:
roslaunch vision_ssd_detect vision_ssd_detect network_definition_file:=/PATH/TO/deploy.prototxt pretrained_model_file:=/PATH/TO/model.caffemodel

Remember to modify the launch file located inside AUTOWARE_BASEDIR/ros/src/computing/perception/detection/vision_detector/packages/vision_ssd_detect/launch/vision_ssd_detect.launch and point the network and pre-trained models to your paths.

Launch file params

Click to expand
Parameter Type Description Default
use_gpu Bool Whether to use GPU acceleration. true
gpu_device_id Integer ID of the GPU to be used. 0
score_threshold Double Value between 0 and 1. Defines the minimum score value to filter detections. 0.5
network_definition_file String Path to the prototxt file $SSDCAFFEPATH/models/VGGNet/VOC0712/SSD_512x512/deploy.prototxt
pretrained_model_file String Path to the pcaffemodel file $SSDCAFFEPATH/models/VGGNet/VOC0712/SSD_512x512/VGG_VOC0712_SSD_512x512_iter_120000.caffemodel
camera_id String Camera ID to subscribe, i.e. camera0 /
image_src String Name of the image topic that should be subscribe to /image_raw

Next step: Install Autoware and AD EYE
Back to the overview: Installation
⚠️ **GitHub.com Fallback** ⚠️