chainer.dataset.cache_or_load_file

chainer.dataset.cache_or_load_file(path, creator, loader)[source]

Caches a file if it does not exist, or loads it otherwise.

This is a utility function used in dataset loading routines. The creator creates the file to given path, and returns the content. If the file already exists, the loader is called instead, and it loads the file and returns the content.

Note that the path passed to the creator is temporary one, and not same as the path given to this function. This function safely renames the file created by the creator to a given path, even if this function is called simultaneously by multiple threads or processes.

Parameters
  • path (str) – Path to save the cached file.

  • creator – Function to create the file and returns the content. It takes a path to temporary place as the argument. Before calling the creator, there is no file at the temporary path.

  • loader – Function to load the cached file and returns the content.

Returns

It returns the returned values by the creator or the loader.