Initial commit
[dyncnn.git] / run.sh
1 #!/bin/bash
2
3 # dyncnn is a deep-learning algorithm for the prediction of
4 # interacting object dynamics
5 #
6 # Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
7 # Written by Francois Fleuret <francois.fleuret@idiap.ch>
8 #
9 # This file is part of dyncnn.
10 #
11 # dyncnn is free software: you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License version 3 as
13 # published by the Free Software Foundation.
14 #
15 # dyncnn is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with dyncnn.  If not, see <http://www.gnu.org/licenses/>.
22
23 # This script creates the synthetic data-set for shape collision
24
25 set -e
26 set -o pipefail
27
28 [[ "${TORCH_NB_THREADS}" ]] || echo "You can set \$TORCH_NB_THREADS to the proper value (default 1)."
29 [[ "${TORCH_USE_GPU}" ]] || echo "You can set \$TORCH_USE_GPU to 'yes' or 'no' (default 'no')."
30 [[ "${DYNCNN_DATA_DIR}" ]] || DYNCNN_DATA_DIR="./data/10p-mg"
31 [[ "${DYNCNN_RESULT_DIR}" ]] || DYNCNN_RESULT_DIR="./results"
32
33 if [[ -d "${DYNCNN_DATA_DIR}" ]]; then
34     echo "Found ${DYNCNN_DATA_DIR}, checking the number of images in there."
35     if [[ $(find "${DYNCNN_DATA_DIR}" -name "dyn_*.png" | wc -l) == 150000 ]]; then
36         echo "Looks good !"
37     else
38         echo "I do not find the proper number of images. Please remove the dir and re-run this scripts, or fix manually."
39         exit 1
40     fi
41 else
42     # Creating the data-base
43     make -j -k
44     mkdir -p "${DYNCNN_DATA_DIR}"
45     ./flatland 50000 \
46                --every_nth 4 --nb_frames 5 \
47                --multi_grasp --nb_shapes 10 \
48                --dir "${DYNCNN_DATA_DIR}"
49 fi
50
51 # Train the model (takes days)
52
53 if [[ ! -f "${DYNCNN_RESULT_DIR}"/epoch_01000_model ]]; then
54     ./dyncnn.lua --heavy --dataDir="${DYNCNN_DATA_DIR}" \
55                  --resultFreq=100 \
56                  --resultDir "${DYNCNN_RESULT_DIR}" \
57                  --nbEpochs 1000
58 fi
59
60 # Create the images of internal activations
61
62 for n in 2 12; do
63     ./dyncnn.lua --heavy --dataDir=./data/10p-mg/ \
64                  --learningStateFile="${DYNCNN_RESULT_DIR}"/epoch_01000_model \
65                  --resultDir="${DYNCNN_RESULT_DIR}" \
66                  --noLog \
67                  --exampleInternals=${n}
68 done