forked from Kevinz-code/CSRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal_mAP.py
56 lines (34 loc) · 1019 Bytes
/
cal_mAP.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
import os
import numpy as np
import torch
import json
def json_map(cls_id, pred_json, ann_json, types):
assert len(ann_json) == len(pred_json)
num = len(ann_json)
predict = np.zeros((num), dtype=np.float64)
target = np.zeros((num), dtype=np.float64)
for i in range(num):
predict[i] = pred_json[i]["scores"][cls_id]
target[i] = ann_json[i]["target"][cls_id]
if types == 'wider':
tmp = np.where(target != 99)[0]
predict = predict[tmp]
target = target[tmp]
num = len(tmp)
if types == 'voc07':
tmp = np.where(target != 0)[0]
predict = predict[tmp]
target = target[tmp]
neg_id = np.where(target == -1)[0]
target[neg_id] = 0
num = len(tmp)
tmp = np.argsort(-predict)
target = target[tmp]
predict = predict[tmp]
pre, obj = 0, 0
for i in range(num):
if target[i] == 1:
obj += 1.0
pre += obj / (i+1)
pre /= obj
return pre