-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadc.py
More file actions
92 lines (66 loc) · 2.94 KB
/
adc.py
File metadata and controls
92 lines (66 loc) · 2.94 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
#Calculate the average detection confidence(ADC)
import os
import sys
import numpy as np
# Open the original annotation file of WIDER FACE training set.
fin = open('wider_face_train_bbx_gt.txt','r')
# The path of detection results on WIDER FACE training set, which is generated by TinaFace predicting detector.
tinaface_train_predict = './formulation/'
image_num = 0
# The sum of detection confidence
total_detection_confidence = np.float64(0.0)
total_gt_num = np.int64(0)
# The statistic number from predicted detection results, based on min(predict_num,gt_num) of each image.
# Here gt_num is the number of original annotations, while predict_num represents predicted detection results on their corresponding image.
total_statistic_num = np.int64(0)
while True:
im_path = fin.readline().replace('\r','').replace('\n','').replace('\t','')
if not im_path:
break
image_num = image_num + 1
print("Processing image %d" % image_num)
gt_num = int(fin.readline().replace('\r','').replace('\n','').replace('\t',''))
# Training image has no annotated bbox
if gt_num == 0:
continue
total_gt_num = total_gt_num + gt_num
# Construct the path of predict annotation
im_path = os.path.splitext(im_path)[0]
predict_anno_path = os.path.join(tinaface_train_predict, im_path + '.txt')
# Open predict annotation txt
fin_predict = open(predict_anno_path,'r')
# Read image path from predicted detection results
fin_predict.readline()
# Read the number of predict detection results
predict_num = int(fin_predict.readline().replace('\r','').replace('\n','').replace('\t',''))
# There are no predicted detection results
if predict_num == 0:
fin_predict.close()
for index in range(gt_num):
fin.readline()
continue
# Sum top_k predict detection confidence.
# Avoid predict_num < gt_num
# That is why we need a high performance predicting face detector
predict_index = min(predict_num,gt_num)
total_statistic_num = total_statistic_num + predict_index
detection_confidence_score = 0.0
# Obtain detection confidence of the top min(predict_num,gt_num)
while predict_index > 0:
fin.readline()
predict_anno_line = fin_predict.readline().split(" ")
detection_confidence_score = float(predict_anno_line[4])
total_detection_confidence = total_detection_confidence + detection_confidence_score
predict_index = predict_index - 1
# When predict_num < gt_num, scan the rest gt annotations to prepare for dealing with the next image annotation.
if predict_num < gt_num:
temp = gt_num - predict_num
while temp > 0:
fin.readline()
temp = temp -1
fin_predict.close()
pass
print("Total gt num: %d" % total_gt_num)
print("Total statistic num: %d" % total_statistic_num)
print("Average detection confidence score (ADC): %f" % (total_detection_confidence/total_statistic_num))
fin.close()