Similar to Label, A model's predictions is constructed from a Data object and its associated predicted Annotations.
When you bulk upload predictions, you will create a Label list that contains a list of predicted Labels, each of which is constructed by a Data (constructed from Data Row ids) and a list of Annotations.
Add predictions to a Model Run
Prepare predictions
from labelbox import Client
from labelbox.data.annotation_types import (
Label, ImageData, LabelList,
ObjectAnnotation, Rectangle, Point)
from labelbox.data.serialization import NDJsonConverter
predictions_all_data_rows = LabelList()
# Every item in predictions_all_data_rows corresponds to a data row.
# Here, we show how to add predictions on one data row.
predictions_data_row = []
# add one bounding box
predictions_data_row.append(
ObjectAnnotation(
name = "<your_class_name>",
value = Rectangle(start = Point(x=..., y=...),end=Point(x=..., y=...))
)
)
# add another bounding box for the same data row.
predictions_data_row.append(
ObjectAnnotation(
name = "<your_class_name>",
value = Rectangle(start = Point(x=..., y=...),end=Point(x=..., y=...))
)
)
# Append data row predictions to the global list of predictions
data_row = ImageData(uid = "<your_data_row_id>")
predictions_all_data_rows.append(
Label(
data = data_row,
annotations = predictions_data_row
)
)
Convert to NDJson format
# To import predictions in Labelbox, you must convert the python types to NDJSON format.
# You can do so by using NDJSONConverter as shown below.
prediction_ndjson = list(NDJsonConverter.serialize(predictions_all_data_rows))
Upload predictions to the Model Run
name = "<your_upload_job_name>"
upload_job = model_run.add_predictions(name=name, predictions=prediction_ndjson)
Monitor upload job
upload_job.wait_until_done()
print(upload_job.state)
print(upload_job.errors)