-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_visualizeResults.py
61 lines (48 loc) · 2.34 KB
/
5_visualizeResults.py
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
import os, importlib, sys
import PARAMETERS
locals().update(importlib.import_module("PARAMETERS").__dict__)
####################################
# Parameters
####################################
image_set = 'test' #'train', 'test'
svm_experimentName = 'exp1'
#no need to change these parameters
boUseNonMaximaSurpression = True
visualizationDir = resultsDir + "visualizations"
cntkParsedOutputDir = cntkFilesDir + image_set + "_" + classifier + "_parsed/"
####################################
# Main
####################################
#load svm
print "classifier = " + classifier
makeDirectory(resultsDir)
makeDirectory(visualizationDir)
if classifier == "svm":
print "Loading svm weights.."
svmWeights, svmBias, svmFeatScale = loadSvm(trainedSvmDir, svm_experimentName)
#loop over all images and visualize
imdb = imdbs[image_set]
for imgIndex in range(0, imdb.num_images):
imgPath = imdb.image_path_at(imgIndex)
imgWidth, imgHeight = imWidthHeight(imgPath)
#evaluate classifier for all rois
if classifier == "svm":
labels, scores = svmPredict(imgIndex, cntkParsedOutputDir, svmWeights, svmBias, svmFeatScale, cntk_nrRois, len(classes), vis_decisionThresholds[classifier])
elif classifier == "nn":
labels, scores = nnPredict(imgIndex, cntkParsedOutputDir, cntk_nrRois, len(classes), vis_decisionThresholds[classifier])
else:
ERROR
#remove the zero-padded rois
scores = scores[:len(imdb.roidb[imgIndex]['boxes'])]
labels = labels[:len(imdb.roidb[imgIndex]['boxes'])]
#perform non-maxima surpression. note that the detected classes in the image is not affected by this.
nmsKeepIndices = []
if boUseNonMaximaSurpression:
nmsKeepIndices = applyNonMaximaSuppression(nmsThreshold, labels, scores, imdb.roidb[imgIndex]['boxes'])
print "Non-maxima surpression kept {:4} of {:4} rois (nmsThreshold={})".format(len(nmsKeepIndices), len(labels), nmsThreshold)
#visualize results
imgDebug = visualizeResults(imgPath, labels, scores, imdb.roidb[imgIndex]['boxes'], cntk_padWidth, cntk_padHeight,
classes, nmsKeepIndices, boDrawNegativeRois=False, boDrawNmsRejectedRois=False)
#imshow(imgDebug, waitDuration=0, maxDim = 800)
imwrite(imgDebug, visualizationDir + "/" + classifier + "_" + str(imgIndex) + os.path.basename(imgPath))
print "DONE."