Merge branch 'main' into main

This commit is contained in:
augustin64 2022-04-25 18:58:08 +02:00 committed by GitHub
commit 5741ab64d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 39 deletions

17
.github/workflows/compilation.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Compile all
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Compile all
run: ./make.sh build all

99
make.sh
View File

@ -3,37 +3,59 @@
FLAGS="-std=c99 -lm" FLAGS="-std=c99 -lm"
OUT="out" OUT="out"
if [[ $1 == "preview" ]]; then if [[ $1 == "build" ]]; then
[[ $2 ]] || set -- "$1" "build" mkdir -p "$OUT"
if [[ $2 == "build" ]]; then [[ $2 ]] || set "$1" "main"
mkdir -p "$OUT" 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
echo "Compilation de src/mnist/preview.c" echo "Compilation de src/mnist/preview.c"
gcc src/mnist/preview.c -o "$OUT/preview_mnist" $FLAGS gcc src/mnist/preview.c -o "$OUT/preview_mnist" $FLAGS
echo "Fait." echo "Fait."
exit 0 exit 0
elif [[ $2 == "train" ]]; then elif [[ $2 == "test" ]]; then
[[ -f "$OUT/preview_mnist" ]] || $0 preview build
"$OUT/preview_mnist" data/mnist/train-images-idx3-ubyte data/mnist/train-labels-idx1-ubyte
exit 0
elif [[ $2 == "t10k" ]]; then
[[ -f "$OUT/preview_mnist" ]] || $0 preview build
"$OUT/preview_mnist" data/mnist/t10k-images-idx3-ubyte data/mnist/t10k-labels-idx1-ubyte
exit 0
fi
fi
if [[ $1 == "test" ]]; then
[[ $2 ]] || set -- "$1" "build"
if [[ $2 == "build" ]]; then
mkdir -p "$OUT"
for i in $(ls test); do for i in $(ls test); do
echo "Compilation de test/$i" echo "Compilation de test/$i"
gcc "test/$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}')" $FLAGS gcc "test/$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}')" $FLAGS
echo "Fait." echo "Fait."
done done
exit 0 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
elif [[ $2 == "train" ]]; then
[[ -f "$OUT/preview_mnist" ]] || $0 build preview
"$OUT/preview_mnist" data/mnist/train-images-idx3-ubyte data/mnist/train-labels-idx1-ubyte
exit 0
elif [[ $2 == "t10k" ]]; then
[[ -f "$OUT/preview_mnist" ]] || $0 build preview
"$OUT/preview_mnist" data/mnist/t10k-images-idx3-ubyte data/mnist/t10k-labels-idx1-ubyte
exit 0
fi
fi
if [[ $1 == "test" ]]; then
if [[ ! $2 ]]; then
$0 build test
exit 0
elif [[ $2 == "run" ]]; then elif [[ $2 == "run" ]]; then
$0 test build $0 build test
mkdir -p .test-cache mkdir -p .test-cache
for i in $(ls "$OUT/test_"*); do for i in $(ls "$OUT/test_"*); do
echo "--- $i ---" echo "--- $i ---"
@ -43,23 +65,15 @@ if [[ $1 == "test" ]]; then
fi fi
fi fi
if [[ $1 == "build" ]]; then
mkdir -p "$OUT"
echo "Compilation de src/mnist/main.c"
gcc src/mnist/main.c -o "$OUT/main" $FLAGS
echo "Fait."
exit 0
fi
if [[ $1 == "train" ]]; then if [[ $1 == "train" ]]; then
[[ -f "$OUT/main" ]] || $0 build [[ -f "$OUT/main" ]] || $0 build main
[[ $2 ]] || set -- "$1" "train" [[ $2 ]] || set -- "$1" "train"
[[ $3 == "-r" || $3 == "--recover" ]] && RECOVER="-r .cache/network.bin" [[ $3 == "-r" || $3 == "--recover" ]] && RECOVER="-r .cache/reseau.bin"
mkdir -p .cache mkdir -p .cache
"$OUT/main" train \ "$OUT/main" train \
--images "data/mnist/$2-images-idx3-ubyte" \ --images "data/mnist/$2-images-idx3-ubyte" \
--labels "data/mnist/$2-labels-idx1-ubyte" \ --labels "data/mnist/$2-labels-idx1-ubyte" \
--out ".cache/network.bin" \ --out ".cache/reseau.bin" \
$RECOVER $RECOVER
exit 0 exit 0
fi fi
@ -67,10 +81,10 @@ fi
if [[ $1 == "recognize" ]]; then if [[ $1 == "recognize" ]]; then
if [[ $2 ]]; then if [[ $2 ]]; then
[[ $3 ]] || set -- "$1" "$2" "text" [[ $3 ]] || set -- "$1" "$2" "text"
[[ -f "$OUT/main" ]] || $0 build [[ -f "$OUT/main" ]] || $0 build main
[[ -f ".cache/network.bin" ]] || $0 train train [[ -f ".cache/reseau.bin" ]] || $0 train train
"$OUT/main" recognize \ "$OUT/main" recognize \
--modele ".cache/network.bin" \ --modele ".cache/reseau.bin" \
--in "$2" \ --in "$2" \
--out "$3" --out "$3"
exit 0 exit 0
@ -80,18 +94,25 @@ if [[ $1 == "recognize" ]]; then
fi fi
fi fi
if [[ $1 == "utils" ]]; then
[[ -f "$OUT/utils" ]] || $0 build utils
"$OUT/utils" ${*:2}
exit 0
fi
if [[ $1 == "webserver" ]]; then if [[ $1 == "webserver" ]]; then
[[ -f "$OUT/main" ]] || $0 build [[ -f "$OUT/main" ]] || $0 build main
[[ -f ".cache/network.bin" ]] || $0 train train [[ -f ".cache/reseau.bin" ]] || $0 train train
FLASK_APP="src/webserver/app.py" flask run FLASK_APP="src/webserver/app.py" flask run
exit 0 exit 0
fi fi
echo "Usage:" echo "Usage:"
echo -e "\t$0 preview ( build | train | t10k )" echo -e "\t$0 preview ( train | t10k )"
echo -e "\t$0 test ( build | run )" echo -e "\t$0 test ( run )"
echo -e "\t$0 build" echo -e "\t$0 build ( main | preview | train | utils | all )"
echo -e "\t$0 train ( train | t10k ) ( -r | --recover )" echo -e "\t$0 train ( train | t10k ) ( -r | --recover )"
echo -e "\t$0 recognize [FILENAME] ( text | json )" echo -e "\t$0 recognize [FILENAME] ( text | json )"
echo -e "\t$0 utils ( help )"
echo -e "\t$0 webserver\n" echo -e "\t$0 webserver\n"
echo -e "Les fichiers de test sont recompilés à chaque exécution,\nles autres programmes sont compilés automatiquement si manquants" echo -e "Les fichiers de test sont recompilés à chaque exécution,\nles autres programmes sont compilés automatiquement si manquants"