kwcoco.cli.coco_info module¶
- class kwcoco.cli.coco_info.CocoFileHelper(fpath, mode='r')[source]¶
Bases:
objectTransparent opening of either a regular json file, or a json file inside of a zipfile. TODO: relate to ub.zopen?
- class kwcoco.cli.coco_info.CocoInfoCLI(*args, **kwargs)[source]¶
Bases:
DataConfigPrint the first few rows from specified tables. Tries to avoid reading the entire file.
This is named info because originally it just parsed the “info” section of the coco json and print it. But it can parse all the tables.
This is done using ijson, so it doesn’t have to read the entire file. This is useful when you quickly want to take a peek at a larger kwcoco file.
Note: there are issues with this tool when the sections are not in the expected order, or if the requested sections are empty. Help wanted.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- classmethod main(argv=True, **kwargs)[source]¶
Example
>>> # xdoctest: +REQUIRES(module:ijson) >>> from kwcoco.cli.coco_info import * # NOQA >>> import kwcoco >>> cls = CocoInfoCLI >>> argv = 0 >>> dset = kwcoco.CocoDataset.demo('vidshapes8') >>> # Add some info to the data section >>> dset.dataset['info'] = [{'type': 'demo', 'data': 'hi mom'}] >>> dset.fpath = ub.Path(dset.fpath).augment(prefix='infotest_') >>> dset.dump() >>> # test normal json >>> kwargs = dict(src=dset.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs) >>> # test zipped json >>> dset_zip = dset.copy() >>> dset_zip.fpath = dset_zip.fpath + '.zip' >>> dset_zip.dump() >>> kwargs = dict(src=dset_zip.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs) >>> # test bad-order json >>> dset_bad_order = dset.copy() >>> dset_bad_order.dataset['images'] = dset_bad_order.dataset.pop('images') >>> dset_bad_order.dataset['info'] = dset_bad_order.dataset.pop('info') >>> dset_bad_order.fpath = ub.Path(dset_bad_order.fpath).augment(prefix='bad_order') >>> dset_bad_order.dump() >>> kwargs = dict(src=dset_bad_order.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs)
Example
>>> # xdoctest: +REQUIRES(module:ijson) >>> # Test for non-compliant json >>> from kwcoco.cli.coco_info import * # NOQA >>> import kwcoco >>> cls = CocoInfoCLI >>> argv = 0 >>> dset = kwcoco.CocoDataset() >>> dset.dataset['info'].append({'type': 'demo', 'data': None}) >>> kwargs = dict(src=dset, show_info=True) >>> cls.main(argv=argv, **kwargs)
- default = {'image_name': <Value(None)>, 'rich': <Value(True)>, 'show_annotations': <Value(0)>, 'show_categories': <Value(0)>, 'show_images': <Value(0)>, 'show_info': <Value('auto')>, 'show_licenses': <Value(0)>, 'show_tracks': <Value(0)>, 'show_videos': <Value(0)>, 'src': <Value(None)>, 'verbose': <Value(0)>}¶
- kwcoco.cli.coco_info.main(argv=True, **kwargs)¶
Example
>>> # xdoctest: +REQUIRES(module:ijson) >>> from kwcoco.cli.coco_info import * # NOQA >>> import kwcoco >>> cls = CocoInfoCLI >>> argv = 0 >>> dset = kwcoco.CocoDataset.demo('vidshapes8') >>> # Add some info to the data section >>> dset.dataset['info'] = [{'type': 'demo', 'data': 'hi mom'}] >>> dset.fpath = ub.Path(dset.fpath).augment(prefix='infotest_') >>> dset.dump() >>> # test normal json >>> kwargs = dict(src=dset.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs) >>> # test zipped json >>> dset_zip = dset.copy() >>> dset_zip.fpath = dset_zip.fpath + '.zip' >>> dset_zip.dump() >>> kwargs = dict(src=dset_zip.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs) >>> # test bad-order json >>> dset_bad_order = dset.copy() >>> dset_bad_order.dataset['images'] = dset_bad_order.dataset.pop('images') >>> dset_bad_order.dataset['info'] = dset_bad_order.dataset.pop('info') >>> dset_bad_order.fpath = ub.Path(dset_bad_order.fpath).augment(prefix='bad_order') >>> dset_bad_order.dump() >>> kwargs = dict(src=dset_bad_order.fpath, show_images=True, show_videos=True, show_annotations=True) >>> cls.main(argv=argv, **kwargs)
Example
>>> # xdoctest: +REQUIRES(module:ijson) >>> # Test for non-compliant json >>> from kwcoco.cli.coco_info import * # NOQA >>> import kwcoco >>> cls = CocoInfoCLI >>> argv = 0 >>> dset = kwcoco.CocoDataset() >>> dset.dataset['info'].append({'type': 'demo', 'data': None}) >>> kwargs = dict(src=dset, show_info=True) >>> cls.main(argv=argv, **kwargs)