-
Notifications
You must be signed in to change notification settings - Fork 14
/
show-layerwise.py
executable file
·76 lines (56 loc) · 1.91 KB
/
show-layerwise.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
#!/usr/bin/env python
from __future__ import division
import sys
import logging
from time import time
import cPickle as pickle
import numpy as np
import h5py
import pylab
#import theano
#import theano.tensor as T
_logger = logging.getLogger()
#=============================================================================
if __name__ == "__main__":
import argparse
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action="store_true", default=False)
parser.add_argument('--dataset', '-d', default="valiset")
parser.add_argument('--samples', '-s', default=100)
parser.add_argument('--stacked', action="store_true", default=False)
parser.add_argument('out_dir', nargs=1)
args = parser.parse_args()
if args.verbose:
level = logging.DEBUG
else:
level = logging.INFO
FORMAT = '[%(asctime)s] %(message)s'
DATEFMT = "%H:%M:%S"
logging.basicConfig(format=FORMAT, datefmt=DATEFMT, level=level)
fname = args.out_dir[0]+"/results.h5"
table = "%s.spl%d.Hp" % (args.dataset, args.samples)
try:
with h5py.File(fname, "r") as h5:
Hp = h5[table][:]
except KeyError, e:
logger.info("Failed to read data from %s: %s" % (fname, e))
exit(1)
except IOError, e:
logger.info("Failed to open %s fname: %s" % (fname, e))
exit(1)
epochs = Hp.shape[0]
n_layers = Hp.shape[1]
if args.stacked:
ylim = 2*Hp[-1].sum()
pylab.ylim([ylim, 0])
pylab.stackplot(np.arange(epochs), Hp[:,::-1].T)
else:
ylim = 2*Hp[-1].min()
pylab.ylim([ylim, 0])
pylab.plot(Hp)
#pylab.figsize(12, 8)
pylab.xlabel("Epochs")
#pylab.ylabel("avg_{x~testdata} log( E_{h~q}[p(x,h)/q(h|x)]")
pylab.legend(["layer %d" % i for i in xrange(n_layers)], loc="lower right")
pylab.show(block=True)