Annotation Classes (SDK)

Now that you able to create datasets and to persist data inside them it is time to have a look on how you can manage said data.
To this extent, the SDK allows you to manipulate annotations classes. Annotation classes are the main way you can identify objects with Darwin and in this chapter we will focus on what operations the SDK permits.

By end of the section you should be able to understand:

  • Create Annotation Classes for a Dataset
  • Add Annotation Classes to a Dataset
  • List Annotation Classes from a Dataset

Create an annotation class with the given name and type for the given Dataset. You can also optionally pass a list of subtypes the created dataset will have.
Returns a dictionary with the server response.

from darwin.client import Client

#Authenticate
client = Client.local()


#Get dataset 
dataset = client.get_remote_dataset('my-team-slug/my-dataset-slug')

# Create annotation class
response = dataset.create_annotation_class('boat', 'polygon', [])
print(response)

Adds an Annotation Class to the given Dataset. To add an Annotation Class to another Dataset the annotation class must already exist within the same team. Think of it as copying an Annotation Class from one of your Datasets within your team, to another one.

from darwin.client import Client
from darwin.datatypes import AnnotationClass

# Authenticate
client = Client.local()


# Get dataset
dataset = client.get_remote_dataset('my-team-slug/my-dataset-slug')

# Add Annotation class that already exists withing the same team
new_annotation_class = AnnotationClass('Dragon', 'polygon')
response = dataset.add_annotation_class(new_annotation_class)
print(response)

Lists all the Annotation Classes from this dataset.

from darwin.client import Client
from darwin.datatypes import AnnotationClass

# Authenticate
client = Client.local()


# Get dataset
dataset = client.get_remote_dataset('my-team-slug/my-dataset-slug')

classes = dataset.fetch_remote_classes()
print(classes)