-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathex4.sh
More file actions
326 lines (250 loc) · 8.96 KB
/
ex4.sh
File metadata and controls
326 lines (250 loc) · 8.96 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# /usr/bin/bash
sourceDir=$1
dataDir=$2
whatToDo=$3
outIMDir=$dataDir/outIm/
treeTopPredDir=$dataDir/bestDetections/
outputDir=$sourceDir/exp4/
mosaicString="1 2 3 4 5 6 7 8 9"
env1="drone"
env2="newFastai"
lRString="0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009"
#lRString="0.01 0.02"
#archString="res dense vgg squ alex"
#archString="dense"
classString="deciduous sickfir healthyfir"
epochs=10
augment=$5
frozen=$6
methodInput=$4"augment"$augment"Frozen"$frozen
archString=$7
trainAllSites=0
trainIndividualSites=1
echo $methodInput
summaryFile=$outputDir/$methodInput"summary.txt"
echo " make sure to prepare paramfile with correct paths!!!!"
#echo "data dir $dataDir"
# Codify the actions that the script will perform
dataPreparation=0
train=0
predict=0
evaluate=0
compute=0
shutdown=0
if [[ $whatToDo == *"d"* ]]; then
dataPreparation=1
fi
if [[ $whatToDo == *"t"* ]]; then
train=1
fi
if [[ $whatToDo == *"c"* ]]; then
compute=1
fi
if [[ $whatToDo == *"e"* ]]; then
evaluate=1
fi
if [[ $whatToDo == *"s"* ]]; then
shutdown=1
fi
if [[ $dataPreparation = 1 ]];then
echo "Data preparation re-do Masks"
conda activate $env1
bash reDoClassMasks.sh $dataDir
conda deactivate
for i in $mosaicString
do
mkdir $dataDir/patches$i
done
echo "Data preparation re-patching"
conda activate $env2
python $sourceDir/treeTopPatcher.py ./paramFile$augment $augment
conda deactivate
echo "Data preparation re-making site folders"
# create one folder per site, also create one folder for all images
cd $dataDir
mkdir site1
cd site1
cp ../patches4/*.* ./
cp ../patches5/*.* ./
cp ../patches6/*.* ./
cp ../patches7/*.* ./
cp ../patches8/*.* ./
cp ../patches9/*.* ./
cd ..
mkdir site2
cd site2
cp ../patches1/*.* ./
cp ../patches2/*.* ./
cp ../patches3/*.* ./
cp ../patches6/*.* ./
cp ../patches8/*.* ./
cp ../patches9/*.* ./
cd ..
mkdir site3
cd site3
cp ../patches1/*.* ./
cp ../patches2/*.* ./
cp ../patches3/*.* ./
cp ../patches4/*.* ./
cp ../patches5/*.* ./
cp ../patches7/*.* ./
cp ../patches9/*.* ./
cd ..
mkdir site4
cd site4
cp ../patches1/*.* ./
cp ../patches2/*.* ./
cp ../patches3/*.* ./
cp ../patches4/*.* ./
cp ../patches5/*.* ./
cp ../patches6/*.* ./
cp ../patches7/*.* ./
cp ../patches8/*.* ./
cd ..
mkdir AllSites
cd AllSites
cp ../patches1/*.* ./
cp ../patches2/*.* ./
cp ../patches3/*.* ./
cp ../patches4/*.* ./
cp ../patches5/*.* ./
cp ../patches6/*.* ./
cp ../patches7/*.* ./
cp ../patches8/*.* ./
cp ../patches9/*.* ./
cd ..
cd $sourceDir
pwd
fi
if [[ $compute = 1 ]];then
mkdir $outIMDir/
for i in $mosaicString
do
mkdir $outIMDir/mosaic$i
done
fi
if [[ $evaluate = 1 ]];then
mkdir $outputDir/
fi
for net in $archString
do
for lr in $lRString
do
conda activate $env2
if [[ $train = 1 ]];then
if [[ $trainAllSites = 1 ]];then
echo "training!"
START=$(date +%s)
echo "models for "model"$net"LR"$lr"epochs"$epochs"frozen"$frozen "
# TRAIN MODEL FOR ALL POSSIBLE SITE COMBINATIONS
echo "training all sites"
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/AllSites/ "ASmodel"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net t $epochs $lr $frozen
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "training all sites done in $DIFF "
fi
if [[ $trainIndividualSites = 1 ]];then
echo "models for "model"$net"LR"$lr"epochs"$epochs"frozen"$frozen "
siteString="1 2 3 4"
for sit in $siteString
do
echo "trainig site $sit"
START=$(date +%s)
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site$sit/ "S"$sit"model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net t $epochs $lr $frozen
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "training site $sit done in $DIFF "
done
fi
fi
conda deactivate
if [[ $compute = 1 ]];then
echo "Testing (computing treetop prediction maps)"
conda activate $env2
#rm $sourceDir/tempImage*.*
#first, do site 1
siteString="1 2 3"
for mos in $siteString
do
echo "python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site1/ "S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/"
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site1/ "S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/
done
#second, do site 2
siteString="4 5 7"
for mos in $siteString
do
echo "python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site2/ "S2model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/"
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site2/ "S2model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/
done
#third, do site 3
siteString="6 8"
for mos in $siteString
do
echo "python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site3/ "S3model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/"
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site3/ "S3model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/
done
#fourth, do site 4
siteString="9"
for mos in $siteString
do
echo "python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site4/ "S4model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/"
python $sourceDir/forestSpeciesPatchClassifierGenerateTreetopMasks.py $dataDir/site4/ "S4model"$net"LR"$lr"epochs"$epochs"frozen"$frozen $net p $treeTopPredDir/Z$mos"Best.jpg" $dataDir/Z$mos".jpg" $outIMDir/mosaic$mos/
done
conda deactivate
fi
if [[ $evaluate = 1 ]];then
conda activate $env1
echo -n "$net"LR"$lr"epochs"$epochs" >> $summaryFile
siteString="1 2 3"
for i in $siteString
do
roiMaskFileName=$dataDir"/Z"$i"ROI.jpg"
epsilon=125
outputFilePrefix=$outIMDir"/mosaic$i/S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen
python $sourceDir/zaoExp4Processer.py $dataDir"/Z"$i $outputFilePrefix $epsilon $classString >> $summaryFile
# Evaluate matched percent
#class=deciduous
#outputFileName=$outIMDir"/mosaic$i/S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen$class"tops.jpg"
#python $sourceDir/crownSegmenterEvaluator.py 1 $dataDir"/Z"$i$class"tops.jpg" $outputFileName $roiMaskFileName $epsilon >> $percentFiledeciduous
#python $sourceDir/crownSegmenterEvaluator.py 1 $outputFileName $dataDir"/Z"$i$class"tops.jpg" $roiMaskFileName $epsilon >> $reversePercentFiledeciduous
#class=sickfir
#outputFileName=$outIMDir"/mosaic$i/S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen$class"tops.jpg"
#python $sourceDir/crownSegmenterEvaluator.py 1 $dataDir"/Z"$i$class"tops.jpg" $outputFileName $roiMaskFileName $epsilon >> $percentFilesickfir
#python $sourceDir/crownSegmenterEvaluator.py 1 $outputFileName $dataDir"/Z"$i$class"tops.jpg" $roiMaskFileName $epsilon >> $reversePercentFilesickfir
#class=healthyfir
#outputFileName=$outIMDir"/mosaic$i/S1model"$net"LR"$lr"epochs"$epochs"frozen"$frozen$class"tops.jpg"
#python $sourceDir/crownSegmenterEvaluator.py 1 $dataDir"/Z"$i$class"tops.jpg" $outputFileName $roiMaskFileName $epsilon >> $percentFilehealthyfir
#python $sourceDir/crownSegmenterEvaluator.py 1 $outputFileName $dataDir"/Z"$i$class"tops.jpg" $roiMaskFileName $epsilon >> $reversePercentFilehealthyfir
done
siteString="4 5 7"
for i in $siteString
do
roiMaskFileName=$dataDir"/Z"$i"ROI.jpg"
epsilon=125
outputFilePrefix=$outIMDir"/mosaic$i/S2model"$net"LR"$lr"epochs"$epochs"frozen"$frozen
python $sourceDir/zaoExp4Processer.py $dataDir"/Z"$i $outputFilePrefix $epsilon $classString >> $summaryFile
done
siteString="6 8"
for i in $siteString
do
roiMaskFileName=$dataDir"/Z"$i"ROI.jpg"
epsilon=100
outputFilePrefix=$outIMDir"/mosaic$i/S3model"$net"LR"$lr"epochs"$epochs"frozen"$frozen
python $sourceDir/zaoExp4Processer.py $dataDir"/Z"$i $outputFilePrefix $epsilon $classString >> $summaryFile
done
siteString="9"
for i in $siteString
do
roiMaskFileName=$dataDir"/Z"$i"ROI.jpg"
epsilon=100
outputFilePrefix=$outIMDir"/mosaic$i/S4model"$net"LR"$lr"epochs"$epochs"frozen"$frozen
python $sourceDir/zaoExp4Processer.py $dataDir"/Z"$i $outputFilePrefix $epsilon $classString >> $summaryFile
done
echo "" >> $summaryFile
conda deactivate
fi
done
done
if [[ $shutdown = 1 ]];then
shutdown
fi