===== Caffe matlab bindings on Ubuntu (needed for fastRCNN/DeepCut) =====
This "tutorial" was written on 2016-11-30.
I am using:
* Ubuntu 16.04.1 LTS
* Matlab 2016a
==== TLDR ====
If you want to run caffe matlab bindings, copy the matlab folder and symlink opencv libraries. My copy is here:
/scratch/aquarius/vsydorov/matlab_ubuntu/matlab-2016a/
==== Longer version (not necessary better) ====
Matlab bundles a lot of libraries with it. It also bundles opencv which is somehow different from the system version. This causes a lot of weird problems, like the infamous ''"undefined symbol _ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE"'' error. Here are some discussions about this error:
* [[https://groups.google.com/forum/#!topic/caffe-users/x8Y26vf-or8]]
* [[https://github.com/BVLC/caffe/issues/3934]]
Don't make the same mistake I (and also the guy in the first link) did and assume this will go away if you just put the libraries in the LD_PRELOAD. It will not. The only solution is to copy matlab folder and symlink the aforementioned opencv libraries in the bin/glnxa64. I also symlinked libtiff.
libtiff.so.5 -> /usr/lib/x86_64-linux-gnu/libtiff.so.5
libopencv_core.so.2.4.9 -> /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9
libopencv_highgui.so.2.4.9 -> /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9
libopencv_imgproc.so.2.4.9 -> /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4.9
Copying matlab folder can take quite a while, so feel free to use my copy
/scratch/aquarius/vsydorov/matlab_ubuntu/matlab-2016a/
I launch my copy like this:
LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" /scratch/aquarius/vsydorov/matlab-2016a/matlab-2016a/bin/matlab -nosplash
==== Bonus: Caffe compilation instructions ====
=== Prerequisites for caffe compilation ===
Follow official installation guides:
* [[http://caffe.berkeleyvision.org/install_apt.html]]
* [[https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide]]
If it does not work, copypaste the following into your terminal:
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y libopencv-dev
=== Compiling caffe for deepercut ===
[[https://github.com/eldar/deepcut]]
I compiled caffe for deepercut in the folder
/scratch/gpuhost9/vsydorov/libraries/caffe/caffe-deepercut
using the following ''Makefile.config'':
# I am compiled with cuda8.0 on ubuntu!
# If you are wondering - you are supposed to disable CUDNN, yes, otherwise it does not compile.
USE_CUDNN := 0
CUDA_DIR := /scratch/gpuhost9/vsydorov/libraries/cuda8.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_50,code=compute_50
BLAS := mkl
BLAS_INCLUDE := /scratch2/clear/mairal/intel/compilers_and_libraries/linux/mkl/include
BLAS_LIB := /scratch2/clear/mairal/intel/compilers_and_libraries/linux/mkl/lib
MATLAB_DIR := /scratch/aquarius/vsydorov/matlab_ubuntu/matlab-2016a
PYTHON_INCLUDE := /scratch/gpuhost9/vsydorov/VENVS/ubunion/include/python2.7
PYTHON_LIB := /usr/lib /scratch/gpuhost9/vsydorov/VENVS/ubunion/lib
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /scratch/gpuhost9/vsydorov/libraries/cudnn-cuda8.0-ver5.1/cuda/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial /scratch2/clear/mairal/intel/compilers_and_libraries/linux/mkl/lib/intel64
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
DEBUG := 0
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
CUSTOM_CXX := g++ -std=c++11
Compilation had been performed by running:
make all -j8
make pycaffe
make matcaffe
Once compilation was done, I tested matlab bindings with the following elegant command:
cd matlab
LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" /scratch/aquarius/vsydorov/matlab_ubuntu/matlab-2016a/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'