kwcoco.cli.coco_reroot module

class kwcoco.cli.coco_reroot.CocoRerootCLI(*args, **kwargs)[source]

Bases: DataConfig

Reroot image paths onto a new image root.

Modify the root of a coco dataset such to either make paths relative to a new root or make paths absolute.

Note

  • This script still has issues, and may change behavior in the future. As a workaround reroot to the same bundle directory first with absolute=True to ensure that paths resolve, and then reroot to the target location.

Todo

  • [ ] Evaluate that all tests cases work

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

classmethod main(cmdline=True, **kw)[source]

CommandLine

xdoctest -m kwcoco.cli.coco_reroot CocoRerootCLI.main:0

Example

>>> from kwcoco.cli.coco_reroot import *  # NOQA
>>> import kwcoco
>>> import ubelt as ub
>>> dpath = ub.Path.appdir('kwcoco/tests/coco_reroot').ensuredir()
>>> old_dset = kwcoco.CocoDataset.demo('special:shapes8')
>>> dst_fpath = dpath / 'reroot_output.kwcoco.zip'
>>> kw = {'src': old_dset.fpath, 'dst': dst_fpath, 'absolute': False}
>>> cmdline = False
>>> cls = CocoRerootCLI
>>> cls.main(cmdline=cmdline, **kw)
>>> assert dst_fpath.exists()
>>> new_dset = kwcoco.CocoDataset(dst_fpath)
>>> assert new_dset.dataset != old_dset.dataset
>>> gpath1 = new_dset.coco_image(1).primary_image_filepath()
>>> gpath2 = old_dset.coco_image(1).primary_image_filepath()
>>> assert gpath1.samefile(gpath2)

Example

>>> # xdoctest: +SKIP
>>> kw = {'src': 'special:shapes8'}
>>> cmdline = False
>>> cls = CocoRerootCLI
>>> cls.main(cmdline, **kw)
default = {'absolute': <Value(True)>, 'autofix': <Value(False)>, 'check': <Value(True)>, 'compress': <Value('auto')>, 'dst': <Value(None)>, 'inplace': <Value(False)>, 'new_prefix': <Value(None)>, 'old_prefix': <Value(None)>, 'src': <Value(None)>}
kwcoco.cli.coco_reroot.find_reroot_autofix(dset)[source]
kwcoco.cli.coco_reroot._check_candidates(candidate, bundle_dpath, missing_gpaths, fastfail=True)[source]