fix for coding guidelines
+import json
+import numpy
+from os import path
+
+import six
+
from chainer import reporter
import chainer.serializer as serializer_module
from chainer.training import extension
import chainer.training.trigger as trigger_module
-import json
-import numpy as np
-from os import path
-import six
try:
import matplotlib
@@ -29,10 +31,7 @@ Please install matplotlib to plot figure.
class PlotReport(extension.Extension):
-
- def __init__(self, y_keys, x_key='iteration', trigger=(1, 'epoch'),
- postprocess=None, file_name='graph.png'):
- """Trainer extension to output graph.
+ """Trainer extension to output plots.
This extension accumulates the observations of the trainer to
:class:`~chainer.DictSummary` at a regular interval specified by a
@@ -53,7 +52,8 @@ class PlotReport(extension.Extension):
Args:
y_keys (iterable of strs): Keys of values regarded as y. If this is
None, nothing is output to the graph.
- x_key (str): Keys of values regarded as x.
+ x_key (str): Keys of values regarded as x. The default value is
+ 'iteration'
trigger: Trigger that decides when to aggregate the result and
output the values. This is distinct from the trigger of this
extension itself. If it is a tuple in the form
@@ -67,6 +67,9 @@ class PlotReport(extension.Extension):
"""
+ def __init__(self, y_keys, x_key='iteration', trigger=(1, 'epoch'),
+ postprocess=None, file_name='graph.png'):
+
_check_available()
self._x_key = x_key
@@ -116,13 +119,12 @@ class PlotReport(extension.Extension):
continue
flag_any_item = True
- xy = np.array(xy)
+ xy = numpy.array(xy)
a.plot(xy[:, 0], xy[:, 1], label=k)
if flag_any_item:
if self._postprocess is not None:
self._postprocess(f, a, summary)
-
f.savefig(path.join(trainer.out, self._file_name))
plot.close()
@@ -130,12 +132,12 @@ class PlotReport(extension.Extension):
def serialize(self, serializer):
if isinstance(serializer, serializer_module.Serializer):
- serializer('_graph_{}'.format(self._file_name),
+ serializer('_plot_{}'.format(self._file_name),
json.dumps(self._data))
else:
self._data = json.loads(
- serializer('_graph_{}'.format(self._file_name), ''))
+ serializer('_plot_{}'.format(self._file_name), ''))
def _init_summary(self):
self._summary = reporter.DictSummary()
