1
1
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
+ )
3
8
from .constants import (
4
9
ANNOTATION_ID_KEY ,
5
10
DATASET_ITEM_ID_KEY ,
13
18
HEIGHT_KEY ,
14
19
CONFIDENCE_KEY ,
15
20
VERTICES_KEY ,
21
+ ANNOTATIONS_KEY ,
22
+ ITEM_ID_KEY ,
23
+ MASK_URL_KEY ,
16
24
)
17
25
18
26
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
+
19
45
class BoxPrediction (BoxAnnotation ):
20
46
def __init__ (
21
47
self ,
@@ -31,7 +57,15 @@ def __init__(
31
57
metadata : Optional [Dict ] = None ,
32
58
):
33
59
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 ,
35
69
)
36
70
self .confidence = confidence
37
71
@@ -73,7 +107,9 @@ def __init__(
73
107
annotation_id : Optional [str ] = None ,
74
108
metadata : Optional [Dict ] = None ,
75
109
):
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
+ )
77
113
self .confidence = confidence
78
114
79
115
def to_payload (self ) -> dict :
0 commit comments