forked from goodfeli/adversarial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_gen_weights.py
59 lines (49 loc) · 1.39 KB
/
show_gen_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
import sys
from pylearn2.gui.patch_viewer import make_viewer
from pylearn2.utils import serial
model = serial.load(sys.argv[1])
generator = model.generator
final = generator.mlp.layers[-1]
success = False
i = -1
success = False
to_search = generator.mlp
while not success:
print "while loop ", i
final = to_search.layers[i]
if 'Composite' in str(type(final)):
i = input("which")
elem = final.layers[i]
if hasattr(elem, 'layers'):
print "stepping into inner MLP"
i = -1
to_search = elem
continue
else:
print "examining this element"
final = elem
try:
print "Trying get_weights topo"
topo = final.get_weights_topo()
print "It worked"
success = True
except Exception:
pass
if success:
print "Making the viewer and showing"
make_viewer(topo).show()
quit()
try:
print "Trying get_weights"
weights = final.get_weights()
print "It worked"
success = True
except NotImplementedError:
i -= 1 # skip over SpaceConverter, etc.
print "Out of the while loop"
print "weights shape ", weights.shape
viewer = make_viewer(weights, is_color=weights.shape[1] % 3 == 0 and weights.shape[1] != 48*48)
print "image shape ", viewer.image.shape
print "made viewer"
viewer.show()
print "executed show"