Compiling and running Deep Pyramid Deformable Part Model (DP-DPM) in Ubuntu 16.04.3 LTS

The starting point is the Girshick's DP-DPM Github repository at
The repo has not been updated since 2015 and many of the libraries it uses may have been changed. Below some hacks to make it compile and run the main demo.

Caffe
DP-DPM recursively fetches the correct version of Caffe through git, but for installation you need to use old version of the installation instructions:
Many of the above are available via Ubuntu main repositories and seem to work:

sudo apt-get install protobuf-compiler 
sudo apt-get install libgflags-dev 
sudo apt-get install libgoogle-glog-dev 
sudo apt-get install libleveldb-dev 
sudo apt-get install liblmdb-dev 
sudo apt-get install libsnappy-dev
sudo apt-get install libhdf5-serial-dev 
sudo apt-get install libhdf5-dev 
sudo apt-get install libatlas-dev
sudo apt-get install libatlas-base-dev 

Then you need a local installation of OpenCV (see https://www.opencv.org/):
 
cd <OPENCV_DIR>
mkdir build; cd build
cmake ..
ccmake .. // Set INSTALL_PREFIX to <OPENCV_DIR>/build/install
make all

First compile everything in CPU_ONLY - for that a little change was needed in one of the old caffe source files:

IN dp-dpm/caffe/include/caffe/util/device_alternate.hpp EDIT:
  
#ifndef CPU_ONLY 
#define CPU_ONLY // ugly wrap by Joni
#endif 

Edit Makefile.config

cp Makefile.config.example Makefile.config
 
***  EDIT Makefile.config: ***
  
# Whatever else you find you need goes here.
 
# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1 
 
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /home/kamarain/Work/ext/opencv-3.3.1/install/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /home/kamarain/Work/ext/opencv-3.3.1/install/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/lib  
USE_PKG_CONFIG := 1
 

And finally compiling caffe with Matlab support:

cd <DPDPM_DIR>/caffe
mkdir build; cd build
cmake ..
ccmake .. // EDIT OPENCV PATH TO <OPENCV_DIR>/build/install/
          // Set building MATLAB on
          // Set install prefix to this directory (although crappy DP-DPM takes everything from the main dir) 
make
make install

DP-DPM

Compiling MEX files needs certain libraries to be found and since my Matlab 2016b annoyingly comes with other versions of stdc++ and protobuf libs I need to pre-load them:

export LD_LIBRARY_PATH=<OPENCV_DIR>/install/lib/:<DPDPM_DIR>/caffe/build/install/lib/ 
export LD_PRELOAD=$LD_PRELOAD:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libprotobuf.so.9

And since DP-DPM MEX files were using some pre-historic MEX compiler we need to edit sources:

compile

And another annoying fix for CPU_ONLY mode fix:

IN <DPDPM_DIR>model/model_cnn_init.m ADD LINE
 
use_gpu = false; % made by Joni 

You may now try to compile, but you might get weird incompatibility errors in which case you need to edit the source code:

IN gdetect/computer_overlap.cc

 const size_t dims[] = {feat_dim_y, feat_dim_x}; //  const int dims[] = {feat_dim_y, feat_dim_x};

IN gdetect/fast_bounded_dt.cc

const size_t *dims = mxGetDimensions(prhs[IN_VALS]); //const int *dims = mxGetDimensions(prhs[IN_VALS]);

IN gdetect/dt.cc

 const size_t *dims = mxGetDimensions(prhs[0]); //const int *dims = mxGetDimensions(prhs[0]);

IN features/features.cc

 const size_t *dims = mxGetDimensions(mximage); //const int *dims = mxGetDimensions(mximage);
 size_t out[3]; //int out[3];

IN features/resize.cc

  const size_t *sdims = mxGetDimensions(mxsrc); //const int *sdims = mxGetDimensions(mxsrc);




Now you are ready to compile DP-DPM Mex files and run the bloody code:

nice matlab -nodesktop -nojvm 
>> compile
>> pascal('bicycle',3)

For some reason the default optimization method, lbfgs, in external/minConf/minConf/minConf_TMP.m did not work (out of memory after some number of iterations with the hard negative exmaples) and I changed it to:

'interp',1,'method','bfgs','corrections',100,'damped',0); 

After that I was able to compile DP-DPM and run the example (remember to download VOC2007 devkit that also contains test images and their ground truth):

>> pascal('bicycle',3)

Kommentit

Tämän blogin suosituimmat tekstit

Using citations in BSc and MSc theses

Installing and running Dlib on Ubuntu 16.04