forked from PalouseRobosub/vision_dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_data.sh
executable file
·54 lines (44 loc) · 1.17 KB
/
split_data.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
#!/bin/bash
# Given a folder, this script will split it into tar files with 100 images
# each inside, and also prepare sloth annotation files inside each one.
# This script is designed for splitting a large folder of images so that
# multiple people can later download and annotate them.
# directory we are operating on
src_dir=${1%/}
# how many files per folder
fpf=100
if [ "$src_dir" == "" ] ; then
echo "must supply directory to operate on"
exit 1
fi
echo "operating on ${src_dir}/"
# split images into folders with 100 images each
i=0;
echo "splitting into folders"
for f in ${src_dir}/*; do
d=${src_dir}_sub_$(printf %03d $((i/${fpf})))
if [ ! -d "$d" ] ; then
echo " $d"
mkdir $d
fi
cp "$f" $d
let i++
done
#create sloth annotation files
echo "creating sloth annotation files"
for d in ${src_dir}_sub_* ; do
echo " ${d}_labels.json"
sloth appendfiles -u ${d}/${d}_labels.json ${d}/*
done
#create tarballs
echo "creating tarballs"
for d in ${src_dir}_sub_* ; do
echo " ${d}.tar"
tar -cf ${d}.tar ${d}
done
#remove temporary subfolders
echo "cleaning up"
for d in ${src_dir}_sub_*/ ; do
rm -rf ${d}
done
echo "done!"