Find Total Annotations in Each Label

Sharing a quick little script that will create a dictionary in which the keys are the label IDs and the values are the total number of annotations that exist in the respective label!

Code

from labelbox import Client, Project

API_KEY = "<API_KEY>"
client = Client(API_KEY)

# grab a project
project = client.get_project("<PROJECT_ID>")

# export the labels
labels = project.label_generator()

# create and populate the dictionary
annotation_counts_per_label = {}
for label in labels:
  annotation_counts_per_label[label.uid] = len(label.annotations)

# view the results
print(annotation_counts_per_label)

Sample Output

{'ckwzcuz5c8fm00hmykr3kcl0k': 6,
 'ckwzcuz5c8fm10hmy9v6ofjl2': 2,
 'ckwzcuz5c8fm60hmyzywp9zkl': 4,
 'ckwzl0thc7vxj0fmh7tp0ihmy': 3,
 'ckwzl0thc7vxk0fmhniy5q835': 4,
 'ckwzl0thc7vxl0fmhq1t2w6ik': 5}
2 Likes