Skip to content

Commit 2f147a6

Browse files
committed
Segmentation Prediction Class
1 parent b5da8d1 commit 2f147a6

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

nucleus/prediction.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from typing import Dict, Optional, List, Any
2-
from .annotation import BoxAnnotation, PolygonAnnotation
2+
from .annotation import (
3+
BoxAnnotation,
4+
PolygonAnnotation,
5+
Segment,
6+
SegmentationAnnotation,
7+
)
38
from .constants import (
49
ANNOTATION_ID_KEY,
510
DATASET_ITEM_ID_KEY,
@@ -13,9 +18,30 @@
1318
HEIGHT_KEY,
1419
CONFIDENCE_KEY,
1520
VERTICES_KEY,
21+
ANNOTATIONS_KEY,
22+
ITEM_ID_KEY,
23+
MASK_URL_KEY,
1624
)
1725

1826

27+
class SegmentationPrediction(SegmentationAnnotation):
28+
@classmethod
29+
def from_json(cls, payload: dict):
30+
return cls(
31+
mask_url=payload[MASK_URL_KEY],
32+
annotations=[
33+
Segment.from_json(ann)
34+
for ann in payload.get(ANNOTATIONS_KEY, [])
35+
],
36+
reference_id=payload.get(REFERENCE_ID_KEY, None),
37+
item_id=payload.get(ITEM_ID_KEY, None),
38+
)
39+
40+
def to_payload(self) -> dict:
41+
payload = super().to_payload()
42+
return payload
43+
44+
1945
class BoxPrediction(BoxAnnotation):
2046
def __init__(
2147
self,
@@ -31,7 +57,15 @@ def __init__(
3157
metadata: Optional[Dict] = None,
3258
):
3359
super().__init__(
34-
label, x, y, width, height, reference_id, item_id, annotation_id, metadata
60+
label,
61+
x,
62+
y,
63+
width,
64+
height,
65+
reference_id,
66+
item_id,
67+
annotation_id,
68+
metadata,
3569
)
3670
self.confidence = confidence
3771

@@ -73,7 +107,9 @@ def __init__(
73107
annotation_id: Optional[str] = None,
74108
metadata: Optional[Dict] = None,
75109
):
76-
super().__init__(label, vertices, reference_id, item_id, annotation_id, metadata)
110+
super().__init__(
111+
label, vertices, reference_id, item_id, annotation_id, metadata
112+
)
77113
self.confidence = confidence
78114

79115
def to_payload(self) -> dict:

0 commit comments

Comments
 (0)