|
Safemotion Lib
|
Public Member Functions | |
| __init__ (self, nn.Module model, str save_dir="", *bool save_to_disk=True, **object checkpointables) | |
| save (self, str name, **dict kwargs) | |
| load (self, str path) | |
| has_checkpoint (self) | |
| get_checkpoint_file (self) | |
| get_all_checkpoint_files (self) | |
| resume_or_load (self, str path, *bool resume=True) | |
| tag_last_checkpoint (self, str last_filename_basename) | |
Public Attributes | |
| model | |
| checkpointables | |
| logger | |
| save_dir | |
| save_to_disk | |
Protected Member Functions | |
| _load_file (self, str f) | |
| _load_model (self, Any checkpoint) | |
| _convert_ndarray_to_tensor (self, dict state_dict) | |
A checkpointer that can save/load model as well as extra checkpointable objects.
Definition at line 20 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.__init__ | ( | self, | |
| nn.Module | model, | ||
| str | save_dir = "", | ||
| *bool | save_to_disk = True, | ||
| **object | checkpointables ) |
Args:
model (nn.Module): model.
save_dir (str): a directory to save and find checkpoints.
save_to_disk (bool): if True, save checkpoint to disk, otherwise
disable saving for this checkpointer.
checkpointables (object): any checkpointable objects, i.e., objects
that have the `state_dict()` and `load_state_dict()` method. For
example, it can be used like
`Checkpointer(model, "dir", optimizer=optimizer)`.
Definition at line 26 of file checkpoint.py.
|
protected |
In-place convert all numpy arrays in the state_dict to torch tensor.
Args:
state_dict (dict): a state-dict to be loaded to the model.
Definition at line 228 of file checkpoint.py.
|
protected |
Load a checkpoint file. Can be overwritten by subclasses to support
different formats.
Args:
f (str): a locally mounted file path.
Returns:
dict: with keys "model" and optionally others that are saved by
the checkpointer dict["model"] must be a dict which maps strings
to torch.Tensor or numpy arrays.
Definition at line 174 of file checkpoint.py.
|
protected |
Load weights from a checkpoint.
Args:
checkpoint (Any): checkpoint contains the weights.
Definition at line 187 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.get_all_checkpoint_files | ( | self | ) |
Returns:
list: All available checkpoint files (.pth files) in target
directory.
Definition at line 135 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.get_checkpoint_file | ( | self | ) |
Returns:
str: The latest checkpoint file in target directory.
Definition at line 120 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.has_checkpoint | ( | self | ) |
Returns:
bool: whether a checkpoint exists in the target directory.
Definition at line 112 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.load | ( | self, | |
| str | path ) |
Load from the given checkpoint. When path points to network file, this
function has to be called on all ranks.
Args:
path (str): path or url to the checkpoint. If empty, will not load
anything.
Returns:
dict:
extra data loaded from the checkpoint that has not been
processed. For example, those saved with
:meth:`.save(**extra_data)`.
Definition at line 77 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.resume_or_load | ( | self, | |
| str | path, | ||
| *bool | resume = True ) |
If `resume` is True, this method attempts to resume from the last
checkpoint, if exists. Otherwise, load checkpoint from the given path.
This is useful when restarting an interrupted training job.
Args:
path (str): path to the checkpoint.
resume (bool): if True, resume from the last checkpoint if it exists.
Returns:
same as :meth:`load`.
Definition at line 149 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.save | ( | self, | |
| str | name, | ||
| **dict | kwargs ) |
Dump model and checkpointables to a file.
Args:
name (str): name of the file.
kwargs (dict): extra arbitrary data to save.
Definition at line 53 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.tag_last_checkpoint | ( | self, | |
| str | last_filename_basename ) |
Tag the last checkpoint.
Args:
last_filename_basename (str): the basename of the last filename.
Definition at line 164 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.checkpointables |
Definition at line 48 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.logger |
Definition at line 49 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.model |
Definition at line 47 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.save_dir |
Definition at line 50 of file checkpoint.py.
| fastreid.utils.checkpoint.Checkpointer.save_to_disk |
Definition at line 51 of file checkpoint.py.