kwcoco.coco_schema
¶
CommandLine
python -m kwcoco.coco_schema
xdoctest -m kwcoco.coco_schema __doc__
Example
>>> import kwcoco
>>> from kwcoco.coco_schema import COCO_SCHEMA
>>> import jsonschema
>>> dset = kwcoco.CocoDataset.demo('shapes1')
>>> # print('dset.dataset = {}'.format(ub.repr2(dset.dataset, nl=2)))
>>> COCO_SCHEMA.validate(dset.dataset)
>>> try:
>>> jsonschema.validate(dset.dataset, schema=COCO_SCHEMA)
>>> except jsonschema.exceptions.ValidationError as ex:
>>> vali_ex = ex
>>> print('ex = {!r}'.format(ex))
>>> raise
>>> except jsonschema.exceptions.SchemaError as ex:
>>> print('ex = {!r}'.format(ex))
>>> schema_ex = ex
>>> print('schema_ex.instance = {}'.format(ub.repr2(schema_ex.instance, nl=-1)))
>>> raise
>>> # Test the multispectral image defintino
>>> import copy
>>> dataset = dset.copy().dataset
>>> img = dataset['images'][0]
>>> img.pop('file_name')
>>> import pytest
>>> with pytest.raises(jsonschema.ValidationError):
>>> COCO_SCHEMA.validate(dataset)
>>> import pytest
>>> img['auxiliary'] = [{'file_name': 'foobar'}]
>>> with pytest.raises(jsonschema.ValidationError):
>>> COCO_SCHEMA.validate(dataset)
>>> img['name'] = 'aux-only images must have a name'
>>> COCO_SCHEMA.validate(dataset)
Module Contents¶
Functions¶
|
|
|