-
Notifications
You must be signed in to change notification settings - Fork 26
/
plot_attr.py
58 lines (49 loc) · 1.82 KB
/
plot_attr.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
import sys, numpy as np
import cPickle as pkl
import matplotlib.pyplot as plt
from matplotlib import cm
paths = sys.argv[1:]
instances = []
for i, path in enumerate(paths):
try:
label, path = path.split(":")
except ValueError:
label = i
print(label, path)
instances.append(dict(label=label,
path=path,
data=pkl.load(open(path))))
def dump(path):
data = dict((instance["label"],
dict(train=instance["data"]["train_err_ave"],
valid=instance["data"]["valid_errs"]))
for instance in instances)
pkl.dump(data, open(path, "wb"))
import pdb; pdb.set_trace()
colors = "r b g purple maroon darkslategray darkolivegreen orangered".split()
colors = cm.rainbow(np.linspace(0, 1, len(instances)))
channel_labels = dict(train_err_ave="train",
valid_errs="valid")
plt.figure()
for channel_name, kwargs in [
("train_err_ave", dict(linestyle="dotted")),
("valid_errs", dict(linestyle="solid"))]:
for color, instance in zip(colors, instances):
label = "%s %s" % (instance["label"], channel_labels[channel_name])
plt.plot(np.asarray(instance["data"][channel_name]), label=label, color=color, linewidth=3, **kwargs)
plt.legend()
plt.xlim((0, 800))
plt.ylabel("error rate")
plt.xlabel("training steps (thousands)")
plt.figure()
for channel_name, kwargs in [
("train_cost_ave", dict(linestyle="dotted")),
("valid_costs", dict(linestyle="solid"))]:
for color, instance in zip(colors, instances):
label = "%s %s" % (instance["label"], channel_name)
plt.plot(instance["data"][channel_name], label=label, color=color, linewidth=3, **kwargs)
plt.legend()
plt.xlim((0, 800))
plt.ylabel("error rate")
plt.xlabel("training steps")
plt.show()