kwcoco.cli.coco_fixup module

class kwcoco.cli.coco_fixup.CocoFixup(*args, **kwargs)[source]

Bases: DataConfig

Valid options: []

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

  • **kwargs – keyword arguments for this data config

classmethod main(cmdline=1, **kwargs)[source]

CommandLine

xdoctest -m kwcoco.cli.coco_fixup CocoFixup.main

Example

>>> from kwcoco.cli.coco_fixup import *  # NOQA
>>> import kwcoco
>>> import ubelt as ub
>>> dpath = ub.Path.appdir('kwcoco/tests/coco_fixup')
>>> dpath.delete().ensuredir()
>>> src_dset = kwcoco.CocoDataset.demo('vidshapes2', image_size=(64, 64), rng=0, dpath=dpath)
>>> fpath1 = src_dset.coco_image(1).primary_image_filepath()
>>> fpath2 = src_dset.coco_image(2).primary_image_filepath()
>>> fpath1.delete()  # remove an asset
>>> fpath2.write_bytes(fpath2.read_bytes()[0::2])  # corrupt an asset
>>> src = ub.Path(src_dset.fpath)
>>> print(f'src_dset={src_dset}')
>>> dst = src.augment(prefix='fixed-')
>>> kwargs = dict(src=src, dst=dst)
>>> cmdline = 0
>>> cls = CocoFixup
>>> cls.main(cmdline=cmdline, **kwargs)
>>> assert dst.exists()
>>> dst_dset = kwcoco.CocoDataset(dst)
>>> print(f'dst_dset={dst_dset}')
>>> assert dst_dset.n_images < src_dset.n_images
>>> assert dst_dset.n_videos < src_dset.n_videos
default = {'corrupted_assets': <Value(True)>, 'dst': <Value(None)>, 'inplace': <Value(False)>, 'missing_assets': <Value(True)>, 'src': <Value(None)>, 'workers': <Value(0)>}
kwcoco.cli.coco_fixup.find_corrupted_assets(dset, check_aux=True, workers=0, corrupted_assets='full')[source]
kwcoco.cli.coco_fixup.find_and_remove_corrupted_assets(dset, check_aux=True, workers=0, corrupted_assets='full')[source]
kwcoco.cli.coco_fixup.coco_img_remove_empty_assets(coco_img, missing)[source]
kwcoco.cli.coco_fixup.remove_empty_videos(dset)[source]
kwcoco.cli.coco_fixup.remove_missing_assets(dset)[source]

Remove the entire image if no assets remain Handle asset / auxiliary dict

kwcoco.cli.coco_fixup.main(cmdline=1, **kwargs)

CommandLine

xdoctest -m kwcoco.cli.coco_fixup CocoFixup.main

Example

>>> from kwcoco.cli.coco_fixup import *  # NOQA
>>> import kwcoco
>>> import ubelt as ub
>>> dpath = ub.Path.appdir('kwcoco/tests/coco_fixup')
>>> dpath.delete().ensuredir()
>>> src_dset = kwcoco.CocoDataset.demo('vidshapes2', image_size=(64, 64), rng=0, dpath=dpath)
>>> fpath1 = src_dset.coco_image(1).primary_image_filepath()
>>> fpath2 = src_dset.coco_image(2).primary_image_filepath()
>>> fpath1.delete()  # remove an asset
>>> fpath2.write_bytes(fpath2.read_bytes()[0::2])  # corrupt an asset
>>> src = ub.Path(src_dset.fpath)
>>> print(f'src_dset={src_dset}')
>>> dst = src.augment(prefix='fixed-')
>>> kwargs = dict(src=src, dst=dst)
>>> cmdline = 0
>>> cls = CocoFixup
>>> cls.main(cmdline=cmdline, **kwargs)
>>> assert dst.exists()
>>> dst_dset = kwcoco.CocoDataset(dst)
>>> print(f'dst_dset={dst_dset}')
>>> assert dst_dset.n_images < src_dset.n_images
>>> assert dst_dset.n_videos < src_dset.n_videos