Updates will be applied - 3:30pm EDT (UTC -500). No downtime expected.

Commit da1a186e authored by Jon Crall's avatar Jon Crall

Fix bug in when categories are null.

parent 2cfc4a56
Pipeline #171307 passed with stages
in 6 minutes and 50 seconds
......@@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## Version 0.6.3 - Unreleased
### Fixed
* Fix bug in `Detections.from_coco_annots` when categories are null.
## Version 0.6.2 - Released 2020-05-01
......
......@@ -649,6 +649,23 @@ class Detections(ub.NiceRepr, _DetAlgoMixin, _DetDrawMixin):
>>> cats = dataset['categories']
>>> dets = Detections.from_coco_annots(anns, cats)
Example:
>>> # xdoctest: +REQUIRES(--module:ndsampler)
>>> # Test case with no category information
>>> from kwimage.structs.detections import * # NOQA
>>> anns = [{
>>> 'id': 0,
>>> 'image_id': 1,
>>> 'category_id': None,
>>> 'bbox': [2, 3, 10, 10],
>>> 'prob': [.1, .9],
>>> }]
>>> cats = [
>>> {'id': 0, 'name': 'background'},
>>> {'id': 2, 'name': 'class1'}
>>> ]
>>> dets = Detections.from_coco_annots(anns, cats)
Example:
>>> import kwimage
>>> # xdoctest: +REQUIRES(--module:ndsampler)
......@@ -692,11 +709,16 @@ class Detections(ub.NiceRepr, _DetAlgoMixin, _DetDrawMixin):
if cnames is None:
cids = [ann['category_id'] for ann in anns]
cid_to_cat = {c['id']: c for c in cats} # Hack
cnames = [cid_to_cat[cid]['name'] for cid in cids]
cnames = [None if cid is None else cid_to_cat[cid]['name']
for cid in cids]
xywh = np.array([ann['bbox'] for ann in anns], dtype=np.float32)
boxes = kwimage.Boxes(xywh, 'xywh')
class_idxs = [classes.index(cname) for cname in cnames]
try:
class_idxs = [classes.index(cname) for cname in cnames]
except ValueError:
class_idxs = [None if cname is None else classes.index(cname)
for cname in cnames]
dets = Detections(
boxes=boxes,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment