-
Notifications
You must be signed in to change notification settings - Fork 0
/
pick.py
executable file
·49 lines (40 loc) · 1.05 KB
/
pick.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
#!/usr/bin/python
"""Pick up some of MLP parameter.
Usage:
pick.py [options] <file>
pick.py -h | --help
options:
-h, --help Show this help.
--of=<file> Output file.
-p <0..>, --pick=<0..> The index of layer to pick.(-p I to pick one, -p I:J to pick I to J)
"""
import re
from docopt import docopt
import numpy as np
import util,dataio
if __name__=='__main__':
args = docopt(__doc__)
of = args["--of"]
pick = args["--pick"]
file = args["<file>"]
nn, actfs = dataio.loadnn(file)
p = []
if re.match(r"^\d$", pick):
p = [ int(pick) ]
elif re.match(r"^\d:\d$", pick):
r = pick.rstrip().split(':')
assert len(r) == 2
r = map(int, r)
p = range(r[0], r[1])
else:
util.panic("Pick up argument is Unknown format: %s" % pick)
d = {}
j = 0
for i in p:
l = getattr(nn, 'l_' + str(i))
s = str(j)
d['w_' + s] = l.W.data
d['hbias_' + s] = l.b.data
d['type_' + s] = actfs[i].__name__
j += 1
np.savez(of, **d)