Skip to content

Commit

Permalink
Fix COCO Panoptic (cvat-ai#319)
Browse files Browse the repository at this point in the history
* add test

* Fix integer overflow in bgr2index
  • Loading branch information
Kirill Sizov authored Jul 5, 2021
1 parent 37b8cb0 commit f955177
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions datumaro/util/mask_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def make_binary_mask(mask):
return mask.astype(bool)

def bgr2index(img):
if img.dtype.kind not in {'b', 'i', 'u'}:
img = img.astype(np.uint8)
if img.dtype.kind not in {'b', 'i', 'u'} or img.dtype.itemsize < 4:
img = img.astype(np.uint32)
return (img[..., 0] << 16) + (img[..., 1] << 8) + img[..., 2]

def index2bgr(id_map):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"file_name":"a.png",
"segments_info":[
{
"id":7,
"id":460551,
"category_id":1,
"area":20.0,
"bbox":[
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions tests/test_coco_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ def test_can_import_panoptic(self):
DatasetItem(id='a', subset='train', image=np.ones((5, 10, 3)),
attributes={'id': 5},
annotations=[
Mask(np.array(
[[0, 0, 1, 1, 0, 1, 1, 0, 0, 0]] * 5
), label=0,
id=7, group=7, attributes={'is_crowd': False}),
Mask(np.ones((5, 5)), label=0, id=460551,
group=460551, attributes={'is_crowd': False}),
]),

DatasetItem(id='b', subset='val', image=np.ones((10, 5, 3)),
Expand Down

0 comments on commit f955177

Please sign in to comment.