-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathictext_eval.py
More file actions
60 lines (52 loc) · 1.92 KB
/
ictext_eval.py
File metadata and controls
60 lines (52 loc) · 1.92 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
import random
import argparse
from coco import COCO
from cocoeval import COCOeval
def evaluate(test_annotation_file, user_submission_file, aesthetic, fps = None, mem = None):
print("\n----------Starting Evaluation----------\n")
cocoGT = COCO(test_annotation_file)
cocoDt = cocoGT.loadRes(user_submission_file, aesthetic=aesthetic)
cocoEval = COCOeval(cocoGT, cocoDt, 'bbox')
cocoEval.params.multi_label = aesthetic
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
stats = cocoEval.stats
if not aesthetic:
output = {
"AP": stats[0],
"AP IOU@0.5": stats[1],
"AP IOU@0.75": stats[2],
}
score = stats[0]
else:
output = {
"AP": stats[0],
"AP IOU@0.5": stats[1],
"AP IOU@0.75": stats[2],
"Multi-Label Precision": stats[12],
"Multi-Label Recall": stats[13],
"Multi-Label F-2 Score (IOU@0.5)": stats[14],
}
score = stats[14]
if fps is not None and mem is not None:
output["FPS"] = fps
output["GPU Memory (MB)"] = mem
if not aesthetic and score >= 0.5:
output["3S"] = calculate_final(score, fps, mem)
elif aesthetic and score >= 0.5 and stats[0] >= 0.5:
output["3S"] = calculate_final(score, fps, mem)
else:
print("Score is too low for consideration. Minimum score for mAP is 0.5 and multi-label f2-score is 0.5.")
output["3S"] = 0
print("\n----------Completed Evaluation----------\n")
return output
def calculate_final(norm_score, fps, mem):
fps = fps/30
mem = mem/4000
norm_spd = min(fps, 1)
norm_size = min(mem, 1)
final_score = 0.2 * norm_spd + 0.2 * (1 - norm_size) + 0.6 * norm_score
print("Speed: {} | Size: {} | Score: {} | 3S: {}".format(
norm_spd, (1 - norm_size), norm_score, final_score))
return final_score