-
Notifications
You must be signed in to change notification settings - Fork 90
/
caffe-lrp-cpu-u16.04.def
122 lines (95 loc) · 3.87 KB
/
caffe-lrp-cpu-u16.04.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Bootstrap: docker
From: ubuntu:16.04
# This definition file allows the user to build a lrp toolbox executable for caffe, based on an ubuntu 16.04
# docker image. E.g. when calling
# > singularity build --fakeroot --force caffe-lrp-cpu-u16.04.sif caffe-lrp-cpu-u16.04.def
# the resulting sif file can directly be called from command line, e.g. as
# > ./caffe-lrp-cpu-u16.04.sif -c caffe-lrp-config-file.txt -t input-file-list.txt
# on any linux-based OS.
%post
####
echo ">>> STEP 0: DISTRO PACKAGE INSTALLATION"
####
# install caffe-related dependencies. order of installation must be exactly this. else, it will break down.
apt-get update
apt-get install -y libleveldb-dev \
libprotobuf-dev \
libsnappy-dev \
libopencv-dev \
libhdf5-serial-dev \
protobuf-compiler \
build-essential \
libatlas-base-dev \
libgflags-dev \
libgoogle-glog-dev \
liblmdb-dev \
libmagick++-dev
apt-get update
apt-get install -y --no-install-recommends libboost-all-dev
apt-get update
apt-get install -y apt-utils \
wget \
sed \
git \
tree \
unzip
####
echo ">>> STEP 1: DOWNLOAD RELEVANT REPOSITORIES"
####
cd /opt
BRANCH=master
wget https://github.com/sebastian-lapuschkin/lrp_toolbox/archive/$BRANCH.zip
unzip $BRANCH.zip
mv lrp_toolbox-$BRANCH lrp_toolbox
rm $BRANCH.zip
####
echo ">>> STEP 2: APPLY DISTRO-SPECIFIC PATCH TO CAFFE"
####
# enter the caffe lrp folder, patch code for ubuntu 14.04->16.04 and install.
cd /opt/lrp_toolbox/caffe-master-lrp
# include "hdf5.h" -> #include "hdf5/serial/hdf5.h"
# include "hdf5_hl.h" -> #include "hdf5/serial/hdf5_hl.h"
# links hdf5 to where it can be found by caffe make and modifies makefile.
# adapts include paths and library names for the demonstrator
echo " running patch."
echo " step 2.1: manipulate header paths for hdf5 "
find ./*/ -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;
echo " step 2.2: create symlinks for hdf5 libraries. please enter your super user pw on prompt "
here=$PWD
cd /usr/lib/x86_64-linux-gnu
ln -s libhdf5_serial_hl.so libhdf5_hl.so
ln -s libhdf5_serial.so libhdf5.so
echo " going back to $here"
cd $here
echo " step 2.3: modify makefile to include hdf5 dirs"
sed -i -e "/INCLUDE_DIRS :=/a INCLUDE_DIRS += \/usr\/include\/hdf5\/serial\/" Makefile.config
echo " step 2.4: modify imagemagick include paths and library names for demonstrator"
cd demonstrator
sed -i -e "s/-lMagick++/-lMagick++-6.Q16/g" -e "s/-lMagickWand/-lMagickWand-6.Q16/g" -e "s/-lMagickCore/-lMagickCore-6.Q16/g" -e "s|-I /usr/include/ImageMagick/|-I /usr/include/ImageMagick-6 -I /usr/include/x86_64-linux-gnu/ImageMagick-6/|g" build.sh
cd ..
####
echo ">>> STEP 3: BUILD CAFFE FOR LRP"
####
# run makefile and test.
make clean
make all -j10
# make test
# make runtest # NOTE: tests from LayerFactoryTest/ will fail. Does not matter though for LRP; but will kill the container building
####
echo ">>> STEP 4: BUILD AND TEST DEMONSTRATOR APPLICATION"
####
cd /opt/lrp_toolbox/caffe-master-lrp/demonstrator
bash build.sh
chmod +x lrp_demo
# DOWNLOAD BVLC REFERENCE CAFFE MODEL AND START DEMONSTRATOR
bash download_model.sh
./lrp_demo ./config_sequential.txt ./testfilelist.txt ./
echo
echo "output images can be found in $(pwd)/lrp_output:"
tree $(pwd)/lrp_output
cd ..
echo "If you can read this, the container has been built successfully"
%files
caffe_lrp_commandline.py /opt/caffe_lrp_commandline.py
%runscript
python /opt/caffe_lrp_commandline.py "$@"