-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_iou.py
50 lines (32 loc) · 977 Bytes
/
get_iou.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
import glob
import pickle
from pdb import set_trace
import yaml
def get_iou(gt, obj):
with open(gt, "rb") as f:
gt_mask = pickle.load(f)
with open(obj, "rb") as f:
obj_mask = pickle.load(f)
iou = []
for gt_slice, obj_slice in zip(gt_mask, obj_mask):
gt_slice = gt_slice == 1
obj_slice = obj_slice == 1
iou.append(
((gt_slice & obj_slice).sum() / (gt_slice | obj_slice).sum()).item()
)
return iou
attr = "FPN"
folder = "visdrone/videos"
gt_fmt = f"vis_%d*meas2_gtbbox*delta_64*{attr}*.mask"
obj_fmt = f"vis_%d*blackgen_obj_{attr}.mp4.mask"
def get_name(fmt, fid):
print(fmt)
ret = glob.glob1(folder, fmt % fid)
print(ret)
assert len(ret) == 1
return folder + "/" + ret[0]
result = []
for fid in range(169, 174):
result = result + get_iou(get_name(gt_fmt, 171), get_name(obj_fmt, 171))
with open(f"IoU_{attr}.txt", "w") as f:
f.write(yaml.dump(result))