@@ -221,6 +221,7 @@ def format_scale_task_info_response(response: dict) -> Union[Dict, List[Dict]]:
221
221
return ret
222
222
223
223
224
+ # pylint: disable=too-many-branches
224
225
def convert_export_payload (api_payload , has_predictions : bool = False ):
225
226
"""Helper function to convert raw JSON to API objects
226
227
@@ -239,33 +240,66 @@ def convert_export_payload(api_payload, has_predictions: bool = False):
239
240
if row .get (SEGMENTATION_TYPE ) is not None :
240
241
segmentation = row [SEGMENTATION_TYPE ]
241
242
segmentation [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
242
- annotations [SEGMENTATION_TYPE ] = SegmentationAnnotation .from_json (
243
- segmentation
244
- )
243
+ if not has_predictions :
244
+ annotations [
245
+ SEGMENTATION_TYPE
246
+ ] = SegmentationAnnotation .from_json (segmentation )
247
+ else :
248
+ annotations [
249
+ SEGMENTATION_TYPE
250
+ ] = SegmentationPrediction .from_json (segmentation )
245
251
for polygon in row [POLYGON_TYPE ]:
246
252
polygon [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
247
- annotations [POLYGON_TYPE ].append (
248
- PolygonAnnotation .from_json (polygon )
249
- )
253
+ if not has_predictions :
254
+ annotations [POLYGON_TYPE ].append (
255
+ PolygonAnnotation .from_json (polygon )
256
+ )
257
+ else :
258
+ annotations [POLYGON_TYPE ].append (
259
+ PolygonPrediction .from_json (polygon )
260
+ )
250
261
for line in row [LINE_TYPE ]:
251
262
line [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
252
- annotations [LINE_TYPE ].append (LineAnnotation .from_json (line ))
263
+ if not has_predictions :
264
+ annotations [LINE_TYPE ].append (LineAnnotation .from_json (line ))
265
+ else :
266
+ annotations [LINE_TYPE ].append (LinePrediction .from_json (line ))
253
267
for keypoints in row [KEYPOINTS_TYPE ]:
254
268
keypoints [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
255
- annotations [KEYPOINTS_TYPE ].append (
256
- KeypointsAnnotation .from_json (keypoints )
257
- )
269
+ if not has_predictions :
270
+ annotations [KEYPOINTS_TYPE ].append (
271
+ KeypointsAnnotation .from_json (keypoints )
272
+ )
273
+ else :
274
+ annotations [KEYPOINTS_TYPE ].append (
275
+ KeypointsPrediction .from_json (keypoints )
276
+ )
258
277
for box in row [BOX_TYPE ]:
259
278
box [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
260
- annotations [BOX_TYPE ].append (BoxAnnotation .from_json (box ))
279
+ if not has_predictions :
280
+ annotations [BOX_TYPE ].append (BoxAnnotation .from_json (box ))
281
+ else :
282
+ annotations [BOX_TYPE ].append (BoxPrediction .from_json (box ))
261
283
for cuboid in row [CUBOID_TYPE ]:
262
284
cuboid [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
263
- annotations [CUBOID_TYPE ].append (CuboidAnnotation .from_json (cuboid ))
285
+ if not has_predictions :
286
+ annotations [CUBOID_TYPE ].append (
287
+ CuboidAnnotation .from_json (cuboid )
288
+ )
289
+ else :
290
+ annotations [CUBOID_TYPE ].append (
291
+ CuboidPrediction .from_json (cuboid )
292
+ )
264
293
for category in row [CATEGORY_TYPE ]:
265
294
category [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
266
- annotations [CATEGORY_TYPE ].append (
267
- CategoryAnnotation .from_json (category )
268
- )
295
+ if not has_predictions :
296
+ annotations [CATEGORY_TYPE ].append (
297
+ CategoryAnnotation .from_json (category )
298
+ )
299
+ else :
300
+ annotations [CATEGORY_TYPE ].append (
301
+ CategoryPrediction .from_json (category )
302
+ )
269
303
for multicategory in row [MULTICATEGORY_TYPE ]:
270
304
multicategory [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
271
305
annotations [MULTICATEGORY_TYPE ].append (
0 commit comments