forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateMSRCPartition.sh
executable file
·120 lines (108 loc) · 3.39 KB
/
createMSRCPartition.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# This script creates the partition of MSRC data into training, validation and
# test images published by Shotton and used by others. To be consistent with
# the literature so comparisons are valid.
#
# For generality, it's all done through subdirectories and sym links. You
# provide the source data directory for the data set, make sure you use an
# absolute path. Then you provide a destination. The default is:
#
# <repoPath>/vagrant/msrcData
#
# so that when you use a VM, the data is accessible from /vagrant on the VM.
#
# For the code to work it assumes the MSRC directory structure, this is
# recreated for each of the training, validation and test set:
#
# <destPath>/training/Images/
# <destPath>/training/GroundTruth/
# <destPath>/training/SegmentationsGTHighQuality/
#
# <destPath>/validation/Images/
# <destPath>/validation/GroundTruth/
# <destPath>/validation/SegmentationsGTHighQuality/
#
# <destPath>/test/Images/
# <destPath>/test/GroundTruth/
# <destPath>/test/SegmentationsGTHighQuality/
#
# On the command line you also provide the three text files containing the input
# images for each of training, validation and test. The format is path-less
# filenames of the images, one per line:
#
# 16_11_s.bmp
# 15_24_s.bmp
# 8_25_s.bmp
# 2_15_s.bmp
# 11_22_s.bmp
# ...
#
#
# Note: ignoring high quality gt for now.
function Usage() {
echo "Usage:"
echo " ./createMSRCPartition.sh [-c] <MSRCDataPath> <trList.txt> <valList.txt> <tstList.txt> <destPath>"
echo "If the optional -c flag is given, then the files are copied instead of symlinked."
}
if [ "$1" == "-c" ]; then
doCopy="true"
echo "COPY MODE"
shift
fi
typeset -a dataSets=('training' 'validation' 'test')
msrcPath="$1"; shift
if [ ! -d "$msrcPath" ]; then
echo "Error: MSRC path does not exist"
Usage
exit 1
fi
typeset -a fileLists=()
for (( i=0; i<3; ++i )) {
infile="$1"; shift
fileLists[$i]="$infile"
if [ ! -f "$infile" ]; then
echo "Error: ${dataSets[$i]} set list file $infile does not exist."
Usage
exit 1
fi
}
destPath="$1"; shift
if [ -d "$destPath" ]; then
echo "Error: Destination path $destPath areadly exists. Exiting"
exit 1
fi
if [ ! -d $(dirname "$destPath") ]; then
echo "Error: Destination directory base $(dirname "$destPath") does not exist"
exit 1
fi
# no errors from now on
set -e
echo "Source data set at $msrcPath"
echo "Making outdir $destPath"
mkdir "$destPath"
for (( i=0; i<3; ++i )) {
dsname=${dataSets[$i]}
odir="$destPath/$dsname"
echo "*** Creating $dsname set under $odir"
mkdir -p "$odir/Images"
mkdir -p "$odir/GroundTruth"
#mkdir -p "$odir/SegmentationsGTHighQuality"
# Iterate over files in our file list
listFile="${fileLists[$i]}"
while read imgFile; do
bfn=$(basename $imgFile)
if [ -z "$doCopy" ]; then
ln -s "$msrcPath/Images/$imgFile" "$odir/Images/"
ln -s "$msrcPath/GroundTruth/${imgFile%.bmp}_GT.bmp" "$odir/GroundTruth/"
else
cp "$msrcPath/Images/$imgFile" "$odir/Images/"
cp "$msrcPath/GroundTruth/${imgFile%.bmp}_GT.bmp" "$odir/GroundTruth/"
fi
done < "$listFile"
echo ""
}
# Finally construct the trainingPlusValidation directory.
echo "*** Creating trainingPlusValidation directory..."
cp -r "$destPath"/training "$destPath"/trainingPlusValidation
cp -r "$destPath"/validation "$destPath"/trainingPlusValidation
echo "Finito"