8
8
TEST_IMG_URLS ,
9
9
TEST_BOX_PREDICTIONS ,
10
10
TEST_POLYGON_PREDICTIONS ,
11
+ TEST_SEGMENTATION_PREDICTIONS ,
11
12
reference_id_from_url ,
12
13
assert_box_prediction_matches_dict ,
13
14
assert_polygon_prediction_matches_dict ,
14
15
)
15
16
16
- from nucleus import BoxPrediction , PolygonPrediction , DatasetItem
17
+ from nucleus import (
18
+ BoxPrediction ,
19
+ PolygonPrediction ,
20
+ SegmentationPrediction ,
21
+ DatasetItem ,
22
+ )
17
23
from nucleus .constants import ERROR_PAYLOAD
18
24
25
+
19
26
@pytest .fixture ()
20
27
def model_run (CLIENT ):
21
28
ds = CLIENT .create_dataset (TEST_DATASET_NAME )
22
29
ds_items = []
23
30
for url in TEST_IMG_URLS :
24
- ds_items .append (DatasetItem (
25
- image_location = url ,
26
- reference_id = reference_id_from_url (url ),
27
- ))
31
+ ds_items .append (
32
+ DatasetItem (
33
+ image_location = url ,
34
+ reference_id = reference_id_from_url (url ),
35
+ )
36
+ )
28
37
29
38
response = ds .append (ds_items )
30
39
assert ERROR_PAYLOAD not in response .json ()
31
40
32
41
model = CLIENT .add_model (
33
- name = TEST_MODEL_NAME ,
34
- reference_id = TEST_MODEL_REFERENCE
42
+ name = TEST_MODEL_NAME , reference_id = TEST_MODEL_REFERENCE
35
43
)
36
44
37
- run = model .create_run (
38
- name = TEST_MODEL_RUN ,
39
- dataset = ds ,
40
- predictions = [])
45
+ run = model .create_run (name = TEST_MODEL_RUN , dataset = ds , predictions = [])
41
46
42
47
yield run
43
48
@@ -46,13 +51,14 @@ def model_run(CLIENT):
46
51
response = CLIENT .delete_model (model .id )
47
52
assert response == {}
48
53
54
+
49
55
def test_box_pred_upload (model_run ):
50
56
prediction = BoxPrediction (** TEST_BOX_PREDICTIONS [0 ])
51
57
response = model_run .predict (annotations = [prediction ])
52
58
53
- assert response [' model_run_id' ] == model_run .model_run_id
54
- assert response [' predictions_processed' ] == 1
55
- assert response [' predictions_ignored' ] == 0
59
+ assert response [" model_run_id" ] == model_run .model_run_id
60
+ assert response [" predictions_processed" ] == 1
61
+ assert response [" predictions_ignored" ] == 0
56
62
57
63
response = model_run .refloc (prediction .reference_id )
58
64
assert len (response ) == 1
@@ -63,31 +69,63 @@ def test_polygon_pred_upload(model_run):
63
69
prediction = PolygonPrediction (** TEST_POLYGON_PREDICTIONS [0 ])
64
70
response = model_run .predict (annotations = [prediction ])
65
71
66
- assert response [' model_run_id' ] == model_run .model_run_id
67
- assert response [' predictions_ignored' ] == 0
68
- assert response [' predictions_ignored' ] == 0
72
+ assert response [" model_run_id" ] == model_run .model_run_id
73
+ assert response [" predictions_ignored" ] == 0
74
+ assert response [" predictions_ignored" ] == 0
69
75
70
76
response = model_run .refloc (prediction .reference_id )
71
77
assert len (response ) == 1
72
- assert_polygon_prediction_matches_dict (response [0 ], TEST_POLYGON_PREDICTIONS [0 ])
78
+ assert_polygon_prediction_matches_dict (
79
+ response [0 ], TEST_POLYGON_PREDICTIONS [0 ]
80
+ )
81
+
82
+
83
+ def test_segmentation_pred_upload (model_run ):
84
+ prediction = SegmentationPrediction .from_json (
85
+ TEST_SEGMENTATION_PREDICTIONS [0 ]
86
+ )
87
+ response = model_run .predict (annotations = [prediction ])
88
+
89
+ assert response ["model_run_id" ] == model_run .model_run_id
90
+ assert response ["predictions_processed" ] == 1
91
+ assert response ["predictions_ignored" ] == 0
92
+
93
+
94
+ def test_segmentation_pred_upload_ignore (model_run ):
95
+ prediction = SegmentationPrediction .from_json (
96
+ TEST_SEGMENTATION_PREDICTIONS [0 ]
97
+ )
98
+ response1 = model_run .predict (annotations = [prediction ])
99
+
100
+ assert response1 ["predictions_processed" ] == 1
101
+
102
+ # Upload Duplicate annotation
103
+ response = model_run .predict (annotations = [prediction ])
104
+ assert response ["model_run_id" ] == model_run .model_run_id
105
+ assert response ["predictions_processed" ] == 0
106
+ assert response ["predictions_ignored" ] == 1
73
107
74
108
75
109
def test_box_pred_upload_update (model_run ):
76
110
prediction = BoxPrediction (** TEST_BOX_PREDICTIONS [0 ])
77
111
response = model_run .predict (annotations = [prediction ])
78
112
79
- assert response [' predictions_processed' ] == 1
113
+ assert response [" predictions_processed" ] == 1
80
114
81
115
# Copy so we don't modify the original.
82
116
prediction_update_params = dict (TEST_BOX_PREDICTIONS [1 ])
83
- prediction_update_params ['annotation_id' ] = TEST_BOX_PREDICTIONS [0 ]['annotation_id' ]
84
- prediction_update_params ['reference_id' ] = TEST_BOX_PREDICTIONS [0 ]['reference_id' ]
117
+ prediction_update_params ["annotation_id" ] = TEST_BOX_PREDICTIONS [0 ][
118
+ "annotation_id"
119
+ ]
120
+ prediction_update_params ["reference_id" ] = TEST_BOX_PREDICTIONS [0 ][
121
+ "reference_id"
122
+ ]
85
123
86
124
prediction_update = BoxPrediction (** prediction_update_params )
87
125
response = model_run .predict (annotations = [prediction_update ], update = True )
88
126
89
- assert response [' predictions_processed' ] == 1
90
- assert response [' predictions_ignored' ] == 0
127
+ assert response [" predictions_processed" ] == 1
128
+ assert response [" predictions_ignored" ] == 0
91
129
92
130
response = model_run .refloc (prediction .reference_id )
93
131
assert len (response ) == 1
@@ -98,18 +136,22 @@ def test_box_pred_upload_ignore(model_run):
98
136
prediction = BoxPrediction (** TEST_BOX_PREDICTIONS [0 ])
99
137
response = model_run .predict (annotations = [prediction ])
100
138
101
- assert response [' predictions_processed' ] == 1
139
+ assert response [" predictions_processed" ] == 1
102
140
103
141
# Copy so we don't modify the original.
104
142
prediction_update_params = dict (TEST_BOX_PREDICTIONS [1 ])
105
- prediction_update_params ['annotation_id' ] = TEST_BOX_PREDICTIONS [0 ]['annotation_id' ]
106
- prediction_update_params ['reference_id' ] = TEST_BOX_PREDICTIONS [0 ]['reference_id' ]
143
+ prediction_update_params ["annotation_id" ] = TEST_BOX_PREDICTIONS [0 ][
144
+ "annotation_id"
145
+ ]
146
+ prediction_update_params ["reference_id" ] = TEST_BOX_PREDICTIONS [0 ][
147
+ "reference_id"
148
+ ]
107
149
prediction_update = BoxPrediction (** prediction_update_params )
108
150
# Default behavior is ignore.
109
151
response = model_run .predict (annotations = [prediction_update ])
110
152
111
- assert response [' predictions_processed' ] == 1
112
- assert response [' predictions_ignored' ] == 1
153
+ assert response [" predictions_processed" ] == 1
154
+ assert response [" predictions_ignored" ] == 1
113
155
114
156
response = model_run .refloc (prediction .reference_id )
115
157
assert len (response ) == 1
@@ -120,42 +162,69 @@ def test_polygon_pred_upload_update(model_run):
120
162
prediction = PolygonPrediction (** TEST_POLYGON_PREDICTIONS [0 ])
121
163
response = model_run .predict (annotations = [prediction ])
122
164
123
- assert response [' predictions_processed' ] == 1
165
+ assert response [" predictions_processed" ] == 1
124
166
125
167
# Copy so we don't modify the original.
126
168
prediction_update_params = dict (TEST_POLYGON_PREDICTIONS [1 ])
127
- prediction_update_params ['annotation_id' ] = TEST_POLYGON_PREDICTIONS [0 ]['annotation_id' ]
128
- prediction_update_params ['reference_id' ] = TEST_POLYGON_PREDICTIONS [0 ]['reference_id' ]
169
+ prediction_update_params ["annotation_id" ] = TEST_POLYGON_PREDICTIONS [0 ][
170
+ "annotation_id"
171
+ ]
172
+ prediction_update_params ["reference_id" ] = TEST_POLYGON_PREDICTIONS [0 ][
173
+ "reference_id"
174
+ ]
129
175
130
176
prediction_update = PolygonPrediction (** prediction_update_params )
131
177
response = model_run .predict (annotations = [prediction_update ], update = True )
132
178
133
- assert response [' predictions_processed' ] == 1
134
- assert response [' predictions_ignored' ] == 0
179
+ assert response [" predictions_processed" ] == 1
180
+ assert response [" predictions_ignored" ] == 0
135
181
136
182
response = model_run .refloc (prediction .reference_id )
137
183
assert len (response ) == 1
138
- assert_polygon_prediction_matches_dict (response [0 ], prediction_update_params )
184
+ assert_polygon_prediction_matches_dict (
185
+ response [0 ], prediction_update_params
186
+ )
139
187
140
188
141
189
def test_polygon_pred_upload_ignore (model_run ):
142
190
prediction = PolygonPrediction (** TEST_POLYGON_PREDICTIONS [0 ])
143
191
response = model_run .predict (annotations = [prediction ])
144
192
145
- assert response [' predictions_processed' ] == 1
193
+ assert response [" predictions_processed" ] == 1
146
194
147
195
# Copy so we don't modify the original.
148
196
prediction_update_params = dict (TEST_POLYGON_PREDICTIONS [1 ])
149
- prediction_update_params ['annotation_id' ] = TEST_POLYGON_PREDICTIONS [0 ]['annotation_id' ]
150
- prediction_update_params ['reference_id' ] = TEST_POLYGON_PREDICTIONS [0 ]['reference_id' ]
197
+ prediction_update_params ["annotation_id" ] = TEST_POLYGON_PREDICTIONS [0 ][
198
+ "annotation_id"
199
+ ]
200
+ prediction_update_params ["reference_id" ] = TEST_POLYGON_PREDICTIONS [0 ][
201
+ "reference_id"
202
+ ]
151
203
152
204
prediction_update = PolygonPrediction (** prediction_update_params )
153
205
# Default behavior is ignore.
154
206
response = model_run .predict (annotations = [prediction_update ])
155
207
156
- assert response [' predictions_processed' ] == 1
157
- assert response [' predictions_ignored' ] == 1
208
+ assert response [" predictions_processed" ] == 1
209
+ assert response [" predictions_ignored" ] == 1
158
210
159
211
response = model_run .refloc (prediction .reference_id )
160
212
assert len (response ) == 1
161
- assert_polygon_prediction_matches_dict (response [0 ], TEST_POLYGON_PREDICTIONS [0 ])
213
+ assert_polygon_prediction_matches_dict (
214
+ response [0 ], TEST_POLYGON_PREDICTIONS [0 ]
215
+ )
216
+
217
+
218
+ def test_mixed_pred_upload (model_run ):
219
+ prediction_semseg = SegmentationPrediction .from_json (
220
+ TEST_SEGMENTATION_PREDICTIONS [0 ]
221
+ )
222
+ prediction_polygon = PolygonPrediction (** TEST_POLYGON_PREDICTIONS [0 ])
223
+ prediction_bbox = BoxPrediction (** TEST_BOX_PREDICTIONS [0 ])
224
+ response = model_run .predict (
225
+ annotations = [prediction_semseg , prediction_polygon , prediction_bbox ]
226
+ )
227
+
228
+ assert response ["model_run_id" ] == model_run .model_run_id
229
+ assert response ["predictions_processed" ] == 3
230
+ assert response ["predictions_ignored" ] == 0
0 commit comments