Upload model predictions

To perform Model Error Analysis, use Model-assisted labeling, or set up Active learning workflows, you must import your model predictions and metrics to Labelbox.

Model predictions and metrics are imported into a Model Run. This reflects a specific iteration or experiment in your model development cycle.

## Upload model predictions by passing a list of annotations in Labelbox NDJSON format 
model_run.add_predictions("upload jobs name", predictions_ndjson)

Annotation types

To use annotation types, import the python classes as shown below.

## Import supported annotation type classes
from labelbox.data.annotation_types import (
    Label, ImageData, MaskData, LabelList, TextData, VideoData,
    ObjectAnnotation, ClassificationAnnotation, Polygon, Rectangle, Line, Mask,
    Point, Checklist, Radio, Text, TextEntity, ClassificationAnswer)

Model predictions must be converted into Labelbox import format so that they can be associated with Labelbox entities as described below.

  1. Associate model prediction class name and tool type to Features

  2. Associate model prediction with Labelbox Data Row ID

Convert your model predictions via annotation types

The example below uses annotation types to convert your model predictions to Labelbox import format.

## export ground truth labels from a project
labels_gen = project.label_generator().as_list()
ground_truth_labels = labels_gen._data

predictions_list = LabelList()

for label in ground_truth_labels:
  # replace this with your model inferencing function
  bbox, point, xy_polyline, classification, segmentation_mask, mask_color = my_model()

  bbox_annotation = ObjectAnnotation(
    name = "bbox",
    value = Rectangle(start = Point(x = bbox[0], y = bbox[1]), end = Point(x = bbox[2]+bbox[0], y = bbox[3]+bbox[1])),

  point_annotation = ObjectAnnotation(value=Point(x=point[0], y=point[1]),
  polyline_annotation = ObjectAnnotation(
    value=Polygon(points=[Point(x=x, y=y) for x, y in xy_polyline]),

  radio_annotation = ClassificationAnnotation(
      name="classification", value=Radio(answer=ClassificationAnswer(name=classification)))

  mask = Mask(mask=MaskData(arr=segmentation_mask), color=mask_color)
  mask_annotation = ObjectAnnotation(name="segmentation", value=mask)
  annotations = [bbox_annotation, point_annotation, polyline_annotation, radio_annotation, mask_annotation]

  image = ImageData(uid = label.data.uid)
  predictions_list.append(Label(data = image, annotations = annotations))

# Associate model predictions with Labelbox feature schema 

# Convert predictions list to NDJSON
predictions_list_ndjson = list(NDJsonConverter.serialize(predictions_list))

# Add predictions to model run
upload_job = model_run.add_predictions("upload-job-name", predictions_list_ndjson)

Complete Python SDK tutorial


Upload image model predictions

Open In ColabOpen In Colab

Did this page help you?