Skip to content

Commit 484564b

Browse files
committed
correct typos and add test plot
1 parent f2638c1 commit 484564b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

data/convert_tblog.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, path_to_log, path_to_save, experiment_list, metric_list, comb
2323
:param title: <str> Title of the plot
2424
"""
2525
self.path_to_log = path_to_log
26-
self.val_only = val_only
26+
self.test_only = val_only
2727
self.metric_list = metric_list
2828
self.combine = combine
2929
self.title = title
@@ -80,25 +80,28 @@ def create_train_val_plot(self, field, tf_log, exp, title=None, legend_label=Non
8080
:param legend_label: <str> specify legend name
8181
:return:
8282
"""
83-
train, val, epoch = [], [], []
83+
train, val, test, epoch = [], [], [], []
8484
for e in tf.train.summary_iterator(tf_log):
8585
for v in e.summary.value:
8686
if v.tag == 'train_{}'.format(field):
8787
train.append(v.simple_value)
8888
epoch.append(e.step)
8989
if v.tag == 'val_{}'.format(field):
9090
val.append(v.simple_value)
91+
if v.tag == 'test_{}'.format(field):
92+
test.append(v.simple_value)
9193

9294
# save as plot
93-
if not self.val_only:
94-
plt.plot(epoch, train, '--', label='train {} {}'.format(field, legend_label if legend_label else ''))
95-
plt.plot(epoch, val, '--', label='val {} {}'.format(field, legend_label if legend_label else ''))
95+
if not self.test_only:
96+
plt.plot(epoch, train, '-', label='train {} {}'.format(field, legend_label if legend_label else ''))
97+
plt.plot(epoch, val, '-', label='val {} {}'.format(field, legend_label if legend_label else ''))
98+
plt.plot(epoch, test, '-', label='test {} {}'.format(field, legend_label if legend_label else ''))
9699
plt.xlabel('Epoch')
97100
plt.legend(loc='best')
98101
if title:
99102
plt.title(title)
100103
else:
101-
plt.title('train {0} vs. val {0}'.format(field))
104+
plt.title('train {0}, val {0} and test {0}'.format(field))
102105

103106
if not self.combine:
104107
save_fig_to = os.path.join(self.path_to_save, exp, '{}_train_val_{}.pdf'.format(exp, field))
@@ -115,7 +118,7 @@ def create_train_val_plot(self, field, tf_log, exp, title=None, legend_label=Non
115118
default='../')
116119
parser.add_argument("--experiment_list", help='Experiments to parse logs for.', nargs='*', default=None)
117120
parser.add_argument("--combine", help='If used, combines plots across experiments', action='store_true')
118-
parser.add_argument("--val_only", help='If used, combines plots across experiments for val metrics only', action='store_true')
121+
parser.add_argument("--test_only", help='If used, combines plots across experiments for test metrics only', action='store_true')
119122
parser.add_argument("--legend_labels", help='List of labels for the legend', nargs='*', default=None)
120123
parser.add_argument("--title", help='List of labels for the legend', type=str, default=None)
121124
parser.add_argument("--metric_list", help='Metrics to plot.', nargs='*', default=['macro_f1', 'micro_f1', 'loss',
@@ -129,7 +132,7 @@ def create_train_val_plot(self, field, tf_log, exp, title=None, legend_label=Non
129132
experiment_list=args.experiment_list,
130133
metric_list=args.metric_list,
131134
combine=args.combine,
132-
val_only=args.val_only,
135+
val_only=args.test_only,
133136
legend_labels=args.legend_labels,
134137
title=args.title)
135138
clog.convert_exp()

0 commit comments

Comments
 (0)