geowatch.cli.experimental.unpack_model module

Todo

  • [ ] Add relevant documentation to point at

    ~/code/geowatch/geowatch/mlops/repackager.py so it is easy for the user to unpack / repack models.

class geowatch.cli.experimental.unpack_model.UnpackModelCLI(*args, **kwargs)[source]

Bases: DataConfig

Unpack the core components of a torch package to make them suitable for environment-agnostic use or repackaging.

SeeAlso

python -m geowatch/mlops/repackager

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
>>> from geowatch.cli.experimental.unpack_model import *  # NOQA
>>> cmdline = 0
>>> kwargs = dict()
>>> kwargs['fpath'] = '/data/joncrall/dvc-repos/smart_phase3_expt/models/fusion/Drop8-ARA-Cropped2GSD-V1/packages/Drop8-ARA-Cropped2GSD-V1_allsensors_V001/Drop8-ARA-Cropped2GSD-V1_allsensors_V001_epoch0_step21021.pt'
>>> cls = UnpackModelCLI
>>> cls.main(cmdline=cmdline, **kwargs)
default = {'dst_dpath': <Value(None)>, 'fpath': <Value(None)>}
geowatch.cli.experimental.unpack_model.unpack_model(package_fpath, dst_dpath=None)[source]

Extracts and writes extracted files to disk.

Returns:

mapping from keys to written paths on disk

Return type:

Dict[str, ub.Path]

Example

>>> import ubelt as ub
>>> from geowatch.tasks.fusion.methods.channelwise_transformer import *  # NOQA
>>> dpath = ub.Path.appdir('geowatch/tests/package').ensuredir()
>>> package_fpath = dpath / 'my_package.pt'
>>> dst_dpath = dpath / 'unpacked_packages'
>>> if not package_fpath.exists():
>>>     # Use one of our fusion.architectures in a test
>>>     from geowatch.tasks.fusion import methods
>>>     from geowatch.tasks.fusion import datamodules
>>>     model = self = methods.MultimodalTransformer(
>>>         arch_name="smt_it_joint_p2", input_sensorchan=5,
>>>         change_head_hidden=0, saliency_head_hidden=0,
>>>         class_head_hidden=0)
>>>     # Save the model (TODO: need to save datamodule as well)
>>>     model.save_package(package_fpath)
>>> results = unpack_model(package_fpath)
>>> # Test repackage
>>> from geowatch.mlops.repackager import repackage_single_checkpoint
>>> repackage_single_checkpoint
geowatch.cli.experimental.unpack_model.extract_package_contents(package_fpath)[source]
Returns:

dict