code: def snapshot_object(target, filename, savefun=None, **kwargs):
      """snapshot_object(target, filename, savefun=None, \
  *, condition=None, writer=None, snapshot_on_error=False, \
  n_retains=-1, autoload=False)
  
      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.
  
      Args:
          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 :meth:`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
              :class:`~chainer.training.extensions.snapshot_writers.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.
  
      Returns:
          Snapshot extension object.
  
      .. seealso::
  
          - :meth:`chainer.training.extensions.snapshot`
      """
      if "num_retain" in kwargs:
          warnings.warn(
              "Argument `num_retain` is deprecated. "
              "Please use `n_retains` instead",
              DeprecationWarning,
          )
          kwargs["n_retains"] = kwargs.pop("num_retain")
  
      return snapshot(
          target=target, filename=filename, savefun=savefun, **kwargs
      )
  
imports: import os
  import warnings
  import chainer
  from chainer.serializers import npz
  from chainer.training import extension
  from chainer.training.extensions import snapshot_writers
  from chainer.utils import argument
label_desc: Use image node_id 4 for calling a global function with example usage: snapshot_object(target, filename, savefun) and returns: snapshot