cvpods.checkpoint package¶
-
class
cvpods.checkpoint.Checkpointer(model: torch.nn.modules.module.Module, save_dir: str = '', resume: bool = False, *, save_to_disk: bool = True, **checkpointables: object)[source]¶ Bases:
objectA checkpointer that can save/load model as well as extra checkpointable objects.
-
__init__(model: torch.nn.modules.module.Module, save_dir: str = '', resume: bool = False, *, save_to_disk: bool = True, **checkpointables: object)[source]¶ - Parameters
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).
-
save(name: str, tag_checkpoint: bool = True, **kwargs: dict)[source]¶ Dump model and checkpointables to a file.
-
load(path: str)[source]¶ Load from the given checkpoint. When path points to network file, this function has to be called on all ranks.
- Parameters
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
save(**extra_data)().
-
get_all_checkpoint_files()[source]¶ - Returns
list –
- All available checkpoint files (.pth files) in target
directory.
-
-
class
cvpods.checkpoint.DefaultCheckpointer(model, save_dir='', resume=False, *, save_to_disk=None, **checkpointables)[source]¶ Bases:
cvpods.checkpoint.checkpoint.CheckpointerSame as
Checkpointer, but is able to handle models in detectron & cvpods model zoo, and apply conversions for legacy models.-
__init__(model, save_dir='', resume=False, *, save_to_disk=None, **checkpointables)[source]¶ - Parameters
model (nn.Module) – model.
save_dir (str) – a directory to save and find checkpoints.
resume (bool) – indicate whether to resume from latest checkpoint or start from scratch.
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).
-
-
class
cvpods.checkpoint.PeriodicCheckpointer(checkpointer: Any, period: int, max_iter: int = None, max_epoch: Optional[int] = None)[source]¶ Bases:
objectSave checkpoints periodically. When .step(iteration) is called, it will execute checkpointer.save on the given checkpointer, if iteration is a multiple of period or if max_iter is reached.
-
__init__(checkpointer: Any, period: int, max_iter: int = None, max_epoch: Optional[int] = None)[source]¶
-
step(iteration: int, **kwargs: Any)[source]¶ Perform the appropriate action at the given iteration.
- Parameters
iteration (int) – the current iteration, ranged in [0, max_iter-1].
kwargs (Any) – extra data to save, same as in
Checkpointer.save().
-
save(name: str, **kwargs: Any)[source]¶ Same argument as
Checkpointer.save(). Use this method to manually save checkpoints outside the schedule.- Parameters
name (str) – file name.
kwargs (Any) – extra data to save, same as in
Checkpointer.save().
-
cvpods.checkpoint.checkpoint module¶
-
class
cvpods.checkpoint.checkpoint.Checkpointer(model: torch.nn.modules.module.Module, save_dir: str = '', resume: bool = False, *, save_to_disk: bool = True, **checkpointables: object)[source]¶ Bases:
objectA checkpointer that can save/load model as well as extra checkpointable objects.
-
__init__(model: torch.nn.modules.module.Module, save_dir: str = '', resume: bool = False, *, save_to_disk: bool = True, **checkpointables: object)[source]¶ - Parameters
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).
-
save(name: str, tag_checkpoint: bool = True, **kwargs: dict)[source]¶ Dump model and checkpointables to a file.
-
load(path: str)[source]¶ Load from the given checkpoint. When path points to network file, this function has to be called on all ranks.
- Parameters
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
save(**extra_data)().
-
get_all_checkpoint_files()[source]¶ - Returns
list –
- All available checkpoint files (.pth files) in target
directory.
-
-
class
cvpods.checkpoint.checkpoint.PeriodicCheckpointer(checkpointer: Any, period: int, max_iter: int = None, max_epoch: Optional[int] = None)[source]¶ Bases:
objectSave checkpoints periodically. When .step(iteration) is called, it will execute checkpointer.save on the given checkpointer, if iteration is a multiple of period or if max_iter is reached.
-
__init__(checkpointer: Any, period: int, max_iter: int = None, max_epoch: Optional[int] = None)[source]¶
-
step(iteration: int, **kwargs: Any)[source]¶ Perform the appropriate action at the given iteration.
- Parameters
iteration (int) – the current iteration, ranged in [0, max_iter-1].
kwargs (Any) – extra data to save, same as in
Checkpointer.save().
-
save(name: str, **kwargs: Any)[source]¶ Same argument as
Checkpointer.save(). Use this method to manually save checkpoints outside the schedule.- Parameters
name (str) – file name.
kwargs (Any) – extra data to save, same as in
Checkpointer.save().
-
-
class
cvpods.checkpoint.checkpoint.DefaultCheckpointer(model, save_dir='', resume=False, *, save_to_disk=None, **checkpointables)[source]¶ Bases:
cvpods.checkpoint.checkpoint.CheckpointerSame as
Checkpointer, but is able to handle models in detectron & cvpods model zoo, and apply conversions for legacy models.-
__init__(model, save_dir='', resume=False, *, save_to_disk=None, **checkpointables)[source]¶ - Parameters
model (nn.Module) – model.
save_dir (str) – a directory to save and find checkpoints.
resume (bool) – indicate whether to resume from latest checkpoint or start from scratch.
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).
-