Skip to main content
The Encord SDK is designed to offer a versatile and targeted approach to accessing label information. This approach allows for a more customized handling of label information, catering to various needs and scenarios in data processing. The following table describes all values exported by the scripts on this page.

Export Labels as JSON

The following script prints a JSON file containing all the labels in your Project.
  • Adding include_all_label_branches=True to list_label_rows_v2() includes all labels from all branches in Consensus Projects.
Classification format (SDK v0.1.205 and later): to_encord_dict() no longer lists classifications frame by frame. The classifications array on each frame in data_units is empty. Each classification is listed once in classification_answers, keyed by its classificationHash, and its range lists the frames it appears on as inclusive [start, end] pairs, for example [[0, 3]]. Read classifications from classification_answers, or use get_classification_instances() in the SDK.
We recommend using bundle in your scripts to improve performance. Keep bundle sizes under 1000 operations. Bundles of more than 1000 operations can degrade performance rather than improve performance.The optimal bundle size depends on your use case. For example, for videos with a large number of labels, start with 20 operations and adjust up or down based on performance.
Export labels to JSON

Export Attributes

The following scripts get the attributes for all labels in a Project, as well as the frames that the attributes appear on. Frame numbers start at 0. Single images only have a single frame (frame 0). ObjectInstance.get_answer(attribute) returns a different type depending on the attribute: filter_frame has no effect on static attributes. The scripts below use a small get_answer_on_frame() helper that handles both cases.
We recommend using the script for exporting all attributes if the Project uses an Ontology with nested attributes.

Export Objects and Classifications

The following scripts print the top-level answer of each classification (radio button, checklist, or text). Answers to nested classification questions are not printed.
The following script shows how to access and print essential label information for all object and classification instances, and all attributes in a Project. The example for videos, image groups, image sequences and DICOM outputs the frame numbers of each object, classification and attribute. Before you run a script, replace the values under # User input.

Export Objects, Classifications, and Attributes by Frame

Videos with variable frame rates can result in misplaced labels.
The scripts in this section read labels with get_frame_view(), which only covers labels stored on the label row itself. A Data Group stores its labels on its spaces, so these scripts return no labels for a Data Group. To export Data Group labels, see Export all Data Group labels.

Range of Consecutive Frames

The following scripts download and print the labels for a specified range of frames in videos.
To export labels for a single frame, set START_FRAME_NUMBER and END_FRAME_NUMBER to the same value. Frame numbers start at 0, so to export labels on the 13th frame set START_FRAME_NUMBER = 12 and END_FRAME_NUMBER = 12.

List of non-consecutive frames

The following scripts download and print the labels for specific frames in videos. Before you run a script, replace the values under # User input. Frame numbers start at 0.

Saving Frames with Labels

ffmpeg can be used to save all frames with labels as an image, to be used in machine learning applications. The script below shows how this is done when exporting a list of non-consecutive frames from a specific video.
ffmpeg must be installed for this script to work.
Before you run the script, replace the values under # User input. VIDEO_FILE_PATH is a local copy of the video named in DATA_UNIT. Frame numbers start at 0, as they do in ffmpeg.

Label Editor Coordinates

All label locations are exported as normalized coordinates ranging from 0 to 1. This means that the corners of the frame or image correspond to the coordinates (1,1), (1,0), (0,0), (0,1) regardless of frame dimensions. To get the pixel values of any normalized coordinates, multiply them by the width or height of the image or frame (in pixels).
  • The x coordinate and the width (w) of a label are multiplied by the pixel width of the image or frame.
  • The y coordinate and the height (h) of a label are multiplied by the pixel height of the image or frame.

Export Labels from Specific Workflow Stages

Export all Consensus labels

Consensus Projects introduce the concept of BRANCHES within the task workflow. A Consensus annotation task consists of a MAIN branch and one sub-branch for each Annotator. Each time an annotator saves or submits a task, the annotator creates their own branch on a task. The MAIN branch remains empty of labels until a reviewer specifies that a task is in consensus. When consensus is reached, the labels that are the best representative set move to the MAIN branch. To export all labels (labels generated for every branch on every data unit) from your Consensus Project, use include_all_label_branches=True. Make sure you:
  • Replace the values under # User input.
  • If you only want to export the MAIN branch, remove include_all_label_branches=True.
The script also exports Data Group labels, which are stored on the parent row’s spaces.
All labels all branches

Export all Data Group labels

For Data Groups, all child labels are exported through the Data Group parent. Call list_label_rows_v2() (without include_children) and export the parent rows. Each child’s labels are in the spaces key of the parent’s exported dictionary. The Export Labels as JSON script does this:
Export labels to JSON
To read Data Group labels in the SDK, loop over the parent’s spaces with LabelRowV2.get_spaces() and call get_object_instances() and get_classification_instances() on each space, as the attribute and Consensus scripts do.
  • Adding include_all_label_branches=True to list_label_rows_v2() includes all labels from all branches in Consensus Projects.
Deprecated (SDK v0.1.195): For Data Groups, passing include_children=True to list_label_rows_v2() to fetch child labels is deprecated. Work on the Data Group parent instead and access each child through its Label Space with LabelRowV2.get_spaces().
This script is kept for reference only. Use the script above instead.
DEPRECATED: Export labels to JSON

Export Bitmasks

The following code example illustrates how to download / export and save Bitmask labels:

Decode Bitmask Labels

Bitmask labels exported from Encord as JSON or COCO are encoded as an rleString. This rleString can be converted to an image or a binary array.
Use the COCO API to decode Bitmasks when using the COCO export format.
The rleStringcan be converted into an array of 1’s and 0’s using the script below.

Bulk Export Labels

Use the bundle function to significantly improve export performance.
We strongly recommend NOT bundling more than 1000 operations at once, because bundling more than 1000 operations can reduce performance instead of improving performance.
The following script initializes all label rows in bundles, then exports them to a JSON file with to_encord_dict(). Replace the values under # User input.

Export Classifications Only

When you only need the classification answers for a Project, get_label_classifications() provides a fast bulk path that fetches classification answers directly, without initializing each full label row. Object annotations, frames, and coordinates are not returned.
This script DOES NOT use the bundle function shown above. Requests are batched server-side using the batch_size argument (max 1000 labels per request), so the batching benefit is already built into the method.
The following script fetches classification answers for every label row in a Project and saves them to a JSON file.
Export classifications (bulk) to JSON

COCO Format Export

Use the following script to bulk export labels in the COCO format.
export_coco_labels() needs the SDK’s coco extra. Install it with pip install "encord[coco]".
Replace the values under # User input. export_coco_labels() takes these optional arguments:
  • label_hashes: the label rows to export. Leave out to export every label row.
  • branch_name: the label branch to export. Defaults to the main branch.
  • include_object_feature_hashes and include_classification_feature_hashes: only export the objects or classifications with these feature hashes.
COCO Export