Skip to content

Commit 967f252

Browse files
authored
[Validate] Drop invalid polygons for IOU matching (#287)
* Drop invalid polygons for IOU matching * Change log for invalid itemsm * Add CHANGELOG entry
1 parent b4fb2f9 commit 967f252

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.10.5](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.10.5) - 2022-04-26
9+
10+
### Fixed
11+
- Invalid polygons are dropped form PolygonMetric iou matching
12+
813
## [0.10.4](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.10.4)) - 2022-05-02
914

1015
### Added
@@ -15,14 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1520
## [0.10.3](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.10.3) - 2022-04-22
1621

1722
### Fixed
18-
1923
- Polygon and bounding box matching uses Shapely again providing faster evaluations
2024
- Evaluation function passing fixed for Polygon and Boundingbox configurations
2125

2226
## [0.10.1](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.10.1) - 2022-04-21
2327

2428
### Added
25-
2629
- Added check for payload size
2730

2831
## [0.10.0](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.10.0)) - 2022-04-21

nucleus/metrics/polygon_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import sys
23
from functools import wraps
34
from typing import Dict, List, Tuple
@@ -76,6 +77,40 @@ def _iou_assignments_for_same_reference_id(
7677
polygon_annotations = list(map(polygon_annotation_to_shape, annotations))
7778
polygon_predictions = list(map(polygon_annotation_to_shape, predictions))
7879

80+
invalid_anns = [
81+
ann
82+
for ann, poly in zip(annotations, polygon_annotations)
83+
if not poly.is_valid
84+
]
85+
invalid_preds = [
86+
pred
87+
for pred, poly in zip(predictions, polygon_predictions)
88+
if not poly.is_valid
89+
]
90+
91+
if invalid_anns or invalid_preds:
92+
# Filter out invalid polys
93+
polygon_annotations = [
94+
poly
95+
for ann, poly in zip(annotations, polygon_annotations)
96+
if poly.is_valid
97+
]
98+
polygon_predictions = [
99+
poly
100+
for pred, poly in zip(predictions, polygon_predictions)
101+
if poly.is_valid
102+
]
103+
invalid_dataset_ids = set(
104+
ann.reference_id for ann in invalid_anns
105+
).union(set(pred.reference_id for pred in invalid_preds))
106+
# TODO(gunnar): change to .id once field is surfaced)
107+
logging.warning(
108+
"Invalid polygons for dataset items: %s Annotations:%s, predictions: %s",
109+
invalid_dataset_ids,
110+
[a.annotation_id for a in invalid_anns],
111+
[p.annotation_id for p in invalid_preds],
112+
)
113+
79114
# Compute IoU matrix and set IoU values below the threshold to 0.
80115
iou_matrix = _iou_matrix(polygon_annotations, polygon_predictions)
81116
iou_matrix[iou_matrix < iou_threshold] = 0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.10.4"
24+
version = "0.10.5"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)