@@ -221,6 +221,7 @@ def format_scale_task_info_response(response: dict) -> Union[Dict, List[Dict]]:
221221 return ret
222222
223223
224+ # pylint: disable=too-many-branches
224225def convert_export_payload (api_payload , has_predictions : bool = False ):
225226 """Helper function to convert raw JSON to API objects
226227
@@ -239,33 +240,66 @@ def convert_export_payload(api_payload, has_predictions: bool = False):
239240 if row .get (SEGMENTATION_TYPE ) is not None :
240241 segmentation = row [SEGMENTATION_TYPE ]
241242 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 )
245251 for polygon in row [POLYGON_TYPE ]:
246252 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+ )
250261 for line in row [LINE_TYPE ]:
251262 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 ))
253267 for keypoints in row [KEYPOINTS_TYPE ]:
254268 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+ )
258277 for box in row [BOX_TYPE ]:
259278 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 ))
261283 for cuboid in row [CUBOID_TYPE ]:
262284 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+ )
264293 for category in row [CATEGORY_TYPE ]:
265294 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+ )
269303 for multicategory in row [MULTICATEGORY_TYPE ]:
270304 multicategory [REFERENCE_ID_KEY ] = row [ITEM_KEY ][REFERENCE_ID_KEY ]
271305 annotations [MULTICATEGORY_TYPE ].append (
0 commit comments