Once you have imported your local data or cloud data into Encord, you can import your labels/annotations for the data.

You MUST call the initialise_labels function (once per data unit) before trying to import your labels/annotations.

The process to import labels into Encord consists of the following:

  1. Import the dependencies.
  2. Authenticate your Encord client.
  3. Specify the Annotate Project with the data you want to label.
  4. Specify the label row you want to import your label to. This specifies the data unit (image, image group, image sequence, video, or DICOM series) you want to add your labels to.
  5. Use the initialise_labels function ONCE to prepare the row for your labels.
  6. Apply your labels to the label row.
  7. Save the label row.
One label row is equivalent to one data unit. You only need to use the initialise_labels function and save the label row ONCE per data unit, regardless of how many labels are added to the data unit. However, any future changes to a data unit need to be initialized and saved.

READ THIS FIRST

All the examples demonstrating the use of each label and classification type utilize the following Project and Ontology:

EntityName
ProjectBlueberries and Cherries PROJECT_HASH: 7d4ead9c-4087-4832-a301-eb2545e7d43b
OntologyBlueberries and Cherries Ontology
Bounding boxCherry
Rotatable bounding boxOther type of fruit
PolygonPersimmon
PolylineBranch
KeypointPedicel
BitmaskBlueberry
Object Primitive (Triangle)Strawberry
Radio classificationBlueberry or cherry?
Checklist classificationMany types of fruit?

Object Labels

Classifications

Import Labels in Bulk

When importing a large number of labels, here are some tips to improve your label import performance:

  • A data unit is one image, one image group, one image sequence, one video, or one DICOM series. One data unit is equivalent to one label row. You only need to call the initialise_labels function and save the label row ONCE per data unit. It does not matter how many labels are added to the data unit between the initialise_labels function and saving the label row.

  • Use the bundle function to significantly improve the import performance when you do any of the following:

    • Import labels on a large number of individual images (NOT image groups, image sequences, videos, or DICOM sets).
    • Import labels on a large number of data units at once.

In the following code, ensure you replace:

  • <private_key_path> with the full path to your private key.
  • <project-id> with the unique ID of your Project.
  • #Perform label row operation before in this loop with the label row operations you want to perform.
  • Optionally, change the value of BUNDLE_SIZE to suit your needs. We strongly recommend NOT bundling more than 1000 operations at once, because bundling more than 1000 operations can reduce performance instead of improving performance.

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import BoundingBoxCoordinates

SSH_PATH = "<private-key-path>"
PROJECT_HASH = "<project-unique-id>"

# Authenticate
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path=SSH_PATH)

# Gets Project to export labels
project: Project = user_client.get_project(PROJECT_HASH)

label_rows = project.list_label_rows_v2()
BUNDLE_SIZE = 100

# Initialize label rows using bundles
with project.create_bundle(bundle_size=BUNDLE_SIZE) as bundle
    for label_row in label_rows:
        label_row.initialise_labels(bundle=bundle)

for label_row in label_rows:

    # Write any label row operation here. For example import, or export label rows. 


# Saving changes to label rows using bundles
with project.create_bundle(bundle_size=BUNDLE_SIZE) as bundle:
    for label_row in label_rows:
        label_row.save(bundle=bundle_save)