forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreproduceMSRC.sh
executable file
·130 lines (107 loc) · 3.5 KB
/
reproduceMSRC.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
121
122
123
124
125
126
127
128
129
#!/bin/bash
# The purpose is to reproduce SOA results on the MSRC data set.
#
# You need to do something like this:
#
# export PYTHONPATH="/home/sherrahj/code/lib/slic-python:/home/sherrahj/code/alienMarkovNetworks/maxflow"
#
# Recommend low number of cores like 8 because there is nesting, parallel within
# parallel, and it uses too much ram.
dataPath="$1"; shift
outDir="$1"; shift
typeset -i nbCores="$1"; shift
if [ -z "$dataPath" -o -z "$outDir" ]; then
echo "Usage Error:"
echo " reproduceMSRC.sh <MSRC data path> <output directory> <nbCores>"
echo "The output dir must not exist. The input directory contains"
echo "the pre-generated train/val/test data sets, see createMSRCPartition.sh"
echo "and README.md."
exit 1
fi
set -e
# Steps are:
# - extract features from images
# - train classifier
# - apply classifier to images
# - apply MRF to classifications
# - compute accuracy of classifier output, MRF output against GT
#
# Parameters
#
# In github see these issues:
#
# https://github.com/RockStarCoders/alienMarkovNetworks/issues/27
# https://github.com/RockStarCoders/alienMarkovNetworks/issues/10
#
slicN=400
slicC=10.0
K=0.2
ftrsBase="$outDir"/ftrsTrain
clfrFn="$outDir"/classifier.pkl
oclDir="$outDir"/classified
olabDir="$outDir"/labelled
if true; then
# Create output directory. It must not already exist.
mkdir "$outDir"
echo "*** Creating training features..."
./createFeatures.py --type=pkl \
--nbSuperPixels=$slicN --superPixelCompactness=$slicC \
"$dataPath/trainingPlusValidation" "$ftrsBase" --nbCores $nbCores
echo " done"
if true; then
# make special training only, validation only sets
./createFeatures.py --type=pkl \
--nbSuperPixels=$slicN --superPixelCompactness=$slicC \
"$dataPath/training" "${ftrsBase}-train" --nbCores $nbCores
./createFeatures.py --type=pkl \
--nbSuperPixels=$slicN --superPixelCompactness=$slicC \
"$dataPath/validation" "${ftrsBase}-validation" --nbCores $nbCores
fi
echo "*** Training classifier..."
./trainClassifier.py --type=randyforest \
--paramSearchFolds=0 \
--rf_n_estimators=500 \
--rf_max_depth=None \
--rf_max_features=75 \
--rf_min_samples_leaf=5 \
--rf_min_samples_split=10 \
"${ftrsBase}_ftrs.pkl" "${ftrsBase}_labs.pkl" \
--outfile="$clfrFn" --nbJobs $nbCores
echo " done"
echo "*** Classify test images..."
mkdir "$oclDir"
./classifyAllImages.sh "$clfrFn" "$oclDir" $slicN $slicC $nbCores \
"$dataPath"/test/Images/*.bmp
echo " done"
echo "*** Label test images..."
mkdir "$olabDir"
./labelAllImagesGivenProbs.sh $K "$olabDir" $nbCores \
"$oclDir"/*.pkl
echo " done"
echo "*** Evaluating results..."
echo " * Classifier only: "
./evalPredictions.py "$oclDir"/evalpairs.csv "$dataPath/test" ''
echo " * Classifier+MRF: "
./evalPredictions.py "$olabDir"/evalpairs.csv "$dataPath/test" ''
echo " done"
fi
#
# ... and Training
#
echo "*** Classify training images..."
mkdir "$oclDir"/training
./classifyAllImages.sh "$clfrFn" "$oclDir"/training $slicN $slicC $nbCores \
"$dataPath"/training/Images/*.bmp
echo "*** Evaluating results..."
./evalPredictions.py "$oclDir"/training/evalpairs.csv "$dataPath/training" ''
echo " done"
#
# Validation too
#
echo "*** Classify validation images..."
mkdir "$oclDir"/validation
./classifyAllImages.sh "$clfrFn" "$oclDir"/validation $slicN $slicC $nbCores \
"$dataPath"/validation/Images/*.bmp
echo "*** Evaluating results..."
./evalPredictions.py "$oclDir"/validation/evalpairs.csv "$dataPath/validation" ''
echo " done"