Skip to content

Commit c3541ba

Browse files
yunchusovrasoveugene123tw
authored
Mergeback 1.4.0 to 1.5.0 (#2826)
* Update MAPI version (#2730) * Update dependency for exportable code (#2732) * Filter invalid polygon shapes (#2795) --------- Co-authored-by: Vladislav Sovrasov <sovrasov.vlad@gmail.com> Co-authored-by: Eugene Liu <eugene.liu@intel.com>
1 parent 251eb42 commit c3541ba

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/otx/core/data/adapter/base_dataset_adapter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,16 @@ def _prepare_label_information(
272272

273273
return {"category_items": category_items, "label_groups": label_groups, "label_entities": label_entities}
274274

275-
def _is_normal_polygon(self, annotation: DatumAnnotationType.polygon) -> bool:
275+
def _is_normal_polygon(self, annotation: DatumAnnotationType.polygon, width: int, height: int) -> bool:
276276
"""To filter out the abnormal polygon."""
277-
x_points = [annotation.points[i] for i in range(0, len(annotation.points), 2)]
278-
y_points = [annotation.points[i + 1] for i in range(0, len(annotation.points), 2)]
279-
return min(x_points) < max(x_points) and min(y_points) < max(y_points)
277+
x_points = annotation.points[::2] # Extract x-coordinates
278+
y_points = annotation.points[1::2] # Extract y-coordinates
279+
280+
return (
281+
min(x_points) < max(x_points) < width
282+
and min(y_points) < max(y_points) < height
283+
and annotation.get_area() > 0
284+
)
280285

281286
def _is_normal_bbox(self, x1: float, y1: float, x2: float, y2: float) -> bool:
282287
"""To filter out the abrnormal bbox."""

src/otx/core/data/adapter/detection_dataset_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_otx_dataset(self) -> DatasetEntity:
4141
self.task_type in (TaskType.INSTANCE_SEGMENTATION, TaskType.ROTATED_DETECTION)
4242
and ann.type == DatumAnnotationType.polygon
4343
):
44-
if self._is_normal_polygon(ann):
44+
if self._is_normal_polygon(ann, image.width, image.height):
4545
shapes.append(self._get_polygon_entity(ann, image.width, image.height))
4646
if self.task_type is TaskType.DETECTION and ann.type == DatumAnnotationType.bbox:
4747
if self._is_normal_bbox(ann.points[0], ann.points[1], ann.points[2], ann.points[3]):

src/otx/core/data/adapter/visual_prompting_dataset_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_otx_dataset(self) -> DatasetEntity:
5353
for ann in datumaro_item.annotations:
5454
if ann.type == DatumAnnotationType.polygon:
5555
# save polygons as-is, they will be converted to masks.
56-
if self._is_normal_polygon(ann):
56+
if self._is_normal_polygon(ann, image.width, image.height):
5757
shapes.append(self._get_polygon_entity(ann, image.width, image.height))
5858

5959
if ann.type == DatumAnnotationType.mask:

tests/unit/algorithms/segmentation/adapters/mmseg/datasets/pipelines/test_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class TestNormalize:
110110
@pytest.mark.parametrize(
111111
"mean,std,to_rgb,expected",
112112
[
113-
(1.0, 1.0, True, np.array([[[1.0, 0.0, 0.0]]], dtype=np.float32)),
114-
(1.0, 1.0, False, np.array([[[-1.0, 0.0, 0.0]]], dtype=np.float32)),
113+
([[[1.0, 1.0, 1.0]]], [[[1.0, 1.0, 1.0]]], True, np.array([[[1.0, 0.0, -1.0]]], dtype=np.float32)),
114+
([[[1.0, 1.0, 1.0]]], [[[1.0, 1.0, 1.0]]], False, np.array([[[-1.0, 0.0, 1.0]]], dtype=np.float32)),
115115
],
116116
)
117117
def test_call(self, mean: float, std: float, to_rgb: bool, expected: np.array) -> None:

0 commit comments

Comments
 (0)