-
Notifications
You must be signed in to change notification settings - Fork 1
/
fp_extract_weights.py
executable file
·84 lines (50 loc) · 1.33 KB
/
fp_extract_weights.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
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
import re, sys
def explode(input_str):
dest = input_str[0]
order = int(input_str[1:])
return (dest, order)
def emit(weightList, fileName):
fileHandle = open(fileName, "w")
for weight in weightList:
fileHandle.write(str(weight))
fileHandle.write("\n")
fileHandle.close()
packed_weight_order = [
"f1-f18",
"p1-p8"
]
weights_order = []
for i in packed_weight_order:
pair = i.split("-")
p1 = explode(pair[0])
p2 = explode(pair[1])
for o in range(p1[1], p2[1]+1):
weights_order.append(p1[0] + str(o))
#pattern = r'{(.+)}.'
pattern = r'{([+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)}.+'
fileInput = open(sys.argv[1])
weights = []
for line in fileInput:
matchObj = re.match(pattern, line)
if matchObj:
weights.append(float(matchObj.group(1)))
#print line
fileInput.close()
if len(weights) != len(weights_order):
print "Weights-Order mismatch. Weights=%d, Order=%d" % (len(weights), len(weights_order))
sys.exit(1)
p = []
f = []
for idx in range(len(weights)):
weight = weights[idx]
order = weights_order[idx]
if order[0] == 'w':
w.append(weight)
elif order[0] == 'p':
p.append(weight)
elif order[0] == 'o':
o.append(weight)
elif order[0] == 'f':
f.append(weight)
emit(f, "f.txt")