-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.py
73 lines (59 loc) · 2.38 KB
/
format.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Converts the TAG data to pickle files
import pickle
Acts = ['Approaching', 'Departing', 'Kicking', 'Pushing', 'Handshaking', 'Hugging', 'Exchanging', 'Punching']
top_dict = {ch:i for i, ch in enumerate(['X', 'DR', 'PO', 'EQ', 'PP', 'PPI'], start=0)}
dist_dict = {ch:i for i, ch in enumerate(['X', 'Away', 'Near', 'Close', 'Conn'], start=0)}
maxframes = 46
for act in Acts:
file = open(act+'_ExtC9_cw.txt', 'r')
lines = file.readlines()
file.close()
examples = {'topc':[], 'topw':[]}
for line in lines:
rels = line.split()
topc, topw = [], []
frames = int(rels[0])
a = 1
for i in range(frames):
topc.append(list())
for j in range(6):
if j < 5:
topc[i].append(list())
for k in range(6):
rel = rels[a].split('-')
a += 1
if j == 5 or k == 5:
continue
if top_dict[rel[0]] != 0:
topc[i][j].append([int(i == top_dict[rel[0]]) for i in range(5)])
else:
topc[i][j].append([0 for i in range(5)])
if dist_dict[rel[2]] != 0:
topc[i][j][k].extend([int(i == dist_dict[rel[2]]) for i in range(4)])
else:
topc[i][j][k].extend([0 for i in range(4)])
for i in range(frames, maxframes):
topc.append(list())
for j in range(5):
topc[i].append(list())
for k in range(5):
topc[i][j].append([0 for i in range(9)])
for i in range(frames):
rel = rels[a].split('-')
a += 1
if top_dict[rel[0]] != 0:
topw.append([int(i == top_dict[rel[0]]) for i in range(5)])
else:
topw.append([0 for i in range(5)])
if dist_dict[rel[2]] != 0:
topw[i].extend([int(i == dist_dict[rel[2]]) for i in range(4)])
else:
topw[i].extend([0 for i in range(4)])
for i in range(frames, maxframes):
topw.append([0 for i in range(9)])
examples['topc'].append(topc)
examples['topw'].append(topw)
print(act, len(examples['topw']))
file = open(act+'_v3.pickle', 'wb')
pickle.dump(examples, file)
file.close()