tipe/make.sh

134 lines
3.5 KiB
Bash
Raw Normal View History

2022-03-21 17:18:49 +01:00
#!/bin/bash
2022-05-14 14:48:54 +02:00
FLAGS="-std=c99 -lm -lpthread"
2022-04-08 19:34:54 +02:00
OUT="out"
2022-03-25 19:19:57 +01:00
2022-05-14 15:56:13 +02:00
set -eu
2022-04-22 15:22:51 +02:00
if [[ $1 == "build" ]]; then
mkdir -p "$OUT"
[[ $2 ]] || set "$1" "main"
if [[ $2 == "main" ]]; then
echo "Compilation de src/mnist/main.c"
gcc src/mnist/main.c -o "$OUT/main" $FLAGS
echo "Fait."
exit 0
elif [[ $2 == "preview" ]]; then
2022-03-27 15:03:13 +02:00
echo "Compilation de src/mnist/preview.c"
2022-04-08 19:34:54 +02:00
gcc src/mnist/preview.c -o "$OUT/preview_mnist" $FLAGS
2022-03-27 15:03:13 +02:00
echo "Fait."
2022-04-10 21:40:59 +02:00
exit 0
2022-04-22 15:22:51 +02:00
elif [[ $2 == "test" ]]; then
for i in $(ls test); do
echo "Compilation de test/$i"
gcc "test/$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}')" $FLAGS
echo "Fait."
done
exit 0
elif [[ $2 == "utils" ]]; then
gcc "src/mnist/utils.c" -o "$OUT/utils" $FLAGS
exit 0
else
$0 build main
$0 build preview
$0 build test
$0 build utils
exit 0
fi
fi
if [[ $1 == "preview" ]]; then
if [[ ! $2 ]]; then
$0 build preview
exit 0
2022-03-21 17:18:49 +01:00
elif [[ $2 == "train" ]]; then
2022-04-22 15:22:51 +02:00
[[ -f "$OUT/preview_mnist" ]] || $0 build preview
2022-04-08 19:34:54 +02:00
"$OUT/preview_mnist" data/mnist/train-images-idx3-ubyte data/mnist/train-labels-idx1-ubyte
2022-04-10 21:40:59 +02:00
exit 0
2022-03-21 17:18:49 +01:00
elif [[ $2 == "t10k" ]]; then
2022-04-22 15:22:51 +02:00
[[ -f "$OUT/preview_mnist" ]] || $0 build preview
2022-04-08 19:34:54 +02:00
"$OUT/preview_mnist" data/mnist/t10k-images-idx3-ubyte data/mnist/t10k-labels-idx1-ubyte
2022-04-10 21:40:59 +02:00
exit 0
2022-03-21 17:18:49 +01:00
fi
fi
2022-03-27 14:42:00 +02:00
if [[ $1 == "test" ]]; then
2022-04-22 15:22:51 +02:00
if [[ ! $2 ]]; then
$0 build test
2022-04-10 21:40:59 +02:00
exit 0
2022-03-27 14:42:00 +02:00
elif [[ $2 == "run" ]]; then
2022-04-22 15:22:51 +02:00
$0 build test
2022-03-27 14:54:20 +02:00
mkdir -p .test-cache
2022-04-08 19:34:54 +02:00
for i in $(ls "$OUT/test_"*); do
2022-03-27 14:42:00 +02:00
echo "--- $i ---"
$i
done
2022-04-10 21:40:59 +02:00
exit 0
2022-03-27 14:42:00 +02:00
fi
fi
2022-03-27 15:03:13 +02:00
2022-04-08 19:34:54 +02:00
if [[ $1 == "train" ]]; then
2022-04-22 15:22:51 +02:00
[[ -f "$OUT/main" ]] || $0 build main
2022-04-08 19:34:54 +02:00
[[ $2 ]] || set -- "$1" "train"
2022-04-19 17:21:37 +02:00
[[ $3 == "-r" || $3 == "--recover" ]] && RECOVER="-r .cache/reseau.bin"
2022-04-08 19:34:54 +02:00
mkdir -p .cache
"$OUT/main" train \
--images "data/mnist/$2-images-idx3-ubyte" \
--labels "data/mnist/$2-labels-idx1-ubyte" \
2022-04-19 17:21:37 +02:00
--out ".cache/reseau.bin" \
$RECOVER
2022-04-10 21:40:59 +02:00
exit 0
2022-04-08 19:34:54 +02:00
fi
2022-05-03 10:02:47 +02:00
if [[ $1 == "test_reseau" ]]; then
[[ -f "$OUT/main" ]] || $0 build main
[[ $2 ]] || set -- "$1" "train"
[[ -f ".cache/reseau.bin" ]] || $0 train train
"$OUT/main" test \
--images "data/mnist/$2-images-idx3-ubyte" \
--labels "data/mnist/$2-labels-idx1-ubyte" \
--modele ".cache/reseau.bin"
exit 0
fi
2022-04-08 19:34:54 +02:00
if [[ $1 == "recognize" ]]; then
if [[ $2 ]]; then
[[ $3 ]] || set -- "$1" "$2" "text"
2022-04-22 15:22:51 +02:00
[[ -f "$OUT/main" ]] || $0 build main
2022-04-08 19:34:54 +02:00
[[ -f ".cache/reseau.bin" ]] || $0 train train
"$OUT/main" recognize \
--modele ".cache/reseau.bin" \
--in "$2" \
--out "$3"
2022-04-10 21:40:59 +02:00
exit 0
2022-04-08 19:34:54 +02:00
else
echo "Pas de fichier d'entrée spécifié. Abandon"
exit 1
fi
fi
2022-04-22 15:22:51 +02:00
if [[ $1 == "utils" ]]; then
[[ -f "$OUT/utils" ]] || $0 build utils
"$OUT/utils" ${*:2}
exit 0
fi
2022-04-11 18:04:10 +02:00
if [[ $1 == "webserver" ]]; then
2022-04-22 15:22:51 +02:00
[[ -f "$OUT/main" ]] || $0 build main
2022-04-11 18:04:10 +02:00
[[ -f ".cache/reseau.bin" ]] || $0 train train
FLASK_APP="src/webserver/app.py" flask run
exit 0
fi
2022-03-27 15:03:13 +02:00
echo "Usage:"
2022-05-03 10:02:47 +02:00
echo -e "\t$0 build ( main | preview | train | utils | all )\n"
echo -e "\t$0 train ( train | t10k ) ( -r | --recover )"
echo -e "\t$0 preview ( train | t10k )"
echo -e "\t$0 test_reseau ( train | t10k )\n"
echo -e "\t$0 recognize [FILENAME] ( text | json )"
echo -e "\t$0 utils ( help )\n"
echo -e "\t$0 test ( run )"
2022-04-19 17:21:37 +02:00
echo -e "\t$0 webserver\n"
2022-05-03 10:02:47 +02:00
echo -e "Les fichiers de test sont recompilés à chaque exécution,\nles autres programmes sont compilés automatiquement si manquants\n"
echo -e "La plupart des options listées ici sont juste faites pour une utilisation plus rapide des commandes fréquentes,"
echo -e "d'autres options sont uniquement disponibles via les fichiers binaires dans '$OUT'"