Skip to content

Commit

Permalink
[Datumaro] Fix mask to polygons warning (#1581)
Browse files Browse the repository at this point in the history
* Fix message, add test
* update changelog
  • Loading branch information
zhiltsov-max authored May 22, 2020
1 parent 2d1b73c commit 42c5637
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed full COCO dataset import error with conflicting labels in keypoints and detection (https://github.com/opencv/cvat/pull/1548)
- Fixed COCO keypoints skeleton parsing and saving (https://github.com/opencv/cvat/issues/1539)
- `tf.placeholder() is not compatible with eager execution` exception for auto_segmentation (https://github.com/opencv/cvat/pull/1562)
- Fixed a problem with mask to polygons conversion when polygons are too small (https://github.com/opencv/cvat/pull/1581)

### Security
-
Expand Down
2 changes: 1 addition & 1 deletion datumaro/datumaro/plugins/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def transform_item(self, item):
log.debug("[%s]: item %s: "
"Mask conversion to polygons resulted in too "
"small polygons, which were discarded" % \
(self.NAME, item.id))
(self._get_name(__class__), item.id))
annotations.extend(polygons)
else:
annotations.append(ann)
Expand Down
28 changes: 28 additions & 0 deletions datumaro/tests/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging as log
import numpy as np

from unittest import TestCase
Expand Down Expand Up @@ -65,6 +66,33 @@ def __iter__(self):
actual = transforms.MasksToPolygons(SrcExtractor())
compare_datasets(self, DstExtractor(), actual)

def test_mask_to_polygons_small_polygons_message(self):
class SrcExtractor(Extractor):
def __iter__(self):
items = [
DatasetItem(id=1, image=np.zeros((5, 10, 3)),
annotations=[
Mask(np.array([
[0, 0, 0],
[0, 1, 0],
[0, 0, 0],
]),
),
]
),
]
return iter(items)

class DstExtractor(Extractor):
def __iter__(self):
return iter([ DatasetItem(id=1, image=np.zeros((5, 10, 3))), ])

with self.assertLogs(level=log.DEBUG) as logs:
actual = transforms.MasksToPolygons(SrcExtractor())

compare_datasets(self, DstExtractor(), actual)
self.assertRegex('\n'.join(logs.output), 'too small polygons')

def test_polygons_to_masks(self):
class SrcExtractor(Extractor):
def __iter__(self):
Expand Down

0 comments on commit 42c5637

Please sign in to comment.