-
Notifications
You must be signed in to change notification settings - Fork 0
/
B1_evaluateRois.py
53 lines (44 loc) · 1.97 KB
/
B1_evaluateRois.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
# -*- coding: utf-8 -*-
import sys, os, importlib
import PARAMETERS
locals().update(importlib.import_module("PARAMETERS").__dict__)
####################################
# Parameters
####################################
subdirs = ['positive']
####################################
# Main
####################################
overlaps = []
roiCounts = []
for subdir in subdirs:
imgFilenames = getFilesInDirectory(imgDir + subdir, ".jpg")
#loop over all iamges
for imgIndex,imgFilename in enumerate(imgFilenames):
if imgIndex % 20 == 0:
print "Processing subdir '{}', image {} of {}".format(subdir, imgIndex, len(imgFilenames))
# load ground truth
imgPath = imgDir + subdir + "/" + imgFilename
imgWidth, imgHeight = imWidthHeight(imgPath)
gtBoxes, gtLabels = readGtAnnotation(imgPath)
gtBoxes = [Bbox(*rect) for rect in gtBoxes]
# load rois and compute scale
rois = readRois(roiDir, subdir, imgFilename)
rois = [Bbox(*roi) for roi in rois]
roiCounts.append(len(rois))
# for each ground truth, compute if it is covered by an roi
for gtIndex, (gtLabel, gtBox) in enumerate(zip(gtLabels,gtBoxes)):
maxOverlap = -1
assert (gtBox.max() <= max(imgWidth, imgHeight) and gtBox.max() >= 0)
if gtLabel in classes[1:]:
for roi in rois:
assert (roi.max() <= max(imgWidth, imgHeight) and roi.max() >= 0)
overlap = bboxComputeOverlapVoc(gtBox, roi)
maxOverlap = max(maxOverlap, overlap)
overlaps.append(maxOverlap)
print "Average number of rois per image " + str(1.0 * sum(roiCounts) / len(imgFilenames))
#compute recall at different overlaps
overlaps = np.array(overlaps, np.float32)
for overlapThreshold in np.linspace(0,1,11):
recall = 1.0 * sum(overlaps >= overlapThreshold) / len(overlaps)
print "At threshold {:.2f}: recall = {:2.2f}".format(overlapThreshold, recall)