Added README.md
[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
31 [[ "${DYNCNN_DATA_DIR}" ]] || DYNCNN_DATA_DIR="./data/10p-mg"
32 [[ "${DYNCNN_RUNDIR}" ]] || DYNCNN_RUNDIR="./results"
33
34 NB_EPOCHS=2000
35
36 if [[ ! -d "${DYNCNN_DATA_DIR}" ]]; then
37     # Creating the data-base
38     make -j -k
39     mkdir -p "${DYNCNN_DATA_DIR}"
40     # 17 frames every 16 is two frames: t+0 and t+16
41     ./flatland 40000 \
42                --nb_shapes 10 \
43                --random_grasp --every_nth 16 --nb_frames 17 \
44                --dir "${DYNCNN_DATA_DIR}"
45 fi
46
47 # Train the model (2000 epochs takes 30h on a GTX 1080 with cuda 8.0,
48 # cudnn 5.1, and recent torch)
49
50 if [[ -f "$(printf "%s/model_%04d.t7" "${DYNCNN_RUNDIR}" ${NB_EPOCHS})" ]]; then
51     echo "Found the model already trained through ${NB_EPOCHS} epochs."
52 else
53     ./dyncnn.lua -nbEpochs ${NB_EPOCHS} -rundir "${DYNCNN_RUNDIR}"
54 fi
55
56 # Create the images of internal activations using the current.t7 in
57 # the rundir
58
59     cat <<EOF
60 ***************************************************************************
61                Creates the images of internal activations
62 ***************************************************************************
63 EOF
64
65 ./dyncnn.lua -rundir "${DYNCNN_RUNDIR}" -noLog -exampleInternals 3,7
66
67 ######################################################################
68 # Plot the loss curves if gnuplot is here
69
70 if [[ $(which gnuplot) ]]; then
71     cat <<EOF
72 ***************************************************************************
73                          Plots the loss curves
74 ***************************************************************************
75 EOF
76
77     TERMINAL="pdfcairo color transparent enhanced font \"Times,14\""
78     EXTENSION="pdf"
79
80     gnuplot <<EOF
81 set terminal ${TERMINAL}
82 set output "${DYNCNN_RUNDIR}/losses.${EXTENSION}"
83 set logscale x
84 set logscale y
85 set size ratio 0.75
86 set xlabel "Number of epochs"
87 set ylabel "Loss"
88 plot '< grep "acc_train_loss" "${DYNCNN_RUNDIR}"/log' using 4:8 with l lw 3 lc rgb '#c0c0ff' title 'Validation loss',\
89      '< grep "acc_train_loss" "${DYNCNN_RUNDIR}"/log' using 4:6 with l lw 1 lc rgb '#000000' title 'Train loss'
90
91 EOF
92
93 fi