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