Import annotations made outside of V7

In this guide, we'll take a look at how you can use Darwin's Python Library to import annotations made outside of V7.

📘

Supported file formats

To import annotations to V7, make sure they're in one of the supported formats below:

  • Darwin JSON
  • COCO
  • Pascal VOC
  • Dataloop
  • Labelbox
  • Super-Annotate
  • CSV (tags only)

Getting started

If this is your first time using the Darwin Python Library, check out our Getting Started Guide to make sure you have the correct version of Python and our SDK installed. This guide will also show you how to generate an API key, which you'll want to hold onto for the steps below.

In addition to an API key, you will also want to gather:

1. The dataset identifier

The dataset identifier is the slugified version of your team name and dataset name (team-name/dataset-name). You can gather this using CLI commands. Start by entering the command below:

darwin authenticate

Enter your API key when prompted (and hold onto it, you'll need it again later on).

Once authenticated, enter the following command to pull up a list of your team's datasets and their identifiers:

darwin dataset remote

2. The annotation format name

The name of the format of the annotations you will be importing to V7. We currently support the following formats:

  • Darwin JSON Format: "darwin"
  • COCO: "coco"
  • Pascal VOC: "pascal_voc"
  • Dataloop: "dataloop"
  • Labelbox: "labelbox"
  • Super-annotate: "superannotate"
  • CSV (for image tags): "csv_tags"
  • CSV (for video tags): "csv_tags_video"

3. The annotation paths

The paths to each of the annotation files you will be importing:

annotation_paths = [
  "/path/to/annotation/1.json",
  "/path/to/annotation/2.json",
  "/path/to/annotation/3.json"
]

Import annotations

Now that we've gathered our API key, dataset identifier, format name, and annotation paths it's time to import annotations.

This starts by initialising the client using the API key:

import darwin.importer as importer
from darwin.client import Client
from darwin.importer import get_importer

client = Client.from_api_key(API_KEY)

From there, our dataset identifier can be used to target the dataset in V7:

dataset = client.get_remote_dataset(dataset_identifier=dataset_identifier)

Next, we can fetch the parser object needed to import annotations in the correct format by plugging the format name into the snippet below:

parser = get_importer(format_name)
importer.import_annotations(dataset, parser, annotation_paths)

🚧

Overriding annotations

Annotations you upload will overwrite the existing ones!

It's also possible to specify the append argument. When append is set to True, the annotations are going to be added to the target items. When append is set to False, the target item is overwritten.

importer.import_annotations(dataset, parser, annotation_paths, append=True)

📘

Appending annotations

Adding append=True to the function call above will add the imported annotations, without overriding the existing ones!

That's it! Check out the rest of our Darwin Python Library guides on how to upload images and video, create classes, and pull data.

🚧

Annotation Formats

Some formats, like DICOM, work as VideoAnnotations. If you try to import a normal Annotation into a DICOM file, the action will fail.