forked from jbornschein/reweighted-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow-param-stats.py
executable file
·84 lines (59 loc) · 2.25 KB
/
show-param-stats.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
#!/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('--filter', type=str, default=None)
parser.add_argument('results', nargs='+')
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)
ylim = +np.inf
for result_dir in args.results:
fname = result_dir+"/results.h5"
try:
with h5py.File(fname, "r") as h5:
print "==== %s ====" % result_dir
logger.debug("Keys:")
for k, v in h5.iteritems():
logger.debug(" %-30s %s" % (k, v.shape))
for k,v in h5.iteritems():
if not 'model.' in k:
continue
if not args.filter is None:
if args.filter not in k:
continue
values = v[:]
iterations = v.shape[0]
values = values.reshape( [iterations, -1] )
v_min = np.min(values, axis=1)
v_max = np.max(values, axis=1)
v_mean = np.mean(values, axis=1)
pylab.errorbar(np.arange(iterations), v_mean, yerr=[v_max-v_mean, v_mean-v_min], label=k)
except KeyError as e:
logger.info("Failed to read data from %s: %s" % (fname, e))
except IOError as e:
logger.info("Failed to open %s fname: %s" % (fname, e))
#pylab.figsize(12, 8)
pylab.xlabel("Epochs")
pylab.ylabel("")
pylab.legend(loc="lower right")
pylab.show(block=True)