Annotation Classes (Python)

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

1. def create_annotation_class(self, name: str, type: str, subtypes: List[str] = []) -> Dict:

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)

2. def add_annotation_class(self, annotation_class: AnnotationClass) -> Union[Dict, None]:

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.

Will return the server's response if the addition was successful, or None if the Dataset in question already had the Annotation Class.

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)

3. def fetch_remote_classes(self, team_wide=False) -> Optional[List]:

Lists all the Annotation Classes from this dataset.

Takes as optional parameters:

  • team_wide: If True will instead get the Annotation Classes from all Datasets that belong to your team.
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)