diff --git a/CHANGELOG.md b/CHANGELOG.md index 99de8a72..870bd7ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ### Changed -- +- Shape coordinates are rounded to 2 digits in dumped annotations () +- COCO format does not produce polygon points for bbox annotations () ### Deprecated - diff --git a/datumaro/datumaro/components/extractor.py b/datumaro/datumaro/components/extractor.py index ae0c1fae..1df3c287 100644 --- a/datumaro/datumaro/components/extractor.py +++ b/datumaro/datumaro/components/extractor.py @@ -20,6 +20,9 @@ AnnotationType = Enum('AnnotationType', 'caption', ]) +_COORDINATE_ROUNDING_DIGITS = 2 + + class Annotation: # pylint: disable=redefined-builtin def __init__(self, id=None, type=None, attributes=None, group=None): @@ -378,9 +381,9 @@ class _Shape(Annotation): id=None, attributes=None, group=None): super().__init__(id=id, type=type, attributes=attributes, group=group) - if points is None: - points = [] - self._points = list(points) + if points is not None: + points = [round(p, _COORDINATE_ROUNDING_DIGITS) for p in points] + self._points = points if label is not None: label = int(label) @@ -460,8 +463,8 @@ class Polygon(_Shape): def get_area(self): import pycocotools.mask as mask_utils - _, _, w, h = self.get_bbox() - rle = mask_utils.frPyObjects([self.points], h, w) + x, y, w, h = self.get_bbox() + rle = mask_utils.frPyObjects([self.points], y + h, x + w) area = mask_utils.area(rle)[0] return area diff --git a/datumaro/datumaro/plugins/coco_format/converter.py b/datumaro/datumaro/plugins/coco_format/converter.py index 478e6599..392f0261 100644 --- a/datumaro/datumaro/plugins/coco_format/converter.py +++ b/datumaro/datumaro/plugins/coco_format/converter.py @@ -15,13 +15,12 @@ import pycocotools.mask as mask_utils import datumaro.util.annotation_tools as anno_tools import datumaro.util.mask_tools as mask_tools from datumaro.components.converter import Converter -from datumaro.components.extractor import (DEFAULT_SUBSET_NAME, AnnotationType, - Points) +from datumaro.components.extractor import (_COORDINATE_ROUNDING_DIGITS, + DEFAULT_SUBSET_NAME, AnnotationType, Points) from datumaro.util import cast, find, str_to_bool from .format import CocoPath, CocoTask - SegmentationMode = Enum('SegmentationMode', ['guess', 'polygons', 'mask']) class _TaskConverter: @@ -308,7 +307,7 @@ class _InstancesConverter(_TaskConverter): 'category_id': cast(ann.label, int, -1) + 1, 'segmentation': segmentation, 'area': float(area), - 'bbox': list(map(float, bbox)), + 'bbox': [round(float(n), _COORDINATE_ROUNDING_DIGITS) for n in bbox], 'iscrowd': int(is_crowd), } if 'score' in ann.attributes: @@ -336,7 +335,6 @@ class _KeypointsConverter(_InstancesConverter): 'supercategory': cast(label_cat.parent, str, ''), 'keypoints': [], 'skeleton': [], - } if point_categories is not None: