From 0ee29f762c9eac30bf48e2e89ae98d9f809e11c9 Mon Sep 17 00:00:00 2001 From: zhiltsov-max Date: Fri, 22 May 2020 15:47:06 +0300 Subject: [PATCH] [Datumaro] Fix mask to polygons warning (#1581) * Fix message, add test * update changelog --- CHANGELOG.md | 1 + datumaro/datumaro/plugins/transforms.py | 2 +- datumaro/tests/test_transforms.py | 28 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8877ab6b095d..270f341b638d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - diff --git a/datumaro/datumaro/plugins/transforms.py b/datumaro/datumaro/plugins/transforms.py index 17f0b2a08fda..d37e284a9853 100644 --- a/datumaro/datumaro/plugins/transforms.py +++ b/datumaro/datumaro/plugins/transforms.py @@ -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) diff --git a/datumaro/tests/test_transforms.py b/datumaro/tests/test_transforms.py index 58c677a275dd..522cf2b520f0 100644 --- a/datumaro/tests/test_transforms.py +++ b/datumaro/tests/test_transforms.py @@ -1,3 +1,4 @@ +import logging as log import numpy as np from unittest import TestCase @@ -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):