-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpost_process.py
More file actions
69 lines (58 loc) · 2.48 KB
/
post_process.py
File metadata and controls
69 lines (58 loc) · 2.48 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
import numpy as np
import os
import json
with open('inf_mapping.txt') as f:
cls = f.readlines()
cls_map = {c.strip():(a.strip(),b.strip()) for a,c,b in [x.split(' ') for x in cls]}
cls2_map = {a.strip():c.strip() for a,c,b in [x.split(' ') for x in cls]}
to_th_id = {a.strip():b.strip() for a,_,b in [x.split(' ') for x in cls]}
lens = {}
for cls in cls_map.keys():
with open('annotations/'+cls+'.txt') as f:
d = f.readlines()
# d = [x for x in d if 'test' not in d]
ls = [x.split(' ') for x in d]
ls = [float(x[2]) - float(x[1]) for x in ls]
lens[cls] = np.asarray(ls).mean()
print(lens)
with open('preds.json') as f:
data = json.load(f)
#thrs =[0.1,0.4,0.2,0.3,0.6,0.3,0.2,0.6,0.4,0.2,0.7,0.7,0.2,0.2,0.8,0.2,0.5,0.4,0.3,0.5]
thrs =[0.1,0.2,0.1,0.1,0.2,0.1,0.1,0.2,0.2,0.1,0.2,0.2,0.1,0.1,0.2,0.1,0.1,0.2,0.1,0.2]
intervals = []
for vid in data.keys():
p, fps = data[vid]
fps = fps[0]
p = np.asarray(p)
for c in range(3):
k = lens[cls2_map[str(c+1)]]
k = int(k*fps)
prd = p[:,c] >thrs[c]+0.2
#np.convolve(p[:,c], np.ones((k,)), mode='same')/k
in_interval = 0
start = -1
for i in range(prd.shape[0]):
if in_interval == 0 and prd[i] == 1:
start = i
in_interval = 1
if in_interval == 1 and prd[i] == 0:
if (i-start)/fps < 0.5*lens[cls2_map[str(c+1)]]:
#print (i-start)/fps, lens[cls2_map[str(c+1)]]
in_interval = 0
start = -1
continue
if (i-start)/fps > 2*lens[cls2_map[str(c+1)]]:
ti = i - int((lens[cls2_map[str(c+1)]]*fps)/2)
intervals.append(vid+' '+str(start/fps)+' '+str(ti/fps)+' '+str(to_th_id[str(c+1)])+' '+str(p[(start+i)//2,c]))
start = ti+1
#print (i-start)/fps, lens[cls2_map[str(c+1)]]
#else:
intervals.append(vid+' '+str(start/fps)+' '+str(i/fps)+' '+str(to_th_id[str(c+1)])+' '+str(p[(start+i)//2,c]))
#intervals.append((to_th_id[str(c+1)], start, i))
in_interval = 0
start = -1
if in_interval == 1:
#intervals.append((to_th_id[c], start, i))
intervals.append(vid+' '+str(start/fps)+' '+str(i/fps)+' '+str(to_th_id[str(c+1)])+' '+str(p[start,c]))
with open('THUMOS14_evalkit_20150930/sel_i3d.txt', 'w') as out:
out.write('\n'.join(intervals))