-
Notifications
You must be signed in to change notification settings - Fork 3
/
preprocess_datasets.sh
executable file
·71 lines (58 loc) · 1.9 KB
/
preprocess_datasets.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
#!/bin/bash
declare -a train_images=("thermal" "winter" "summer")
declare -a valid_images=("thermal" "winter" "summer")
declare -A train_limits=( ["thermal"]=3890 ["summer"]=3790 ["winter"]=4580)
train_file="lstm_train.txt"
valid_file="lstm_valid.txt"
cfg_file="yolo_v3_spp_lstm.cfg"
data_file="lstm.data"
name_file="lstm.names"
#image_dir="$PWD/darknet/build/darknet/x64/data/lstm"
image_dir="$HOME/Downloads/lstm"
[ -f "$train_file" ] && rm "$train_file"
[ -f "$valid_file" ] && rm "$valid_file"
rm -rf "$image_dir"
mkdir "$image_dir"
for ds in "${train_images[@]}";
do
echo $ds
python convert_coco_yolo.py "${ds}.json" "${ds}" "${image_dir}"
i=0
while IFS= read line
do
printf "$HOME/Downloads/lstm/${ds}_$line\n" >> "$train_file";
cp "$HOME/Downloads/${ds}/${line}" "${image_dir}/${ds}_${line}" 2>/dev/null
i=$(($i + 1))
if [ $i -eq "${train_limits[$ds]}" ]
then
break
fi
done <"${ds}.txt"
done
for ds in "${valid_images[@]}";
do
echo $ds
i=0
while IFS= read line
do
if [ $i -gt "${train_limits[$ds]}" ]
then
printf "$HOME/Downloads/lstm/${ds}_$line\n" >> "$valid_file";
cp "$HOME/Downloads/${ds}/${line}" "${image_dir}/${ds}_${line}" 2>/dev/null
fi
i=$(($i + 1))
done <"${ds}.txt"
done
#shuf "$train_file" > "train_file_shuffled.txt"
#mv "train_file_shuffled.txt" "$train_file"
#shuf "$valid_file" > "valid_file_shuffled.txt"
#mv "valid_file_shuffled.txt" "$valid_file"
# Copy necessary files to the correct directories
cp "$cfg_file" "$PWD/darknet/build/darknet/x64/"
cp "$train_file" "$PWD/darknet/build/darknet/x64/data/"
cp "$valid_file" "$PWD/darknet/build/darknet/x64/data/"
cp "$data_file" "$PWD/darknet/build/darknet/x64/data/"
cp "$name_file" "$PWD/darknet/build/darknet/x64/data/"
cp "run_all_iters.sh" "$PWD/darknet/build/darknet/x64/"
# Download pretrained weight
#wget https://pjreddie.com/media/files/darknet53.conv.74 -O "$PWD/darknet/build/darknet/x64/darknet53.conv.74"