Added README.md
[dyncnn.git] / run.sh
diff --git a/run.sh b/run.sh
index d905ef9..3f8529d 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -27,42 +27,67 @@ set -o pipefail
 
 [[ "${TORCH_NB_THREADS}" ]] || echo "You can set \$TORCH_NB_THREADS to the proper value (default 1)."
 [[ "${TORCH_USE_GPU}" ]] || echo "You can set \$TORCH_USE_GPU to 'yes' or 'no' (default 'no')."
+
 [[ "${DYNCNN_DATA_DIR}" ]] || DYNCNN_DATA_DIR="./data/10p-mg"
-[[ "${DYNCNN_RESULT_DIR}" ]] || DYNCNN_RESULT_DIR="./results"
-
-if [[ -d "${DYNCNN_DATA_DIR}" ]]; then
-    echo "Found ${DYNCNN_DATA_DIR}, checking the number of images in there."
-    if [[ $(find "${DYNCNN_DATA_DIR}" -name "dyn_*.png" | wc -l) == 150000 ]]; then
-        echo "Looks good !"
-    else
-        echo "I do not find the proper number of images. Please remove the dir and re-run this scripts, or fix manually."
-        exit 1
-    fi
-else
+[[ "${DYNCNN_RUNDIR}" ]] || DYNCNN_RUNDIR="./results"
+
+NB_EPOCHS=2000
+
+if [[ ! -d "${DYNCNN_DATA_DIR}" ]]; then
     # Creating the data-base
     make -j -k
     mkdir -p "${DYNCNN_DATA_DIR}"
-    ./flatland 50000 \
-               --every_nth 4 --nb_frames 5 \
-               --multi_grasp --nb_shapes 10 \
+    # 17 frames every 16 is two frames: t+0 and t+16
+    ./flatland 40000 \
+               --nb_shapes 10 \
+               --random_grasp --every_nth 16 --nb_frames 17 \
                --dir "${DYNCNN_DATA_DIR}"
 fi
 
-# Train the model (takes days)
+# Train the model (2000 epochs takes 30h on a GTX 1080 with cuda 8.0,
+# cudnn 5.1, and recent torch)
 
-if [[ ! -f "${DYNCNN_RESULT_DIR}"/epoch_01000_model ]]; then
-    ./dyncnn.lua --heavy --dataDir="${DYNCNN_DATA_DIR}" \
-                 --resultFreq=100 \
-                 --resultDir "${DYNCNN_RESULT_DIR}" \
-                 --nbEpochs 1000
+if [[ -f "$(printf "%s/model_%04d.t7" "${DYNCNN_RUNDIR}" ${NB_EPOCHS})" ]]; then
+    echo "Found the model already trained through ${NB_EPOCHS} epochs."
+else
+    ./dyncnn.lua -nbEpochs ${NB_EPOCHS} -rundir "${DYNCNN_RUNDIR}"
 fi
 
-# Create the images of internal activations
+# Create the images of internal activations using the current.t7 in
+# the rundir
+
+    cat <<EOF
+***************************************************************************
+               Creates the images of internal activations
+***************************************************************************
+EOF
+
+./dyncnn.lua -rundir "${DYNCNN_RUNDIR}" -noLog -exampleInternals 3,7
 
-for n in 2 12; do
-    ./dyncnn.lua --heavy --dataDir=./data/10p-mg/ \
-                 --learningStateFile="${DYNCNN_RESULT_DIR}"/epoch_01000_model \
-                 --resultDir="${DYNCNN_RESULT_DIR}" \
-                 --noLog \
-                 --exampleInternals=${n}
-done
+######################################################################
+# Plot the loss curves if gnuplot is here
+
+if [[ $(which gnuplot) ]]; then
+    cat <<EOF
+***************************************************************************
+                         Plots the loss curves
+***************************************************************************
+EOF
+
+    TERMINAL="pdfcairo color transparent enhanced font \"Times,14\""
+    EXTENSION="pdf"
+
+    gnuplot <<EOF
+set terminal ${TERMINAL}
+set output "${DYNCNN_RUNDIR}/losses.${EXTENSION}"
+set logscale x
+set logscale y
+set size ratio 0.75
+set xlabel "Number of epochs"
+set ylabel "Loss"
+plot '< grep "acc_train_loss" "${DYNCNN_RUNDIR}"/log' using 4:8 with l lw 3 lc rgb '#c0c0ff' title 'Validation loss',\
+     '< grep "acc_train_loss" "${DYNCNN_RUNDIR}"/log' using 4:6 with l lw 1 lc rgb '#000000' title 'Train loss'
+
+EOF
+
+fi