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, (C) IDIAP                                #
17 # Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
18 #########################################################################
19
20 MAIN_URL="http://www.idiap.ch/folded-ctf"
21
22 ######################################################################
23 # Compiling
24
25 make -j -k
26
27 if [[ $? != 0 ]]; then
28     echo "Compilation failed." >&2
29     exit 1
30 fi
31
32 echo
33
34 ######################################################################
35 # Generating the pool file
36
37 DATA_PATH=./rmk-data
38 POOL_NAME=${DATA_PATH}/rmk.pool
39
40 if [[ -d ${DATA_PATH} ]]; then
41
42     if [[ -f ${POOL_NAME} ]]; then
43
44         echo "The pool file exists."
45
46     else
47
48         echo "Can not find the pool file, checking the data integrity."
49
50         md5sum -c ${DATA_PATH}/list.md5
51
52         if [[ $? != 0 ]]; then
53             echo "The data set is corrupted. You can download it" >&2
54             echo "from ${MAIN_URL}" >&2
55             exit 1
56         fi
57
58         echo "Generating the pool file."
59
60         ./list_to_pool ${DATA_PATH}/full.lst ${DATA_PATH} ${POOL_NAME}.wrk
61
62         if [[ $? == 0 ]]; then
63             mv ${POOL_NAME}.wrk ${POOL_NAME}
64         else
65             \rm ${POOL_NAME}.wrk 2> /dev/null
66             echo "Pool generation failed." >&2
67             exit 1
68         fi
69
70     fi
71
72 else
73
74     echo "Can not find the RateMyKitten images in ${DATA_PATH}. You can download" >&2
75     echo "them from ${MAIN_URL}" >&2
76     exit 1
77
78 fi
79
80 ######################################################################
81 # Running the computation per se
82
83 RESULT_DIR=./results
84
85 case $1 in
86
87     pics)
88
89         SEED=0
90
91         EXPERIMENT_RESULT_DIR="${RESULT_DIR}/hb-${SEED}"
92
93         if [[ -d "${EXPERIMENT_RESULT_DIR}" ]]; then
94
95             for n in -1 0 2501 2504; do
96
97                 ./folding --random-seed=${SEED} \
98                     --pool-name=${POOL_NAME} \
99                     --result-path=${EXPERIMENT_RESULT_DIR} \
100                     --detector-name=${EXPERIMENT_RESULT_DIR}/default.det \
101                     --nb-images=1 \
102                     --material-feature-nb=${n} \
103                     open-pool \
104                     read-detector \
105                     write-pool-images
106
107             done
108
109         else
110             echo "You have to run at least the first round completely to be able" >&2
111             echo "to generate the pictures." >&2
112             exit 1
113         fi
114
115         ;;
116
117     valgrind|"")
118
119         if [[ ! -d ${RESULT_DIR} ]]; then
120             mkdir ${RESULT_DIR}
121         fi
122
123         for SEED in {0..9}; do
124
125             for MODE in hb h+b; do
126
127                 EXPERIMENT_RESULT_DIR="${RESULT_DIR}/${MODE}-${SEED}"
128
129                 mkdir ${EXPERIMENT_RESULT_DIR} 2> /dev/null
130
131                 if [[ $? == 0 ]]; then
132
133                     if [[ $MODE == "h+b" ]]; then
134                         OPTS="${OPTS} --force-head-belly-independence=yes"
135                     fi
136
137                     if [[ $1 == "valgrind" ]]; then
138                         OPTS="${OPTS} --nb-classifiers-per-level=1 --nb-weak-learners-per-classifier=10"
139                         OPTS="${OPTS} --proportion-for-train=0.1 --proportion-for-validation=0.025 --proportion-for-test=0.01"
140                         OPTS="${OPTS} --wanted-true-positive-rate=0.1"
141                         DEBUGGER="valgrind --db-attach=yes --leak-check=full --show-reachable=yes"
142                     fi
143
144                     ${DEBUGGER} ./folding \
145                         --random-seed=${SEED} \
146                         --pool-name=${POOL_NAME} \
147                         --result-path=${EXPERIMENT_RESULT_DIR} \
148                         --detector-name=${EXPERIMENT_RESULT_DIR}/default.det \
149                         ${OPTS} \
150                         open-pool \
151                         train-detector \
152                         compute-thresholds \
153                         write-detector \
154                         sequence-test-detector | tee -a ${EXPERIMENT_RESULT_DIR}/stdout
155
156                 else
157
158                     echo "${EXPERIMENT_RESULT_DIR} exists, aborting experiment."
159
160                 fi
161
162             done
163
164         done
165
166 esac