, filename, savefun=None, *, condition=None, writer=None, snapshot_on_error=False, n_retains=- 1, autoload=False)[source]

Returns a trainer extension to take snapshots of a given object.

This extension serializes the given object and saves it to the output directory.

This extension is called once per epoch by default. To take a snapshot at a different interval, a trigger object specifying the required interval can be passed along with this extension to the extend() method of the trainer.

The default priority is -100, which is lower than that of most built-in extensions.

  • target – Object to serialize.

  • filename (str) – Name of the file into which the object is serialized. It can be a format string, where the trainer object is passed to the str.format() method. For example, 'snapshot_{.updater.iteration}' is converted to 'snapshot_10000' at the 10,000th iteration.

  • savefun – Function to save the object. It takes two arguments: the output file path and the object to serialize.

  • condition – Condition object. It must be a callable object that returns boolean without any arguments. If it returns True, the snapshot will be done. If not, it will be skipped. The default is a function that always returns True.

  • writer – Writer object. It must be a callable object. See below for the list of built-in writers. If savefun is other than None, this argument must be None. In that case, a SimpleWriter object instantiated with specified savefun argument will be used.

  • snapshot_on_error (bool) – Whether to take a snapshot in case trainer loop has been failed.

  • n_retains (int) – Number of snapshot files to retain through the cleanup. Must be a positive integer for any cleanup to take place. Automatic deletion of old snapshots only works when the filename is string.

  • num_retain (int) – Same as n_retains (deprecated).

  • autoload (bool) – With this enabled, the extension automatically finds the latest snapshot and loads the data to the target. Automatic loading only works when the filename is a string.


Snapshot extension object.