tipe/make.sh

98 lines
2.5 KiB
Bash
Raw Normal View History

2022-03-21 17:18:49 +01:00
#!/bin/bash
2022-03-25 19:19:57 +01:00
FLAGS="-std=c99 -lm"
2022-04-08 19:34:54 +02:00
OUT="out"
2022-03-25 19:19:57 +01:00
2022-03-21 17:18:49 +01:00
if [[ $1 == "preview" ]]; then
[[ $2 ]] || set -- "$1" "build"
if [[ $2 == "build" ]]; then
2022-04-08 19:34:54 +02:00
mkdir -p "$OUT"
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-03-21 17:18:49 +01:00
elif [[ $2 == "train" ]]; then
2022-04-08 19:34:54 +02:00
[[ -f "$OUT/preview_mnist" ]] || $0 preview build
"$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-08 19:34:54 +02:00
[[ -f "$OUT/preview_mnist" ]] || $0 preview build
"$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
[[ $2 ]] || set -- "$1" "build"
if [[ $2 == "build" ]]; then
2022-04-08 19:34:54 +02:00
mkdir -p "$OUT"
2022-03-27 14:42:00 +02:00
for i in $(ls test); do
2022-03-27 15:03:13 +02:00
echo "Compilation de test/$i"
2022-04-08 19:34:54 +02:00
gcc "test/$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}')" $FLAGS
2022-03-27 15:03:13 +02:00
echo "Fait."
2022-03-27 14:42:00 +02:00
done
2022-04-10 21:40:59 +02:00
exit 0
2022-03-27 14:42:00 +02:00
elif [[ $2 == "run" ]]; then
$0 test build
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 == "build" ]]; then
2022-04-19 13:55:08 +02:00
mkdir -p "$OUT"
2022-04-08 19:34:54 +02:00
echo "Compilation de src/mnist/main.c"
gcc src/mnist/main.c -o "$OUT/main" $FLAGS
echo "Fait."
2022-04-10 21:40:59 +02:00
exit 0
2022-04-08 19:34:54 +02:00
fi
if [[ $1 == "train" ]]; then
[[ -f "$OUT/main" ]] || $0 build
[[ $2 ]] || set -- "$1" "train"
2022-04-25 14:39:45 +02:00
[[ $3 == "-r" || $3 == "--recover" ]] && RECOVER="-r .cache/network.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-25 14:39:45 +02:00
--out ".cache/network.bin" \
2022-04-19 17:21:37 +02:00
$RECOVER
2022-04-10 21:40:59 +02:00
exit 0
2022-04-08 19:34:54 +02:00
fi
if [[ $1 == "recognize" ]]; then
if [[ $2 ]]; then
[[ $3 ]] || set -- "$1" "$2" "text"
[[ -f "$OUT/main" ]] || $0 build
2022-04-25 14:39:45 +02:00
[[ -f ".cache/network.bin" ]] || $0 train train
2022-04-08 19:34:54 +02:00
"$OUT/main" recognize \
2022-04-25 14:39:45 +02:00
--modele ".cache/network.bin" \
2022-04-08 19:34:54 +02:00
--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-11 18:04:10 +02:00
if [[ $1 == "webserver" ]]; then
[[ -f "$OUT/main" ]] || $0 build
2022-04-25 14:39:45 +02:00
[[ -f ".cache/network.bin" ]] || $0 train train
2022-04-11 18:04:10 +02:00
FLASK_APP="src/webserver/app.py" flask run
exit 0
fi
2022-03-27 15:03:13 +02:00
echo "Usage:"
echo -e "\t$0 preview ( build | train | t10k )"
2022-04-08 19:34:54 +02:00
echo -e "\t$0 test ( build | run )"
echo -e "\t$0 build"
2022-04-19 17:21:37 +02:00
echo -e "\t$0 train ( train | t10k ) ( -r | --recover )"
echo -e "\t$0 recognize [FILENAME] ( text | json )"
echo -e "\t$0 webserver\n"
2022-03-27 15:03:13 +02:00
echo -e "Les fichiers de test sont recompilés à chaque exécution,\nles autres programmes sont compilés automatiquement si manquants"