automatic commit
[folded-ctf.git] / run.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by Francois Fleuret                                           #
17 # (C) Idiap Research Institute                                          #
18 #                                                                       #
19 # Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
20 #########################################################################
21
22 MAIN_URL="http://www.idiap.ch/folded-ctf"
23
24 #########################################################################
25 # Compiling
26
27 make -j -k
28
29 if [[ $? != 0 ]]; then
30     echo "Compilation failed." >&2
31     exit 1
32 fi
33
34 echo
35
36 #########################################################################
37 # Generating the pool file
38
39 DATA_PATH=./rmk-data
40 POOL_NAME=${DATA_PATH}/rmk.pool
41
42 if [[ -d ${DATA_PATH} ]]; then
43
44     if [[ -f ${POOL_NAME} ]]; then
45
46         echo "The pool file exists."
47
48     else
49
50         echo "Can not find the pool file, checking the data integrity."
51
52         md5sum -c ${DATA_PATH}/list.md5
53
54         if [[ $? != 0 ]]; then
55             echo "The data set is corrupted. You can download it" >&2
56             echo "from ${MAIN_URL}" >&2
57             exit 1
58         fi
59
60         echo "Generating the pool file."
61
62         ./list_to_pool ${DATA_PATH}/full.lst ${DATA_PATH} ${POOL_NAME}.wrk
63
64         if [[ $? == 0 ]]; then
65             mv ${POOL_NAME}.wrk ${POOL_NAME}
66         else
67             \rm ${POOL_NAME}.wrk 2> /dev/null
68             echo "Pool generation failed." >&2
69             exit 1
70         fi
71
72     fi
73
74 else
75
76     echo "Can not find the RateMyKitten images in ${DATA_PATH}. You can download" >&2
77     echo "them from ${MAIN_URL}" >&2
78     exit 1
79
80 fi
81
82 RESULT_DIR=./results
83
84 case $1 in
85
86     #####################################################################
87     ## Generate illustrating pictures
88
89     pics)
90
91         SEED=0
92
93         EXPERIMENT_RESULT_DIR="${RESULT_DIR}/hb-${SEED}"
94
95         if [[ -d "${EXPERIMENT_RESULT_DIR}" ]]; then
96
97             # Value of -1 corresponds to saving the images with the
98             # ground-truth or the pi-referentials alone, while other
99             # values show registered pi-feature windows.
100
101             for npf in -1 0 2500; do
102
103                 ./folding --random-seed=${SEED} \
104                     --pool-name=${POOL_NAME} \
105                     --result-path=/tmp/ \
106                     --detector-name=${EXPERIMENT_RESULT_DIR}/default.det \
107                     --nb-images=63 \
108                     --material-feature-nb=${npf} \
109                     open-pool \
110                     read-detector \
111                     write-pool-images
112
113             done
114
115         else
116             echo "You have to run at least the first round completely to be able" >&2
117             echo "to generate the pictures." >&2
118             exit 1
119         fi
120
121         ;;
122
123     #####################################################################
124     ## Run the full computation
125
126     valgrind|"")
127
128         if [[ ! -d ${RESULT_DIR} ]]; then
129             mkdir ${RESULT_DIR}
130         fi
131
132         for SEED in {0..9}; do
133
134             for MODE in hb h+b; do
135
136                 EXPERIMENT_RESULT_DIR="${RESULT_DIR}/${MODE}-${SEED}"
137
138                 mkdir ${EXPERIMENT_RESULT_DIR} 2> /dev/null
139
140                 if [[ $? == 0 ]]; then
141
142                     if [[ $MODE == "h+b" ]]; then
143                         OPTS="--force-head-belly-independence=yes"
144                     else
145                         OPTS=""
146                     fi
147
148                     if [[ $1 == "valgrind" ]]; then
149                         # The valgrind operation runs a simpler computation in valgrind
150                         OPTS="${OPTS} --nb-classifiers-per-level=1 --nb-weak-learners-per-classifier=10"
151                         OPTS="${OPTS} --proportion-for-train=0.1 --proportion-for-validation=0.025 --proportion-for-test=0.01"
152                         OPTS="${OPTS} --wanted-true-positive-rate=0.1"
153                         DEBUGGER="valgrind --db-attach=yes --leak-check=full --show-reachable=yes"
154                     fi
155
156                     ${DEBUGGER} ./folding \
157                         --random-seed=${SEED} \
158                         --pool-name=${POOL_NAME} \
159                         --result-path=${EXPERIMENT_RESULT_DIR} \
160                         --detector-name=${EXPERIMENT_RESULT_DIR}/default.det \
161                         ${OPTS} \
162                         open-pool \
163                         train-detector \
164                         compute-thresholds \
165                         write-detector \
166                         sequence-test-detector | tee -a ${EXPERIMENT_RESULT_DIR}/stdout
167
168                 else
169
170                     echo "${EXPERIMENT_RESULT_DIR} exists, cancelling that run."
171
172                 fi
173
174             done
175
176         done
177
178 esac