-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·105 lines (92 loc) · 3.32 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
#SBATCH --job-name=thesis_preprocess
#SBATCH --output=setup-%j.log
#SBATCH --cpus-per-task=1
#SBATCH --mem=200G
#SBATCH --time=04:00:00
# Accept flags from the command line:
# -d: force download of dataset
# -b: force generation of bboxes
# -c: force generation of crops
# -n <number>: number of crops to generate
# combination of flags is possible (e.g. -bc), except for -n
# Help function
function usage {
echo "Usage: $0 [-d] [-b] [-c] [-e] [-s] [-P] [-n <number>]"
echo " -d: force download of dataset"
echo " -b: force generation of bboxes"
echo " -c: force generation of crops"
echo " -e: force generation of environment"
echo " -s: force separation of crops in train/val/test sets"
echo " -P: force ALL preprocessing steps"
echo " -n <number>: number of crops to generate (default = 50)"
echo " combination of flags is possible (e.g. -bc), except for -n"
exit 1
}
# Process flags
download=""
bboxes=""
crops=""
separate=""
env=false
preprocessAll=false
numCrops=50
while getopts ":dbcsPen:" opt; do
case $opt in
d) download="-f";;
b) bboxes="-f";;
c) crops="-f";;
s) separate="-f";;
e) env=true;;
P) preprocessAll=true;;
n) numCrops="$OPTARG"
if ! [[ "$numCrops" =~ ^[0-9]+$ ]] ; then
echo "error: -n argument is not a number" >&2
usage
fi;;
\?) echo "Invalid option -$OPTARG" >&2
usage;;
esac
done
# If P flag is set, set all flags
if [ "$preprocessAll" = true ] ; then
bboxes="-f"
crops="-f"
separate="-f"
fi
# Pretty print welcome message
echo ""
echo ""
echo "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
echo "SWORD-SIMP Dataset Setup Script"
echo "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
echo "Dataset location: $SCRATCH/dataset/source"
echo "Force download of database = $download"
echo "Force generation of bboxes = $bboxes"
echo "Force generation of crops = $crops"
echo "Force generation of environment = $env"
echo "Force separation of crops = $separate"
echo "Number of crops = $numCrops"
echo "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
echo ""
echo ""
WORKDIR=$(pwd)
SCRATCH=/scratch/$USER
# If e flag is set, delete the virtual environment if it exists
if [ "$env" = true ] ; then
if [ -d "$HOME/.envs/thesis_env" ] ; then
echo "Deleting virtual environment..."
rm -rf $HOME/.envs/thesis_env
fi
fi
# Set up the environment (module load, virtual environment, requirements)
chmod +x $WORKDIR/setup_env.sh
source $WORKDIR/setup_env.sh
# download dataset using the download script in work dir (force if flag is set), if it fails exit
python3 -u $WORKDIR/download.py $SCRATCH/dataset/source/images $download || exit
# generate the bboxes (force if flag is set), if it fails exit
python3 -u $WORKDIR/extract_bboxes.py $SCRATCH/dataset/source/images -o $SCRATCH/dataset/source/labels $bboxes || exit
# generate crops (force if flag is set), if it fails exit
python3 -u $WORKDIR/generate_crops.py $SCRATCH/dataset/source/ $numCrops $crops || exit
sbatch --dependency=afterok:$SLURM_JOB_ID separate_crops.sh $separate
deactivate