Python annotation types

Formats

NDJSON

The standard input format used to upload annotations to Labelbox.

Python annotation types

The Labelbox Python Annotation Types are a common format for representing human and machine-generated annotations. Teams can use Annotations Types to standardize and simplify many aspects of their machine learning data management.

Key features:

Installation

Annotation Types is part of data extra of the Labelbox Python SDK.

pip install "labelbox[data]"

Basics

  • A LabelCollection is a list or generator for working with a collection of Labels
  • A Label is constructed fromData and Annotations. E.g. an image and bounding boxes
  • An Annotation is either an ObjectAnnotation or a ClassificationAnnotation.
  • Annotations have a name and a Geometry, Classification, or some Text data.

Hierarchy

Creating labels and annotations

A simple example creating a Point at the coordinate (10, 10) with the class name "target" on an image.

from labelbox.data.annotation_types import  Label, LabelList, ImageData, Point, ObjectAnnotation

labels = [
  Label(
    data = ImageData(url = "http://my-img.jpg"),
    annotations = [
        ObjectAnnotation(
            value = Point(x = 10, y = 10),
            name = "target"
        )
     ]
  )
]
labels = LabelList(labels)

Serializing annotations

It's a common workflow to change the format for annotations to work with tools like Model diagnostics or Model-assisted labeling (MAL). Using a built-in or custom serializer you can transform annotations to the necessary format.

from labelbox.data.serialization import NDJsonConverter

project = client.get_project("<project-id>")

# To assign feature schema ids to named fields
lblabels = labels.assign_feature_schema_ids(OntologyBuilder.from_project(project))
# conver to NDJSON format
ndlabels = NDJsonConverter.serialize(lblabels)

# Upload for model assisted labeling
upload_task = project.upload_annotations(
  name="upload-job-1",
  annotations=ndjsons,
  validate=True
)

Tutorials

You can explore the functionality of the library through the following notebooks.

Python Tutorial

Github

Google Colab

Annotation Type Basics

Open in Github

Open in Google Colab

Converters

Open in Github

Open in Google Colab

Label Containers

Open in Github

Open in Google Colab

MAL Using Annotation Types

Open in Github

Open in Google Colab


Did this page help you?