Many fixes, now generates a single image per frame.
[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
32 [[ "${DYNCNN_RUNDIR}" ]] || DYNCNN_RUNDIR="./results"
33
34 ######################################################################
35 # Create the data-set if the directory does not exist
36
37 if [[ ! -d "${DYNCNN_DATA_DIR}" ]]; then
38     cat <<EOF
39 ***************************************************************************
40                           Generate the data-set
41 ***************************************************************************
42 EOF
43
44     make -j -k
45     mkdir -p "${DYNCNN_DATA_DIR}"
46     # 17 frames every 16 is two frames: t+0, t+16
47     ./flatland 40000 \
48                --nb_shapes 10 \
49                --multi_grasp --every_nth 16 --nb_frames 17 \
50                --dir "${DYNCNN_DATA_DIR}"
51 fi
52
53 ######################################################################
54 # Train the model (takes 15h on a GTX 1080 with cuda 8.0, cudnn 5.1,
55 # and recent torch)
56
57 if [[ ! -f "${DYNCNN_RUNDIR}"/model_1000.t7 ]]; then
58     cat <<EOF
59 ***************************************************************************
60                   Train the model (should take a while)
61 ***************************************************************************
62 EOF
63     ./dyncnn.lua -rundir "${DYNCNN_RUNDIR}"
64 fi
65
66 ######################################################################
67 # Create the images of internal activations using the current.t7 in
68 # the rundir
69
70 cat <<EOF
71 ***************************************************************************
72                    Save the internal activation images
73 ***************************************************************************
74 EOF
75
76 for n in 2 12; do
77     ./dyncnn.lua -rundir "${DYNCNN_RUNDIR}" -noLog -exampleInternals "${n}"
78 done
79
80 ######################################################################
81 # Plot the loss curves if gnuplot is here
82
83 if [[ $(which gnuplot) ]]; then
84     cat <<EOF
85 ***************************************************************************
86                            Plot the loss curves
87 ***************************************************************************
88 EOF
89
90     TERMINAL="pdfcairo color transparent enhanced font \"Times,14\""
91     EXTENSION="pdf"
92
93     gnuplot <<EOF
94 set terminal ${TERMINAL}
95 set output "${DYNCNN_RUNDIR}/losses.${EXTENSION}"
96 set logscale x
97 set logscale y
98 set size ratio 0.75
99 set xlabel "Number of epochs"
100 set ylabel "Loss"
101 plot '< grep "LOSS " "${DYNCNN_RUNDIR}"/log' using 4:6 with l lw 3 lc rgb '#c0c0ff' title 'Validation loss',\
102      '< grep "LOSS " "${DYNCNN_RUNDIR}"/log' using 4:5 with l lw 1 lc rgb '#000000' title 'Train loss'
103
104 EOF
105
106 fi