PlotReport(y_keys, x_key='iteration', trigger=(1, 'epoch'), postprocess=None, filename=None, marker='x', grid=True, **kwargs)¶
Trainer extension to output plots.
This extension accumulates the observations of the trainer to
DictSummaryat a regular interval specified by a supplied trigger, and plot a graph with using them.
There are two triggers to handle this extension. One is the trigger to invoke this extension, which is used to handle the timing of accumulating the results. It is set to
1, 'iteration'by default. The other is the trigger to determine when to emit the result. When this trigger returns True, this extension appends the summary of accumulated values to the list of past summaries, and writes the list to the log file. Then, this extension makes a new fresh summary object which is used until the next time that the trigger fires.
It also adds
'iteration'entries to each result dictionary, which are the epoch and iteration counts at the output.
If your environment needs to specify a backend of matplotlib explicitly, please call
trainer.run. For example:
import matplotlib matplotlib.use('Agg') trainer.extend( extensions.PlotReport(['main/loss', 'validation/main/loss'], 'epoch', file_name='loss.png')) trainer.run()
Then, once one of instances of this extension is called,
matplotlib.usewill have no effect.
For the details, please see here: https://matplotlib.org/faq/usage_faq.html#what-is-a-backend
- 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. 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
<int>, 'iteration', it is passed to
- postprocess – Callback to postprocess the result dictionaries. Figure object, Axes object, and all plot data are passed to this callback in this order. This callback can modify the figure.
- filename (str) – Name of the figure file under the output directory. It can be a format string. Although it is recommended to use this argument, you can also specify the file name of a figure with the file_name argument for backward compatibility. If both filename and file_name are specified, filename will be used.
- marker (str) – The marker used to plot the graph. Default is
Noneis given, it draws with no markers.
- grid (bool) – Set the axis grid on if True. Default is True.
Invokes the extension.
Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.
Parameters: trainer (Trainer) – Trainer object that calls this operator.
Finalizes the extension.
This method is called at the end of the training loop.
Initializes up the trainer state.
This method is called before entering the training loop. An extension that modifies the state of
Trainercan override this method to initialize it.
When the trainer has been restored from a snapshot, this method has to recover an appropriate part of the state of the trainer.
ExponentialShiftextension changes the optimizer’s hyperparameter at each invocation. Note that the hyperparameter is not saved to the snapshot; it is the responsibility of the extension to recover the hyperparameter. The
ExponentialShiftextension recovers it in its
initializemethod if it has been loaded from a snapshot, or just setting the initial value otherwise.
Parameters: trainer (Trainer) – Trainer object that runs the training loop.
on_error(trainer, exc, tb)¶
Handles the error raised during training before finalization.
This method is called when an exception is thrown during the training loop, before finalize. An extension that needs different error handling from finalize, can override this method to handle errors.
Serializes the extension state.
It is called when a trainer that owns this extension is serialized. It serializes nothing by default.
Default name of the extension.
It is the name of the class by default. Implementation can override this property, or provide a class attribute to hide it.
trigger= (1, 'iteration')¶