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