Utility class that manages a group of files with a shared base name.

For actions like SavedModel exporting, there are potentially many different file naming and cleanup strategies that may be desirable. This class provides a basic interface allowing SavedModel export to be decoupled from these details, and a default implementation that should work for many basic scenarios. Users may subclass this class to alter behavior and define more customized naming and cleanup strategies.

base_name A shared base name for file names generated by this class.
max_to_keep The maximum number of files matching base_name to keep after each call to cleanup. The most recent (as determined by file modification time) max_to_keep files are preserved; the rest are deleted. If < 0, all files are preserved.
next_id_fn An optional callable that returns integer IDs to append to base name (formatted as '{base_name}-{id}'). The order of integers is used to sort files to determine the oldest ones deleted by clean_up. If not supplied, a default ID based on an incrementing counter is used. One common alternative maybe be to use the current global step count, for instance passing next_id_fn=global_step.numpy.

managed_files Returns all files managed by this instance, in sorted order.



View source

Cleans up old files matching {base_name}-*.

The most recent max_to_keep files are preserved.


View source

Returns a new file name based on base_name and next_id_fn().