geowatch.cli.experimental.find_recent_checkpoint module¶
- class geowatch.cli.experimental.find_recent_checkpoint.FindRecentCheckpointCLI(*args, **kwargs)[source]¶
Bases:
DataConfig
Helper script to lookup the most recent checkpoint.
Not sure what the best home for this script is. Useful to help make train scripts more consise. Perhaps this is part of the mlops CLI?
Usage¶
This prints out extra arguments to be used at the end of a lightning CLI invocation. As such, you should ensure its contents are read into a bash array, and that array should be passed to the invocation such that any bash-level word splitting is explicit.
In short this is the following pattern that should be used
PREV_CHECKPOINT_TEXT=$(python -m geowatch.cli.experimental.find_recent_checkpoint --default_root_dir="$DEFAULT_ROOT_DIR") echo "PREV_CHECKPOINT_TEXT = $PREV_CHECKPOINT_TEXT" if [[ "$PREV_CHECKPOINT_TEXT" == "None" ]]; then PREV_CHECKPOINT_ARGS=() else PREV_CHECKPOINT_ARGS=(--ckpt_path "$PREV_CHECKPOINT_TEXT") fi echo "${PREV_CHECKPOINT_ARGS[@]}"
This method of usage will do nothing when there is no checkpoint, and add the appropriate restart argument when something is needed.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- classmethod main(cmdline=1, **kwargs)[source]¶
Example
>>> # xdoctest: +SKIP >>> import ubelt as ub >>> from geowatch.cli.experimental.find_recent_checkpoint import * # NOQA >>> cmdline = 0 >>> # Make a dummy train directory >>> default_root_dir = ub.Path.appdir('geowatch/tests/find_recent_checkpoint') >>> fake_dpath = (default_root_dir / 'lightning_logs/version_0/checkpoints').ensuredir() >>> (fake_dpath / 'pretend.ckpt').write_text('dummy') >>> kwargs = dict(default_root_dir=default_root_dir) >>> cls = FindRecentCheckpointCLI >>> cls.main(cmdline=cmdline, **kwargs) >>> kwargs['as_cli_arg'] = True >>> cls.main(cmdline=cmdline, **kwargs)
- default = {'allow_last': <Value(True)>, 'as_cli_arg': <Value(False)>, 'default_root_dir': <Value(None)>}¶
- geowatch.cli.experimental.find_recent_checkpoint.main(cmdline=1, **kwargs)¶
Example
>>> # xdoctest: +SKIP >>> import ubelt as ub >>> from geowatch.cli.experimental.find_recent_checkpoint import * # NOQA >>> cmdline = 0 >>> # Make a dummy train directory >>> default_root_dir = ub.Path.appdir('geowatch/tests/find_recent_checkpoint') >>> fake_dpath = (default_root_dir / 'lightning_logs/version_0/checkpoints').ensuredir() >>> (fake_dpath / 'pretend.ckpt').write_text('dummy') >>> kwargs = dict(default_root_dir=default_root_dir) >>> cls = FindRecentCheckpointCLI >>> cls.main(cmdline=cmdline, **kwargs) >>> kwargs['as_cli_arg'] = True >>> cls.main(cmdline=cmdline, **kwargs)