Import Labels/Annotations

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

❗️

CRITICAL INFORMATION

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.

ℹ️

Note

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 of the examples used to illustrate using each label and classification type use the following example 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?

Labels

Bounding box

Example 1

Imports a single bounding box (Cherry) to a single image (cherry_001.png).

Example 2:

Imports three instances (tracking an object across three sequential frames: 103, 104, and 105) of a bounding box (Cherry) to a video (Cherries_video.mp4).

Example 3

Imports three bounding boxes (Cherry) to a single image (cherry_001.png).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 103, 104, 105, object 2 - frames 206, 207, 208, and object 3 - frames 313, 315, 317) of three bounding boxes (Cherry) to a video (Cherries_video.mp4).

# 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 = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="<name-of-data-unit>"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
box_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="<name-of-object-bounding-box>", type_=Object
    )

# Instantiate an object instance from the box ontology node
box_object_instance: ObjectInstance = box_ontology_object.create_instance()

box_object_instance.set_for_frames(
    coordinates=BoundingBoxCoordinates(
        height=<numerical-value>,
        width=<numerical-value>,
        top_left_x=<numerical-value>,
        top_left_y=<numerical-value>,
    ),
    # Add the bounding box to the frames specified
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
 )

# Link the object instance to the label row.
label_row.add_object_instance(box_object_instance)

# Upload the label to the server
label_row.save()

# 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 = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="cherry_001.png"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
box_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Cherry", type_=Object
    )

# Instantiate an object instance from the box ontology node
box_object_instance: ObjectInstance = box_ontology_object.create_instance()

box_object_instance.set_for_frames(
    coordinates=BoundingBoxCoordinates(
        height=0.1,
        width=0.1,
        top_left_x=0.7,
        top_left_y=0.3,
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(box_object_instance)

# Upload the label to the server
label_row.save()

# 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 = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
box_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Cherry", type_=Object
    )

# Instantiate an object instance from the box ontology node
box_object_instance: ObjectInstance = box_ontology_object.create_instance()

# Tracking across 3 frames
coordinates_per_frame = {
    103: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
    ),
    104: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
    ),
    105: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    box_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Link the object instance to the label row.

label_row.add_object_instance(box_object_instance)

# Upload the label to the server
label_row.save()

# 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 = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="cherry_001.png"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
box_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Cherry", type_=Object
    )

# Bounding box 1 - START
# Instantiate object instance 01 from the box ontology node
box_object_instance01: ObjectInstance = box_ontology_object.create_instance()

box_object_instance01.set_for_frames(
    coordinates=BoundingBoxCoordinates(
        height=0.1,
        width=0.1,
        top_left_x=0.2,
        top_left_y=0.2,
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(box_object_instance01)

# Bounding box 1 - END

# Bounding box 2 - START

# Instantiate object instance 02 from the box ontology node
box_object_instance02: ObjectInstance = box_ontology_object.create_instance()

box_object_instance02.set_for_frames(
    coordinates=BoundingBoxCoordinates(
        height=0.1,
        width=0.1,
        top_left_x=0.3,
        top_left_y=0.3,
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(box_object_instance02)

# Bounding box 2 - END

# Bounding box 3 - START

# Instantiate an object instance 03 from the box ontology node
box_object_instance3: ObjectInstance = box_ontology_object.create_instance()

box_object_instance01.set_for_frames(
    coordinates=BoundingBoxCoordinates(
        height=0.1,
        width=0.1,
        top_left_x=0.4,
        top_left_y=0.4,
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(box_object_instance03)

# Bounding box 3 - END

# Upload all labels for this data unit (individual image) to the server
label_row.save()
# 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 = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
box_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Cherry", type_=Object
    )

# Bounding box 1 - START

# Instantiate an object instance from the box ontology node
box_object_instance01: ObjectInstance = box_ontology_object.create_instance()

# Tracking object 1 across 3 frames
coordinates_per_frame = {
    103: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
    ),
    104: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
    ),
    105: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    box_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Link the object instance to the label row.

label_row.add_object_instance(box_object_instance01)

# Bounding box 1 - END

# Bounding box 2 - START

# Instantiate an object instance from the box ontology node
box_object_instance02: ObjectInstance = box_ontology_object.create_instance()

# Tracking object 2 across 3 frames
coordinates_per_frame = {
    206: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
    ),
    207: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
    ),
    208: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    box_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Link the object instance to the label row.

label_row.add_object_instance(box_object_instance02)


# Bounding box 3 - START

# Instantiate an object instance from the box ontology node
box_object_instance03: ObjectInstance = box_ontology_object.create_instance()

# Tracking across 3 frames
coordinates_per_frame = {
    313: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
    ),
    315: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
    ),
    317: BoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    box_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Link the object instance to the label row.

label_row.add_object_instance(box_object_instance03)

# Bounding box 3 - END

# Upload all labels for this data unit (video) to the server
label_row.save()

Rotatable Bounding Box

Example 1

Imports a single rotatable bounding box (Other type of fruit) to a single image (apple_001.png).

Example 2

Imports three instances (tracking an object across three sequential frames: 120, 121, and 122) of a bounding box (Other type of fruit) to a video (Cherries_video.mp4).

Example 3

Imports three rotatable bounding boxes (Other type of fruit) to a single image (apple_001.png).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 120, 121, 122, object 2 - frames 222, 224, 226, and object 3 - frames 321, 323, 325) of three rotatable bounding boxes (Other type of fruit) to a video (Cherries_video.mp4).

# Import dependencies
from pathlib import Path

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

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-hash-for-project>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one rotatable bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="<data-unit-title>"
)[0]

label_row.initialise_labels()

# Find a rotatable bounding box annotation object in the project ontology
rbb_ontology_object: Object = project.ontology_structure.get_child_by_title((
        title="<rotatable-bounding-box-class-title>", type_=Object
    )

# Instantiate an object instance from the rotatable bounding box ontology node
rbb_object_instance: ObjectInstance = rbb_ontology_object.create_instance()

rbb_object_instance.set_for_frames(
    coordinates=RotatableBoundingBoxCoordinates(
        height=<height-value>
        width=<width-value>,
        top_left_x=<top-left-x-value>,
        top_left_y=<top-left-y-value>,
        theta=<angle-of-rotation>
    ),
    # Add the rotatable bounding box to frame number specified
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(rbb_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one rotatable bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="apple_001.jpg"
)[0]

label_row.initialise_labels()

# Find a rotatable bounding box annotation object in the project ontology
rbb_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Other type of fruit", type_=Object
    )

# Instantiate an object instance from the rotatable bounding box ontology node
rbb_object_instance: ObjectInstance = rbb_ontology_object.create_instance()

rbb_object_instance.set_for_frames(
    coordinates=RotatableBoundingBoxCoordinates(
        height=0.23,
        width=0.13,
        top_left_x=0.3,
        top_left_y=0.5,
        theta=95
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(rbb_object_instance)

# Upload the label to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a rotatable bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
rbb_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Other type of fruit", type_=Object
    )

# Instantiate an object instance from the box ontology node
rbb_object_instance: ObjectInstance = rbb_ontology_object.create_instance()


coordinates_per_frame = {
    120: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
        theta=23
    ),
    121: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
        theta=27
    ),
    122: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
        theta=57
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    rbb_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(rbb_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one rotatable bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="apple_001.jpg"
)[0]

label_row.initialise_labels()

# Find a rotatable bounding box annotation object in the project ontology
rbb_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Other type of fruit", type_=Object
    )

# Rotatable bounding box 01 - START

# Instantiate an object instance from the rotatable bounding box ontology node
rbb_object_instance01: ObjectInstance = rbb_ontology_object.create_instance()

rbb_object_instance01.set_for_frames(
    coordinates=RotatableBoundingBoxCoordinates(
        height=0.23,
        width=0.13,
        top_left_x=0.1,
        top_left_y=0.2,
        theta=37
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(rbb_object_instance01)

# Rotatable bounding box 01 - END

# Rotatable bounding box 02 - START

# Instantiate an object instance from the rotatable bounding box ontology node
rbb_object_instance02: ObjectInstance = rbb_ontology_object.create_instance()

rbb_object_instance02.set_for_frames(
    coordinates=RotatableBoundingBoxCoordinates(
        height=0.23,
        width=0.13,
        top_left_x=0.3,
        top_left_y=0.5,
        theta=95
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(rbb_object_instance02)

# Rotatable bounding box 02 - END

# Rotatable bounding box 03 - START

# Instantiate an object instance from the rotatable bounding box ontology node
rbb_object_instance03: ObjectInstance = rbb_ontology_object.create_instance()

rbb_object_instance03.set_for_frames(
    coordinates=RotatableBoundingBoxCoordinates(
        height=0.23,
        width=0.13,
        top_left_x=0.3,
        top_left_y=0.5,
        theta=95
    ),
    # Add the bounding box to the image frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(rbb_object_instance03)

# Rotatable bounding box 03 - END


# Upload all the labels for the data unit (individual image) to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a rotatable bounding box - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bounding box annotation object in the project ontology
rbb_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Other type of fruit", type_=Object
    )


# Rotatable bounding box 01 - START

# Instantiate an object instance from the box ontology node
rbb_object_instance01: ObjectInstance = rbb_ontology_object.create_instance()


coordinates_per_frame = {
    120: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
        theta=23
    ),
    121: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
        theta=27
    ),
    122: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
        theta=57
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    rbb_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(rbb_object_instance01)

# Rotatable bounding box 01 - END


# Rotatable bounding box 02 - START

# Instantiate an object instance from the box ontology node
rbb_object_instance02: ObjectInstance = rbb_ontology_object.create_instance()


coordinates_per_frame = {
    222: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
        theta=23
    ),
    224: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
        theta=27
    ),
    226: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
        theta=57
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    rbb_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(rbb_object_instance02)

# Rotatable bounding box 02 - END


# Rotatable bounding box 03 - START

# Instantiate an object instance from the box ontology node
rbb_object_instance03: ObjectInstance = rbb_ontology_object.create_instance()


coordinates_per_frame = {
    321: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.2,
        top_left_y=0.2,
        theta=23
    ),
    323: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.3,
        top_left_y=0.3,
        theta=27
    ),
    325: RotatableBoundingBoxCoordinates(
        height=0.5,
        width=0.5,
        top_left_x=0.4,
        top_left_y=0.4,
        theta=57
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    rbb_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(rbb_object_instance03)

# Rotatable bounding box 03 - END


# Upload all labels for this data unit (video) to the server
label_row.save()

Polygons

Example 1

Imports a single polygon (Persimmon) to a single image (persimmon_001.jpg).

Example 2

Imports three instances (tracking an object across three sequential frames: 143, 144, and 145) of a polygon (Persimmon) to a video (Cherries_video.mp4).

Example 3

Imports three polygons (Persimmon) to a single image (persimmon_001.jpg).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 153, 154, 155, object 2 - frames 242, 244, 246, and object 3 - frames 343, 345, 347) of three polygons (Persimmon) to a video (Cherries_video.mp4).

# Import dependencies
from pathlib import Path

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

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one polygon - START
label_row = project.list_label_rows_v2(
    data_title_eq="<name-of-data-unit>"
)[0]

label_row.initialise_labels()

# Creating one bounding box - START
# Find a polygon annotation object in the project ontology
polygon_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="<object-name>", type_=Object
    )

# Instantiate an object instance from the polygon ontology node
polygon_object_instance: ObjectInstance = polygon_ontology_object.create_instance()

# The x,y coordinates of each polygon vertex are specified as follows
polygon_object_instance.set_for_frames(
    coordinates=PolygonCoordinates(
        [PointCoordinate(.xx,.xx), PointCoordinate(.xx,.xx), PointCoordinate(.xx,.xxx), PointCoordinate(.13,.456)]
    ),
    # Add the polygon to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polygon_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "</Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="persimmon_001.jpg"
)[0]

label_row.initialise_labels()


# Creating one polygon - START
# Find a polygon annotation object in the project ontology
polygon_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Persimmon", type_=Object
    )

# Instantiate an object instance from the polygon ontology node
polygon_object_instance: ObjectInstance = polygon_ontology_object.create_instance()

# The x,y coordinates of each polygon vertex are specified as follows
polygon_object_instance.set_for_frames(
    coordinates=PolygonCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polygon_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a polygon - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a polygon annotation object in the project ontology
polygon_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Persimmon", type_=Object
    )

# Instantiate an object instance from the polygon ontology node
polygon_object_instance: ObjectInstance = polygon_ontology_object.create_instance()

coordinates_per_frame = {
    143: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    144: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    145: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polygon_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polygon_object_instance)

# Upload the label to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "</Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="persimmon_001.jpg"
)[0]

label_row.initialise_labels()

# Find a polygon annotation object in the project ontology
polygon_ontology_object01: Object = project.ontology_structure.get_child_by_title(
        title="Persimmon", type_=Object
    )

# Polygon 1 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance01: ObjectInstance = polygon_ontology_object.create_instance()

# The x,y coordinates of each polygon vertex are specified as follows
polygon_object_instance01.set_for_frames(
    coordinates=PolygonCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polygon_object_instance01)

# Polygon 1 - END


# Polygon 2 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance02: ObjectInstance = polygon_ontology_object.create_instance()

# The x,y coordinates of each polygon vertex are specified as follows
polygon_object_instance02.set_for_frames(
    coordinates=PolygonCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polygon_object_instance02)

# Polygon 2 - END


# Polygon 3 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance03: ObjectInstance = polygon_ontology_object.create_instance()

# The x,y coordinates of each polygon vertex are specified as follows
polygon_object_instance03.set_for_frames(
    coordinates=PolygonCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polygon_object_instance03)

# Polygon 3 - END


# Upload all labels for the data unit (single image) to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three instances of a polygon - START
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a polygon annotation object in the project ontology
polygon_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Persimmon", type_=Object
    )

# Polygon 1 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance01: ObjectInstance = polygon_ontology_object.create_instance()

coordinates_per_frame = {
    153: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    154: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    155: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polygon_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polygon_object_instance01)

# Polygon 1 - END


# Polygon 2 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance02: ObjectInstance = polygon_ontology_object.create_instance()

coordinates_per_frame = {
    242: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    244: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    246: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polygon_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polygon_object_instance02)

# Polygon 2 - END


# Polygon 3 - START

# Instantiate an object instance from the polygon ontology node
polygon_object_instance03: ObjectInstance = polygon_ontology_object.create_instance()

coordinates_per_frame = {
    343: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    345: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    347: PolygonCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polygon_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polygon_object_instance03)

# Polygon 3 - END


# Upload all labels for this data unit (video) to the server
label_row.save()

Polyline

Example 1

Imports a single polyline (Branch) to a single image (persimmon_001.jpg).

Example 2

Imports three instances (tracking an object across three sequential frames: 146, 147, and 148) of a polygon (Branch) to a video (Cherries_video.mp4).

Example 3

Imports three polylines (Branch) to a single image (persimmon_001.jpg).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 246, 247, 248, object 2 - frames 346, 347, 348, and object 3 - frames 446, 447, 448) of three polylines (Branch) to a video (Cherries_video.mp4).

# Import dependencies
from pathlib import Path

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

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="<name-of-data-unit>"
)[0]

label_row.initialise_labels()

# Find a polyline annotation object in the project ontology
polyline_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="<object-name>", type_=Object
    )

# Instantiate an object instance from the polyline ontology node
polyline_object_instance: ObjectInstance = polyline_ontology_object.create_instance()

# The x,y coordinates of each polyline vertex are specified as follows
polline_object_instance.set_for_frames(
    coordinates=PolylineCoordinates(
        [PointCoordinate(.xx,.xx), PointCoordinate(.xx,.xx), PointCoordinate(.xx,.xxx), PointCoordinate(.13,.456)]
    ),
    # Add the polyline to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polyline_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "</Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="apple_001.png"
)[0]

label_row.initialise_labels()


# Creating one polyline - START
# Find a polyline annotation object in the project ontology
polyline_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Branch", type_=Object
    )

# Instantiate an object instance from the polyline ontology node
polyline_object_instance: ObjectInstance = polyline_ontology_object.create_instance()

# The x,y coordinates of each polyline vertex are specified as follows
polyline_object_instance.set_for_frames(
    coordinates=PolylineCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polyline to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polyline_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a polyline annotation object in the project ontology
polyline_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Branch", type_=Object
    )

# Instantiate an object instance from the polyline ontology node
polyline_object_instance: ObjectInstance = polyline_ontology_object.create_instance()

coordinates_per_frame = {
    146: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    147: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    148: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polyline_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polyline_object_instance)

# Upload the label to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "</Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="apple_001.png"
)[0]

label_row.initialise_labels()


# Creating one polyline - START
# Find a polyline annotation object in the project ontology
polyline_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Branch", type_=Object
    )

# Polyline 1 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance01: ObjectInstance = polyline_ontology_object.create_instance()

# The x,y coordinates of each polyline vertex are specified as follows
polyline_object_instance01.set_for_frames(
    coordinates=PolylineCoordinates(
        [PointCoordinate(.1,.1), PointCoordinate(.2,.2), PointCoordinate(.3,.3), PointCoordinate(.4,.4)]
    ),
    # Add the polyline to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(polyline_object_instance01)

# Polyline 1 - END


# Polyline 2 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance02: ObjectInstance = polyline_ontology_object.create_instance()

# The x,y coordinates of each polyline vertex are specified as follows
polyline_object_instance02.set_for_frames(
    coordinates=PolylineCoordinates(
        [PointCoordinate(.15,.15), PointCoordinate(.25,.25), PointCoordinate(.35,.35), PointCoordinate(.45,.45)]
    ),
    # Add the polyline to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
)

# Link the object instance to the label row.
label_row.add_object_instance(polyline_object_instance02)

# Polyline 2 - END


# Polyline 3 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance03: ObjectInstance = polyline_ontology_object.create_instance()

# The x,y coordinates of each polyline vertex are specified as follows
polyline_object_instance03.set_for_frames(
    coordinates=PolylineCoordinates(
        [PointCoordinate(.17,.17), PointCoordinate(.27,.27), PointCoordinate(.37,.37), PointCoordinate(.47,.47)]
    ),
    # Add the polyline to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
)

# Link the object instance to the label row.
label_row.add_object_instance(polyline_object_instance03)

# Polyline 3 - END


# Upload all labels for this data unit (individual image) to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a polyline annotation object in the project ontology
polyline_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Branch", type_=Object
    )

# Polyine 1 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance01: ObjectInstance = polyline_ontology_object.create_instance()

coordinates_per_frame = {
    246: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    247: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
    248: PolylineCoordinates(
        [PointCoordinate(.1,.1),
         PointCoordinate(.2,.1),
         PointCoordinate(.3,.2),
         PointCoordinate(.1,.3)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polyline_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polyline_object_instance01)

# Polyline 1 - END


# Polyine 2 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance02: ObjectInstance = polyline_ontology_object.create_instance()

coordinates_per_frame = {
    346: PolylineCoordinates(
        [PointCoordinate(.11,.11),
         PointCoordinate(.21,.11),
         PointCoordinate(.31,.21),
         PointCoordinate(.11,.31)
         ]
    ),
    347: PolylineCoordinates(
        [PointCoordinate(.11,.11),
         PointCoordinate(.21,.11),
         PointCoordinate(.31,.21),
         PointCoordinate(.11,.31)
         ]
    ),
    348: PolylineCoordinates(
        [PointCoordinate(.11,.11),
         PointCoordinate(.21,.11),
         PointCoordinate(.31,.21),
         PointCoordinate(.11,.31)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polyline_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polyline_object_instance02)

# Polyline 2 - END


# Polyine 3 - START

# Instantiate an object instance from the polyline ontology node
polyline_object_instance03: ObjectInstance = polyline_ontology_object.create_instance()

coordinates_per_frame = {
    446: PolylineCoordinates(
        [PointCoordinate(.21,.21),
         PointCoordinate(.22,.21),
         PointCoordinate(.23,.22),
         PointCoordinate(.21,.23)
         ]
    ),
    447: PolylineCoordinates(
        [PointCoordinate(.21,.21),
         PointCoordinate(.22,.21),
         PointCoordinate(.23,.22),
         PointCoordinate(.21,.23)
         ]
    ),
    448: PolylineCoordinates(
        [PointCoordinate(.21,.21),
         PointCoordinate(.22,.21),
         PointCoordinate(.23,.22),
         PointCoordinate(.21,.23)
         ]
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    polyline_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(polyline_object_instance03)

# Polyline 3 - END


# Upload all labels for this data unit (video) to the server
label_row.save()

Keypoint

Example 1

Imports a single keypoint (Pedicel) to a single image (blueberry_003.png).

Example 2

Imports three instances (tracking an object across three sequential frames: 143, 144, and 145) of a keypoint (Pedicel) to a video (Blueberries_video.mp4).

Example 3

Imports three keypoints (Pedicel) to a single image (blueberry_003.png).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 143, 144, 145, object 2 - frames 242, 244, 246, and object 3 - frames 343, 345, 347) of three keypoints (Pedicel) to a video (Blueberries_video.mp4).

# Import dependencies
from pathlib import Path

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

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="<name-of-data-unit>"
)[0]

label_row.initialise_labels()

# Creating one Keypoint - START
# Find a keypoint annotation object in the project ontology
keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="<object-name>", type_=Object
    )

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance: ObjectInstance = keypoint_ontology_object.create_instance()

# The x,y coordinates of the keypoint are specified as follows
keypoint_object_instance.set_for_frames(
    coordinates=PointCoordinate(
        x=<value-for-x-axis>
        y=<value-for-y-axis>
    ),
    # Add the keypoint to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(keypoint_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/prod-sdk-ssh-key-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="blueberry_003.png"
)[0]

label_row.initialise_labels()


# Creating one keypoint - START
# Find a keypoint annotation object in the project ontology
keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Pedicel", type_=Object
    )

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance: ObjectInstance = keypoint_ontology_object.create_instance()

# The x,y coordinates of the keypoint are specified as follows
keypoint_object_instance.set_for_frames(
    coordinates=PointCoordinate(
        x=.1,
        y=.1
    ),
    # Add the keypoint to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(keypoint_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/laverne-encord/prod-sdk-ssh-key-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a keypoint annotation object in the project ontology
keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Pedicel", type_=Object
    )

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance: ObjectInstance = keypoint_ontology_object.create_instance()

coordinates_per_frame = {
    143: PointCoordinate(
        x=.1,
        y=.2
    ),
    144: PointCoordinate(
        x=.11,
        y=.22
    ),
    145: PointCoordinate(
        x=.12,
        y=.23
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    keypoint_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(keypoint_object_instance)

# Upload the label to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/chris-encord/prod-sdk-ssh-key-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="blueberry_003.png"
)[0]

label_row.initialise_labels()

# Find a keypoint annotation object in the project ontology
keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Pedicel", type_=Object
    )


# Keypoint 1 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance01: ObjectInstance = keypoint_ontology_object.create_instance()

# The x,y coordinates of the keypoint are specified as follows
keypoint_object_instance01.set_for_frames(
    coordinates=PointCoordinate(
        x=.1,
        y=.1
    ),
    # Add the keypoint to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(keypoint_object_instance01)

# Keypoint 1 - END


# Keypoint 2 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance02: ObjectInstance = keypoint_ontology_object.create_instance()

# The x,y coordinates of the keypoint are specified as follows
keypoint_object_instance02.set_for_frames(
    coordinates=PointCoordinate(
        x=.2,
        y=.2
    ),
    # Add the keypoint to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(keypoint_object_instance02)

# Keypoint 2 - END


# Keypoint 3 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance03: ObjectInstance = keypoint_ontology_object.create_instance()

# The x,y coordinates of the keypoint are specified as follows
keypoint_object_instance03.set_for_frames(
    coordinates=PointCoordinate(
        x=.3,
        y=.3
    ),
    # Add the keypoint to the specified frame number
    frames=<frame-number>,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(keypoint_object_instance03)

# Keypoint 3 - END


# Upload the label to the server
label_row.save()
# Import dependencies
from pathlib import Path

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

SSH_PATH = "/Users/laverne-encord/prod-sdk-ssh-key-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a keypoint annotation object in the project ontology
keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Pedicel", type_=Object
    )

# Keypoint 1 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance01: ObjectInstance = keypoint_ontology_object.create_instance()

coordinates_per_frame = {
    143: PointCoordinate(
        x=.1,
        y=.2
    ),
    144: PointCoordinate(
        x=.11,
        y=.22
    ),
    145: PointCoordinate(
        x=.12,
        y=.23
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    keypoint_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(keypoint_object_instance01)

# Keypoint 1 - END


# Keypoint 2 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance02: ObjectInstance = keypoint_ontology_object.create_instance()

coordinates_per_frame = {
    242: PointCoordinate(
        x=.21,
        y=.22
    ),
    244: PointCoordinate(
        x=.211,
        y=.222
    ),
    246: PointCoordinate(
        x=.212,
        y=.223
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    keypoint_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(keypoint_object_instance02)

# Keypoint 2 - END


# Keypoint 3 - START

# Instantiate an object instance from the keypoint ontology node
keypoint_object_instance03: ObjectInstance = keypoint_ontology_object.create_instance()

coordinates_per_frame = {
    343: PointCoordinate(
        x=.31,
        y=.32
    ),
    345: PointCoordinate(
        x=.311,
        y=.322
    ),
    347: PointCoordinate(
        x=.312,
        y=.323
    ),
}
for frame_number, coordinates in coordinates_per_frame.items():
    keypoint_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(keypoint_object_instance03)

# Keypoint 3 - END


# Upload all labels for this data unit (video) to the server
label_row.save()

Bitmask

Example 1:

Imports a single bitmask (Blueberry) to a single image (blueberry_003.jpg). For simplicity, the bitmask covers the entire image (image dimensions: 1254x836).

Example 2:

Imports three instances (tracking an object across three sequential frames: 156, 157, and 159) of a bitmask (Blueberry) to a video (Blueberries_video.mp4). For simplicity, the bitmask covers the entire frame (video dimensions: 1920x1080).

Example 3:

Imports three bitmasks (Blueberry) to a single image (blueberry_003.jpg). For simplicity, the bitmasks cover the entire image (image dimensions: 1254x836).

Example 4:

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 156, 157, 158, object 2 - frames 256, 258, 259, and object 3 - frames 355, 357, 359) of three bitmasks (Blueberry) to a video (Blueberries_video.mp4). For simplicity, the bitmasks cover the entire frame (video dimensions: 1920x1080).

# Import dependencies
import numpy as np

from pathlib import Path

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

# Firstly, we need to prepare the mask itself.
# For simplicity, we can just mask the whole image
# Note, that the size of the mask must be identical to the size of the image
numpy_coordinates = np.ones((<y-axis-value>, <x-axis-value>))

# we also need to make sure that the image is in boolean format
numpy_coordinates = numpy_coordinates.astype(bool)


SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one bitmask - START
label_row = project.list_label_rows_v2(
    data_title_eq="<data-unit-name>"
)[0]

label_row.initialise_labels()

# Find a bitmask annotation object in the project ontology
bitmask_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="<bitmask-object-name>", type_=Object
)

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance: ObjectInstance = bitmask_ontology_object.create_instance()

# The coordinates the bitmask are specified as follows

bitmask_object_instance.set_for_frames(
    # Create coordinates from provided numpy bitmask
    coordinates=BitmaskCoordinates(numpy_coordinates),
    # Add the bitmask to the first frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# And assign the object instance to the label row
label_row.add_object_instance(bitmask_object_instance)

label_row.save()

# Import dependencies
import numpy as np

from pathlib import Path

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

# Firstly, we need to prepare the mask itself.
# For simplicity, we can just mask the whole image
# Note, that the size of the mask must be identical to the size of the image
numpy_coordinates = np.ones((836, 1254))

# we also need to make sure that the image is in boolean format
numpy_coordinates = numpy_coordinates.astype(bool)


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="blueberry_003.jpg"
)[0]

label_row.initialise_labels()

# Find a bitmask annotation object in the project ontology
bitmask_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Blueberry", type_=Object
)

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance: ObjectInstance = bitmask_ontology_object.create_instance()

# The coordinates the bitmask are specified as follows

bitmask_object_instance.set_for_frames(
    # Create coordinates from provided numpy bitmask
    coordinates=BitmaskCoordinates(numpy_coordinates),
    # Add the bitmask to the first frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# And assign the object instance to the label row
label_row.add_object_instance(bitmask_object_instance)

label_row.save()

# Import dependencies
import numpy as np

from pathlib import Path

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

# Firstly, we need to prepare the mask itself.
# For simplicity, we'll mask the enitre frame
# Note, that the size of the mask must be identical to the size of the image/frame
numpy_coordinates = np.ones((1080, 1920))

# we also need to make sure that the image/frame is in boolean format
numpy_coordinates = numpy_coordinates.astype(bool)


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three bitmasks for three consecutive images- START
# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bitmask annotation object in the project ontology
bitmask_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Blueberry", type_=Object
)

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance: ObjectInstance = bitmask_ontology_object.create_instance()

coordinates_per_frame = {
    156: BitmaskCoordinates(numpy_coordinates),
    157: BitmaskCoordinates(numpy_coordinates),
    158: BitmaskCoordinates(numpy_coordinates),
}
for frame_number, coordinates in coordinates_per_frame.items():
    bitmask_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(bitmask_object_instance)

# Upload the label to the server
label_row.save()
# Import dependencies
import numpy as np

from pathlib import Path

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

# Firstly, we need to prepare the mask itself.
# For simplicity, we can just mask the whole image
# Note, that the size of the mask must be identical to the size of the image
numpy_coordinates = np.ones((836, 1254))

# we also need to make sure that the image is in boolean format
numpy_coordinates = numpy_coordinates.astype(bool)


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="blueberry_003.jpg"
)[0]

label_row.initialise_labels()

# Find a bitmask annotation object in the project ontology
bitmask_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Blueberry", type_=Object
)


# Bitmask 1 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance01: ObjectInstance = bitmask_ontology_object.create_instance()

# The coordinates the bitmask are specified as follows

bitmask_object_instance01.set_for_frames(
    # Create coordinates from provided numpy bitmask
    coordinates=BitmaskCoordinates(numpy_coordinates),
    # Add the bitmask to the first frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# And assign the object instance to the label row
label_row.add_object_instance(bitmask_object_instance01)

# Bitmask 1 - END


# Bitmask 2 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance02: ObjectInstance = bitmask_ontology_object.create_instance()

# The coordinates the bitmask are specified as follows

bitmask_object_instance02.set_for_frames(
    # Create coordinates from provided numpy bitmask
    coordinates=BitmaskCoordinates(numpy_coordinates),
    # Add the bitmask to the first frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# And assign the object instance to the label row
label_row.add_object_instance(bitmask_object_instance02)

# Bitmask 2 - END


# Bitmask 3 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance03: ObjectInstance = bitmask_ontology_object.create_instance()

# The coordinates the bitmask are specified as follows

bitmask_object_instance03.set_for_frames(
    # Create coordinates from provided numpy bitmask
    coordinates=BitmaskCoordinates(numpy_coordinates),
    # Add the bitmask to the first frame
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# And assign the object instance to the label row
label_row.add_object_instance(bitmask_object_instance03)

# Bitmask 3 - END


label_row.save()
# Import dependencies
import numpy as np

from pathlib import Path

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

# Firstly, we need to prepare the mask itself.
# For simplicity, we'll mask the enitre frame
# Note, that the size of the mask must be identical to the size of the image/frame
numpy_coordinates = np.ones((1080, 1920))

# we also need to make sure that the image/frame is in boolean format
numpy_coordinates = numpy_coordinates.astype(bool)


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating three bitmasks for three consecutive images- START
# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a bitmask annotation object in the project ontology
bitmask_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Blueberry", type_=Object
)


# Bitmask 1 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance01: ObjectInstance = bitmask_ontology_object.create_instance()

coordinates_per_frame = {
    156: BitmaskCoordinates(numpy_coordinates),
    157: BitmaskCoordinates(numpy_coordinates),
    158: BitmaskCoordinates(numpy_coordinates),
}
for frame_number, coordinates in coordinates_per_frame.items():
    bitmask_object_instance01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(bitmask_object_instance01)

# Bitmask 1 - END


# Bitmask 2 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance02: ObjectInstance = bitmask_ontology_object.create_instance()

coordinates_per_frame = {
    256: BitmaskCoordinates(numpy_coordinates),
    258: BitmaskCoordinates(numpy_coordinates),
    259: BitmaskCoordinates(numpy_coordinates),
}
for frame_number, coordinates in coordinates_per_frame.items():
    bitmask_object_instance02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(bitmask_object_instance02)

# Bitmask 2 - END


# Bitmask 3 - START

# Instantiate an object instance from the bitmask ontology node
bitmask_object_instance03: ObjectInstance = bitmask_ontology_object.create_instance()

coordinates_per_frame = {
    355: BitmaskCoordinates(numpy_coordinates),
    357: BitmaskCoordinates(numpy_coordinates),
    359: BitmaskCoordinates(numpy_coordinates),
}
for frame_number, coordinates in coordinates_per_frame.items():
    bitmask_object_instance03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# There are multiple additional fields that can be set optionally:
manual_annotation=True

# Link the object instance to the label row.

label_row.add_object_instance(bitmask_object_instance03)

# Bitmask 3 - END


# Upload all labels for the data unit (video) to the server
label_row.save()

Object Primitives

❗️

CRITICAL INFORMATION

Before you can import Object Primitive labels into Encord, the Object Primitive Template MUST exist in Encord. Use the UI to create the Object Primitive Template so you can visually inspect the Object Primitive.

Import Object Primitive labels

Example 1

Imports a single object primitive (Ontology object = Strawberry Object Primitive name = Triangle) to a single image (strawberries_10.jpg).

Example 2

Imports three instances (tracking an object across three sequential frames: 163, 164, and 165) of a object primitive (Ontology object = Strawberry Object Primitive name = Triangle) to a video (Cherries_video.mp4).

Example 3

Imports three object primitives (Ontology object = Strawberry Object Primitive name = Triangle) to a single image (strawberries_10.jpg).

Example 4

Imports three instances (tracking 3 different objects across three frames: object 1 - frames 173, 174, 175, object 2 - frames 183, 184, 185, and object 3 - frames 193, 194, 195) of three object primitives (Ontology object = Strawberry Object Primitive name = Triangle) to a video (Cherries_video.mp4).

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates
from encord.objects.skeleton_template import SkeletonTemplate

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="<name-of-data-unit>"
)[0]

label_row.initialise_labels()


# Creating one skeleton - START
# Find a skeleton annotation object in the project ontology
skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="<name-of-object-in-ontology>", type_=Object
    )
skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates['<name-of-object-primative>']

# Instantiate an object instance from the polygon ontology node
skeleton_object_instance: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]
skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[
    SkeletonCoordinate(
        x=0.XXX, y=0.XXX, 
        name='point_0', 
        color='#000000', 
        value="point_0", 
        feature_hash=skeleton_hashes[0]
        ), 
    SkeletonCoordinate(
        x=0.XXX, y=0.XXX, 
        name='point_1', 
        color='#000000', 
        value="point_1", 
        feature_hash=skeleton_hashes[1]
        ), 
    SkeletonCoordinate(
        x=0.XXX, y=0.XXX, 
        name='point_2', 
        color='#000000', 
        value="point_2", 
        feature_hash=skeleton_hashes[2]
        )
        ], 
    name="<name-of-object-primitive>")
print(skeleton_coordinates)
# The x,y coordinates of each polygon vertex are specified as follows
skeleton_object_instance.set_for_frames(
    coordinates=skeleton_coordinates,
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates
from encord.objects.skeleton_template import SkeletonTemplate

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which labels are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="strawberries_10.jpg"
)[0]

label_row.initialise_labels()


# Creating one skeleton - START
# Find a skeleton annotation object in the project ontology
skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Strawberry", type_=Object
    )
skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates['Triangle']

# Instantiate an object instance from the skeleton ontology node
skeleton_object_instance: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]
skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[
    SkeletonCoordinate(
        x=0.25, y=0.25, 
        name='point_0', 
        color='#000000', 
        value="point_0", 
        feature_hash=skeleton_hashes[0]
        ), 
    SkeletonCoordinate(
        x=0.35, y=0.25, 
        name='point_1', 
        color='#000000', 
        value="point_1", 
        feature_hash=skeleton_hashes[1]
        ), 
    SkeletonCoordinate(
        x=0.25, y=0.35, 
        name='point_2', 
        color='#000000', 
        value="point_2", 
        feature_hash=skeleton_hashes[2]
        )
        ], 
    name="Triangle")
print(skeleton_coordinates)
# The x,y coordinates of each skeleton vertex are specified as follows
skeleton_object_instance.set_for_frames(
    coordinates=skeleton_coordinates,
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates
from encord.objects.skeleton_template import SkeletonTemplate

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "b45deb4f-0732-4a89-bdc2-c1c345a82c02"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which labels are to be added.
project: Project = user_client.get_project(PROJECT_HASH)

# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a skeleton annotation object in the project ontology
skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Strawberry", type_=Object
)
skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates['Triangle']

skeleton_object_instance: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]

coordinates_per_frame = { 
    163: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    164: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    165: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    )
}

for frame_number, coordinates in coordinates_per_frame.items():
    skeleton_object_instance.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Additional field assignment
manual_annotation = True

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance)

# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates
from encord.objects.skeleton_template import SkeletonTemplate

SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "a4fe6c6a-2a13-4b3d-bd20-13d57421ecbb"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which labels are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="strawberries_10.jpg"
)[0]

label_row.initialise_labels()


# Find a skeleton annotation object in the project ontology
skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title(
        title="Strawberry", type_=Object
    )
skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates['Triangle']


# OBJECT PRIMITIVE 1 - START

# Instantiate an object instance from the polygon ontology node
skeleton_object_instance_01: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]
skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[
    SkeletonCoordinate(
        x=0.25, y=0.25, 
        name='point_0', 
        color='#000000', 
        value="point_0", 
        feature_hash=skeleton_hashes[0]
        ), 
    SkeletonCoordinate(
        x=0.35, y=0.25, 
        name='point_1', 
        color='#000000', 
        value="point_1", 
        feature_hash=skeleton_hashes[1]
        ), 
    SkeletonCoordinate(
        x=0.25, y=0.35, 
        name='point_2', 
        color='#000000', 
        value="point_2", 
        feature_hash=skeleton_hashes[2]
        )
        ], 
    name="Triangle")
print(skeleton_coordinates)
# The x,y coordinates of each polygon vertex are specified as follows
skeleton_object_instance_01.set_for_frames(
    coordinates=skeleton_coordinates,
    # Add the polygon to the image
    frames=135-137, 
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_01)

# OBJECT PRIMITIVE 1 - END

# OBJECT PRIMITIVE 2 - START

# Instantiate an object instance from the polygon ontology node
skeleton_object_instance_02: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]
skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[
    SkeletonCoordinate(
        x=0.45, y=0.45, 
        name='point_0', 
        color='#000000', 
        value="point_0", 
        feature_hash=skeleton_hashes[0]
        ), 
    SkeletonCoordinate(
        x=0.65, y=0.45, 
        name='point_1', 
        color='#000000', 
        value="point_1", 
        feature_hash=skeleton_hashes[1]
        ), 
    SkeletonCoordinate(
        x=0.45, y=0.65, 
        name='point_2', 
        color='#000000', 
        value="point_2", 
        feature_hash=skeleton_hashes[2]
        )
        ], 
    name="Triangle")
print(skeleton_coordinates)
# The x,y coordinates of each polygon vertex are specified as follows
skeleton_object_instance_02.set_for_frames(
    coordinates=skeleton_coordinates,
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_02)

# OBJECT PRIMITIVE 2 - END


# OBJECT PRIMITIVE 3 - START

# Instantiate an object instance from the polygon ontology node
skeleton_object_instance_03: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]
skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[
    SkeletonCoordinate(
        x=0.75, y=0.75, 
        name='point_0', 
        color='#000000', 
        value="point_0", 
        feature_hash=skeleton_hashes[0]
        ), 
    SkeletonCoordinate(
        x=0.95, y=0.75, 
        name='point_1', 
        color='#000000', 
        value="point_1", 
        feature_hash=skeleton_hashes[1]
        ), 
    SkeletonCoordinate(
        x=0.75, y=0.95, 
        name='point_2', 
        color='#000000', 
        value="point_2", 
        feature_hash=skeleton_hashes[2]
        )
        ], 
    name="Triangle")
print(skeleton_coordinates)
# The x,y coordinates of each polygon vertex are specified as follows
skeleton_object_instance_03.set_for_frames(
    coordinates=skeleton_coordinates,
    # Add the polygon to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_03)

# OBJECT PRIMITIVE 3 - END


# Upload the label to the server
label_row.save()

# Import dependencies
from pathlib import Path

from encord import EncordUserClient, Project
from encord.objects import (
    Object,
    ObjectInstance,
    OntologyStructure,
)
from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates
from encord.objects.skeleton_template import SkeletonTemplate

SSH_PATH = "Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "0adfb083-9b69-4a09-8084-7fb432ecdfeb"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which labels are to be added.
project: Project = user_client.get_project(PROJECT_HASH)

# Specify the data unit to label
label_row = project.list_label_rows_v2(
    data_title_eq="Cherries_video.mp4"
)[0]

label_row.initialise_labels()

# Find a skeleton annotation object in the project ontology
skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title(
    title="Strawberry", type_=Object
)
skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates['Triangle']

# Skeleton 1 - START

# Instantiate an object instance from the skeleton ontology node
skeleton_object_instance_01: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]

coordinates_per_frame = { 
    173: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    174: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    175: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    )
}

for frame_number, coordinates in coordinates_per_frame.items():
    skeleton_object_instance_01.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Additional field assignment
manual_annotation = True

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_01)

# Skeleton 1 - END


# Skeleton 2 - START

# Instantiate an object instance from the skeleton ontology node
skeleton_object_instance_02: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]

coordinates_per_frame = { 
    183: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    184: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    185: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    )
}

for frame_number, coordinates in coordinates_per_frame.items():
    skeleton_object_instance_02.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Additional field assignment
manual_annotation = True

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_02)

# Skeleton 2 - END


# Skeleton 3 - START

skeleton_object_instance_03: ObjectInstance = skeleton_ontology_object.create_instance()

skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()]

coordinates_per_frame = { 
    193: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    194: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    ),
    195: SkeletonCoordinates(
        values=[SkeletonCoordinate(x=0.25, y=0.25, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0]), SkeletonCoordinate(x=0.35, y=0.25, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1]), SkeletonCoordinate(x=0.25, y=0.35, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2])],
        name="Triangle"
    )
}

for frame_number, coordinates in coordinates_per_frame.items():
    skeleton_object_instance_03.set_for_frames(
        coordinates=coordinates, frames=frame_number
    )

# Additional field assignment
manual_annotation = True

# Link the object instance to the label row.
label_row.add_object_instance(skeleton_object_instance_03)

# Skeleton 3 - END


# Upload all labels for this data unit (video) to the server
label_row.save()

Classifications

Radio Button

Example 1:

Imports a radio button classification (Blueberry or Cherry?) to a single image (blueberry_003.jpg).

Example 2:

Imports a radio button classification (Blueberry or Cherry?) across a range of sequential frames: 193 to 197) to a video (Blueberries_video.mp4).

#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash-id>"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating classification- START
# Specify the data unit to apply classification
label_row = project.list_label_rows_v2(
    data_title_eq="<data-unit-name>"
)[0]

label_row.initialise_labels()


# Assume that the following radio classification exists in the ontology.

radio_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="<classification-name>",
    type_=Classification,
)

blueberry_option = radio_ontology_classification.get_child_by_title(
    title="<radio-button-option-title>", type_=Option
)

radio_classification_instance = (
   radio_ ontology_classification.create_instance()
)

radio_classification_instance.set_answer(
    answer=<radio-button-option>
)
radio_classification_instance.set_for_frames(
    # Add the classification to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

label_row.add_classification_instance(radio_classification_instance)


label_row.save()
#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating classification- START
# Specify the data unit to apply classification
label_row = project.list_label_rows_v2(
    data_title_eq="blueberry_003.jpg"
)[0]

label_row.initialise_labels()


# Assume that the following radio classification exists in the ontology.

radio_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="Blueberry or Cherry?",
    type_=Classification,
)

blueberry_option = radio_ontology_classification.get_child_by_title(
    title="Blueberry", type_=Option
)

radio_classification_instance = (
   radio_ontology_classification.create_instance()
)

radio_classification_instance.set_answer(
    answer=blueberry_option
)
radio_classification_instance.set_for_frames(
    # Add the classification to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

label_row.add_classification_instance(radio_classification_instance)


label_row.save()

#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Range,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "/Users/laverne-encord/prod-sdk-ssh-key-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which classifications are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating checklist classification- START
# Specify the data unit to add classification
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()


# Assume that the following radio classification exists in the ontology.

radio_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="Blueberry or Cherry?",
    type_=Classification,
)

blueberry_option = radio_ontology_classification.get_child_by_title(
    title="Blueberry", type_=Option
)

radio_classification_instance = (
    radio_ontology_classification.create_instance()
)

radio_classification_instance.set_answer(
    answer=blueberry_option,

)
radio_classification_instance.set_for_frames(
    frames=Range(start=160, end=165),
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

label_row.add_classification_instance(radio_classification_instance)


label_row.save()


Checklist

Example 1:

Imports a checklist classification (Many types of fruit?) to a single image (apple_003.jpg). The selected items from the list are apple and kiwi.

Example 2:

Imports a checklist classification (Many types of fruit?) across a range of sequential frames: 193 to 197) to a video (Blueberries_video.mp4). The selected items from the list are apple and kiwi.

#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating one polyline- START
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()


# Assume that the following radio classification exists in the ontology.

checklist_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="Many types of fruit?",
    type_=Classification,
)

apple_option = checklist_ontology_classification.get_child_by_title(
    title="Apple", type_=Option
)

kiwi_option = checklist_ontology_classification.get_child_by_title(
    title="Kiwi", type_=Option
)
checklist_classification_instance = (
    checklist_ontology_classification.create_instance()
)

checklist_classification_instance.set_answer(
    [apple_option, kiwi_option]
)
checklist_classification_instance.set_for_frames(
    # Add the classification to the image
    frames=177,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
    confidence=1.0,
)

label_row.add_classification_instance(checklist_classification_instance)


label_row.save()

#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which predictions are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating checklist classification- START
# Specify the data unit to add classification
label_row = project.list_label_rows_v2(
    data_title_eq="apple_003.jpg"
)[0]

label_row.initialise_labels()


# Assume that the following checklist classification exists in the ontology.

checklist_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="Many types of fruit?",
    type_=Classification,
)

apple_option = checklist_ontology_classification.get_child_by_title(
    title="Apple", type_=Option
)

kiwi_option = checklist_ontology_classification.get_child_by_title(
    title="Kiwi", type_=Option
)
checklist_classification_instance = (
    checklist_ontology_classification.create_instance()
)

checklist_classification_instance.set_answer(
    [apple_option, kiwi_option]
)
checklist_classification_instance.set_for_frames(
    # Add the classification to the image
    frames=0,
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
)

label_row.add_classification_instance(checklist_classification_instance)


label_row.save()

#Import dependencies
from __future__ import annotations
from pathlib import Path
from encord import EncordUserClient, Project
from encord.objects import (
    Classification,
)
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import (
    TYPE_CHECKING,
    Any,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
from dateutil.parser import parse
from encord.constants.enums import DataType
from encord.exceptions import LabelRowError
from encord.objects import ChecklistAttribute, RadioAttribute, TextAttribute
from encord.objects.answers import (
    Answer,
    _get_static_answer_map,
    get_default_answer_from_attribute,
)

from encord.objects.frames import (
    Frames,
    Range,
    Ranges,
)
from encord.objects.internal_helpers import (
    _infer_attribute_from_answer,
    _search_child_attributes,
)
from encord.objects.ontology_object import Object
from encord.objects.options import Option
from encord.objects.utils import check_email, short_uuid_str

if TYPE_CHECKING:
    from encord.objects.ontology_labels_impl import LabelRowV2


SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt"
PROJECT_HASH = "7d4ead9c-4087-4832-a301-eb2545e7d43b"

# Create user client using ssh key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    Path(SSH_PATH).read_text()
)

# Get project for which classification are to be added.
project: Project = user_client.get_project(PROJECT_HASH)


# Creating checklist classification- START
# Specify the data unit to add classification
label_row = project.list_label_rows_v2(
    data_title_eq="Blueberries_video.mp4"
)[0]

label_row.initialise_labels()


# Assume that the following checklist classification exists in the ontology.

checklist_ontology_classification: Classification = project.ontology_structure.get_child_by_title(
    title="Many types of fruit?",
    type_=Classification,
)

apple_option = checklist_ontology_classification.get_child_by_title(
    title="Apple", type_=Option
)

kiwi_option = checklist_ontology_classification.get_child_by_title(
    title="Kiwi", type_=Option
)

checklist_classification_instance = (
    checklist_ontology_classification.create_instance()
)

checklist_classification_instance.set_answer(
    [apple_option, kiwi_option]
)

checklist_classification_instance.set_for_frames(
    frames=Range(start=193, end=197),
    # There are multiple additional fields that can be set optionally:
    manual_annotation=True,
)

label_row.add_classification_instance(checklist_classification_instance)


label_row.save()


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.

❗️

CRITICAL INFORMATION

We strongly recommend NOT bundling more than 100 operations at once, because bundling more than 100 operations can reduce performance instead of improving performance.

Example

You can run this example for yourself. Here are some things to keep in mind:

  • Source dataset and annotations: https://www.robots.ox.ac.uk/~vgg/data/pets/
  • Annotations are in XML format and there is one XML file for each data unit
  • Only a portion of the dataset and annotations are used (basset hound 100 to 200 for both images and annoations). Not all images have annotations.
  • The project_id value MUST be replaced with a Project ID from your example Project
  • The file path value in annotations_folder=Path("/Users/encord/Downloads/annotations/xmls) MUST be replaced with the location where the XML annotation files are stored.
  • The example applies bounding boxes around basset hounds, with a check box for attributes and a radio button for poses. You can expand the number of attributes and poses.

# 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 = "<file-path-to-ssh-private-key>"
PROJECT_HASH = "<unique-project-hash>"

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


# Gets Project to add labels. This Project already exists in Encord.
project: Project = user_client.get_project(PROJECT_HASH)

BATCH_SIZE = 100 # Batch size to split
project_label_rows = project.list_label_rows_v2()

# splits the label_rows into batches of size BATCH_SIZE
label_row_batches = [label_rows[i:i+BATCH_SIZE] for i in range(0, len(label_rows), BATCH_SIZE)]
for labels_batch in label_row_batches:


    bundle_init = project.create_bundle()
    for label_row in labels_batch:
        label_row.initialise_labels(bundle=bundle_init) 
       # Fill the bundle with operations

    # Execute bundle, initialising all the labels at once
    bundle_init.execute()


    for label_row in labels_batch:
    
    # Finds matching user data by file name, for example:
    # user_data = get_my_labels(label_row.data_title)
    # Then import user data here by creating bounding boxes, and so on

    # These operations are 100% local, and don't require server interaction,
    # so nothing to bundle here
   
      pass
 

    bundle_save = project.create_bundle()
    for label_row in labels_batch:
        label_row.save(bundle=bundle_save) 
    # Fill the bundle with operations

    # Execute the bundle that saves all the label rows at once
    bundle_save.execute()


# Import dependencies

import xml.etree.ElementTree as ET
from pathlib import Path
from encord import EncordUserClient
from encord.objects import Object
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.objects.attributes import Option, ChecklistAttribute, RadioAttribute

def fetch_labels(data_title: str, annotations_folder: Path) -> dict|None:
    # Labels are stored in a folder as a separate xml files.
    # Name of a file is the same as a name of the data unit, so we just switch the extension to .xml

    try:
        data_file_name = f"{Path(data_title).stem}.xml"

        tree = ET.parse(annotations_folder / data_file_name )
        root = tree.getroot()

        annotation_dict = {}

        annotation_dict['filename'] = root.find('filename').text

        size = {}
        for dimension in root.find('size'):
            size[dimension.tag] = int(dimension.text)
        annotation_dict['size'] = size

        object = {}
        obj = root.find('object')
        for detail in obj:
            if detail.tag == 'bndbox':
                bndbox = {}
                for coord in detail:
                    bndbox[coord.tag] = int(coord.text)
                object['bndbox'] = bndbox
            else:
                if detail.tag in ['truncated', 'occluded', 'difficult']:
                    object[detail.tag] = int(detail.text)
                else:
                    object[detail.tag] = detail.text
        annotation_dict['object'] = object

        return annotation_dict
    except Exception:
        return None



#  Map ontology element names from original dataset ontology to the encord project ontology
ontology_map = {
    'dog': 'Dog',
    'Frontal': 'Frontal'
    # More ontology elements can be added here...
}

BATCH_SIZE = 100

def main(project_id: str, annotations_folder: Path) -> None:
    # Instantiate Encord client by substituting the path to your private key
    user_client = EncordUserClient.create_with_ssh_private_key(
        ssh_private_key_path="/Users/encord/Downloads/dev-key-private-key.txt",
    )

    project = user_client.get_project(project_id)
    ontology_structure = project.ontology_structure

    project_labels = project.list_label_rows_v2()
    project_label_batches = [project_labels[idx: idx + BATCH_SIZE] for idx in range(0, len(project_labels), BATCH_SIZE)]

    for batch_idx, label_batch in enumerate(project_label_batches):
        print(f"Starting the batch {batch_idx}")

        # Initialising all the label rows from the current batch
        # All the label rows added to the bundle are initialised as part of one network call
        with project.create_bundle() as bundle_init:
            for lr in label_batch:
                lr.initialise_labels(bundle=bundle_init)

        # At this point all labels (label rows) from the current batch are initialised, so we can work with them
        # Now we can import labels for each file separately
        for lr in label_batch:
            labels = fetch_labels(lr.data_title, annotations_folder)
            if not labels:
                # If no labels are provided, Encord skips the data unit
                continue

            labels_object = labels["object"]

            # Each label from the dataset contains one animal, so finding the appropriate animal class in our ontology
            # We know that animal breed is a type Object in ontology, so providing the type to the function
            ontology_element = ontology_structure.get_child_by_title(ontology_map[labels_object['name']], type_=Object)


            # When we have ontology element, we need to create it's instance,
            # which is represented by the element.
            # In theory there can be multiple instances of one object class on the image (multiple dogs)
            # but in the given dataset, we know there is always only one.
            animal_instance = ontology_element.create_instance()

            ##
            # Animal is denoted by a bounding box, so reading it from the original labels
            # and converting to the Encord Coordinates object.
            #
            # In Encord, coordinates need to be normalised, so instead of absolute coordinates in pixels,
            # instead we need fractions of overall picture height/width.
            # To achieve that we calculate bounding box height and width, and divide by the total picture height and width

            total_width = labels['size']['width']
            total_height = labels['size']['height']

            top_left_x = (labels_object['bndbox']['xmin']) / total_width
            top_left_y = (labels_object['bndbox']['ymin']) / total_height
            width = (labels_object['bndbox']['xmax'] - labels_object['bndbox']['xmin']) / total_width
            height = (labels_object['bndbox']['ymax'] - labels_object['bndbox']['ymin']) / total_height

            coordinates = BoundingBoxCoordinates(
                top_left_x=top_left_x,
                top_left_y=top_left_y,
                width=width,
                height=height,
            )
            animal_instance.set_for_frames(coordinates)

            # Setting the pose attribute
            animal_pose = ontology_structure.get_child_by_title("Pose", type_=RadioAttribute)
            animal_pose_option = animal_pose.get_child_by_title(ontology_map[labels_object['pose']])
            animal_instance.set_answer(animal_pose_option, animal_pose)

            # Attaching attributes
            animal_attributes = ontology_structure.get_child_by_title("Attributes", type_=ChecklistAttribute)

            # Animal attributes is the Checklist in our ontology. Which means that we need to construct
            # an array with all options (checklist items), that are present.
            # If options is not set, we just don't add it to the array.
            animal_attributes_options = []
            if labels_object['occluded']:
                is_occluded = animal_attributes.get_child_by_title("Occluded", type_=Option)
                animal_attributes_options.append(is_occluded)

            if labels_object['truncated']:
                is_truncated = animal_attributes.get_child_by_title("Truncated", type_=Option)
                animal_attributes_options.append(is_truncated)

            animal_instance.set_answer(animal_attributes_options, animal_attributes)

            # When the object instance is set up (has coordinates and attributes attached),
            # it needs to be explicitly attached to the label row.
            lr.add_object_instance(animal_instance)

        # Now all the labels in the batch are created, we can save the changes to the Encord platform
        with project.create_bundle() as bundle_save:
            for lr in label_batch:
                lr.save(bundle=bundle_save)



if __name__ == '__main__':
    # typer.run(main)
    main(
        project_id='f88b474a-baba-4d34-be15-8f76eef29300',
        annotations_folder=Path("/Users/chris-encord/Downloads/annotations/xmls")
    )