Skip to content

Commit d581fa9

Browse files
committed
PR comments
1 parent 4f97552 commit d581fa9

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

nucleus/metrics/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MetricResult:
2121
"""
2222

2323
value: float
24-
weight: float = 1
24+
weight: float = 1.0
2525

2626
@staticmethod
2727
def aggregate(results: Iterable["MetricResult"]) -> "MetricResult":

nucleus/metrics/filters.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,8 @@ def confidence_filter(
2424
lambda prediction: not hasattr(prediction, "confidence")
2525
or prediction.confidence >= min_confidence
2626
)
27-
predictions_copy.box_predictions = list(
28-
filter(filter_fn, predictions.box_predictions)
29-
)
30-
predictions_copy.polygon_predictions = list(
31-
filter(filter_fn, predictions.polygon_predictions)
32-
)
33-
predictions_copy.cuboid_predictions = list(
34-
filter(filter_fn, predictions.cuboid_predictions)
35-
)
36-
predictions_copy.category_predictions = list(
37-
filter(filter_fn, predictions.category_predictions)
38-
)
39-
predictions_copy.segmentation_predictions = list(
40-
filter(filter_fn, predictions.segmentation_predictions)
41-
)
27+
for attr in predictions.__dict__:
28+
predictions_copy.__dict__[attr] = list(
29+
filter(filter_fn, predictions.__dict__[attr])
30+
)
4231
return predictions_copy

nucleus/metrics/polygon_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22
from abc import abstractmethod
3-
from typing import List
3+
from typing import List, Union
44

5-
from nucleus.annotation import AnnotationList
6-
from nucleus.prediction import PredictionList
5+
from nucleus.annotation import AnnotationList, BoxAnnotation, PolygonAnnotation
6+
from nucleus.prediction import BoxPrediction, PolygonPrediction, PredictionList
77

88
from .base import Metric, MetricResult
99
from .filters import confidence_filter
@@ -90,10 +90,10 @@ def __call__(
9090
predictions = confidence_filter(
9191
predictions, self.confidence_threshold
9292
)
93-
polygon_annotations: List[BoxOrPolygonAnnotation] = []
93+
polygon_annotations: List[Union[BoxAnnotation, PolygonAnnotation]] = []
9494
polygon_annotations.extend(annotations.box_annotations)
9595
polygon_annotations.extend(annotations.polygon_annotations)
96-
polygon_predictions: List[BoxOrPolygonAnnotation] = []
96+
polygon_predictions: List[Union[BoxPrediction, PolygonPrediction]] = []
9797
polygon_predictions.extend(predictions.box_predictions)
9898
polygon_predictions.extend(predictions.polygon_predictions)
9999

nucleus/metrics/polygon_utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from functools import wraps
3-
from typing import Dict, List, Tuple, Union
3+
from typing import Dict, List, Tuple, TypeVar
44

55
import numpy as np
66
from scipy.optimize import linear_sum_assignment
@@ -12,10 +12,12 @@
1212
from .base import MetricResult
1313
from .errors import PolygonAnnotationTypeError
1414

15-
BoxOrPolygonPrediction = Union[BoxPrediction, PolygonPrediction]
16-
BoxOrPolygonAnnotation = Union[
17-
BoxAnnotation, PolygonAnnotation, BoxOrPolygonPrediction
18-
]
15+
BoxOrPolygonPrediction = TypeVar(
16+
"BoxOrPolygonPrediction", BoxPrediction, PolygonPrediction
17+
)
18+
BoxOrPolygonAnnotation = TypeVar(
19+
"BoxOrPolygonAnnotation", BoxAnnotation, PolygonAnnotation
20+
)
1921

2022

2123
def polygon_annotation_to_shape(

0 commit comments

Comments
 (0)