chainer.training.extensions.LogReport¶
-
class
chainer.training.extensions.
LogReport
(keys=None, trigger=(1, 'epoch'), postprocess=None, filename='log')[source]¶ Trainer extension to output the accumulated results to a log file.
This extension accumulates the observations of the trainer to
DictSummary
at a regular interval specified by a supplied trigger, and writes them into a log file in JSON format.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 some entries to each result dictionary.
'epoch'
and'iteration'
are the epoch and iteration counts at the output, respectively.'elapsed_time'
is the elapsed time in seconds since the training begins. The value is taken fromTrainer.elapsed_time
.
- Parameters
keys (iterable of strs) – Keys of values to accumulate. If this is None, all the values are accumulated and output to the log file.
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>, 'epoch'
or<int>, 'iteration'
, it is passed toIntervalTrigger
.postprocess – Callback to postprocess the result dictionaries. Each result dictionary is passed to this callback on the output. This callback can modify the result dictionaries, which are used to output to the log file.
filename (str) – Name of the log file under the output directory. It can be a format string: the last result dictionary is passed for the formatting. For example, users can use ‘{iteration}’ to separate the log files for different iterations. If the log name is None, it does not output the log to any file. For historical reasons
log_name
is also accepted as an alias of this argument.
Methods
-
__call__
(trainer)[source]¶ 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.
-
initialize
(trainer)[source]¶ Initializes up the trainer state.
This method is called before entering the training loop. An extension that modifies the state of
Trainer
can 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.
For example,
ExponentialShift
extension 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. TheExponentialShift
extension recovers it in itsinitialize
method 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)[source]¶ 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.
-
serialize
(serializer)[source]¶ Serializes the extension state.
It is called when a trainer that owns this extension is serialized. It serializes nothing by default.
-
__eq__
()¶ Return self==value.
-
__ne__
()¶ Return self!=value.
-
__lt__
()¶ Return self<value.
-
__le__
()¶ Return self<=value.
-
__gt__
()¶ Return self>value.
-
__ge__
()¶ Return self>=value.
Attributes
-
default_name
¶ 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.
-
log
¶ The current list of observation dictionaries.
-
name
= None¶
-
priority
= 100¶
-
trigger
= (1, 'iteration')¶