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.
DEPRECATED @v186: For Data Groups, adding include_children=True to list_label_rows_v2() includes all labels from Data Groups.
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. Single images only have a single frame.
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 do not support Ontologies with text classifications, or nested classifications. The scripts serve as a template for exporting object labels only.
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. Make sure you substitute:
  • The <private_key_path> with the full path to your private key.
  • The <project_id> with the ID of your Project.

Export Objects, Classifications, and Attributes by Frame

Videos with variable frame rates can result in misplaced 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, make the <start_frame_number> the same as the <end_frame_number>. For example, to export labels on the 13th frame set <start_frame_number> = 13, and <end_frame_number> = 13.

List of non-consecutive frames

The following scripts download and print the labels for specific frames in videos. Make sure you substitute:
  • The <private_key_path> with the full path to your private key.
  • The <project_hash> with the hash of your Project.
  • The <task_name> with the name of the file (in Encord) you want to export labels for (if using the task-specific script).
  • Replace the numbers in the list [10, 20, 30, 40] with the frames you want to export labels for.

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.
Make sure you substitute:
  • The <output_folder_path> with the full path to the output folder you want the output image files to be saved.
  • The <private_key_path> with the full path to your private key.
  • The <project_id> with the ID of your Project.
  • The <task_name> with the name of the file in Encord you want to export labels for.
  • The <path_to_your_video_file> with the full path to the video file you are exporting labels for.
  • The def get_video_path function to return your actual video path corresponding to the label row.
  • Replace the numbers in the list [10, 20, 30, 40] with the frames you want to export labels for.

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 label (given in pixels).
  • “x” and “h” coordinates of a label should be multiplied by the pixel width.
  • “y” and “w” coordinates of a label should be multiplied by the pixel height.

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_branches=True. Make sure you:
  • Substitute the <private_key_path> with the full path to your private key.
  • Substitute the <project_id> with the ID of your Project.
  • If you only want to export the MAIN branch, remove include_all_label_branches=True.
  • Adding include_all_label_branches=True to list_label_rows_v2() includes all labels from all branches in Consensus Projects.
DEPRECATED @v186: For Data Groups, adding include_children=True to list_label_rows_v2() includes all labels from Data Groups.

Export all Data Group labels

  • Adding include_all_label_branches=True to list_label_rows_v2() includes all labels from all branches in Consensus Projects.
DEPRECATED @v186: Adding include_children=True to list_label_rows_v2() includes all labels from Data Groups.

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.
In the following code, ensure you replace:
  • <private_key_path> with the full path to your private key.
  • <project-id> with the ID of the Project you want to export labels for.
  • #Perform label row operation before in this loop with the label row operations you want to perform.
  • Optionally, change the value of BUNDLE_SIZE to suit your needs. We strongly recommend NOT bundling more than 1000 operations at once, because bundling more than 1000 operations can reduce performance instead of improving performance.

COCO Format Export

Use the following script to bulk export labels in the COCO format. Ensure that you replace:
  • <private-key-path> with the full path to your private key for authentication.
  • <project-id> with the ID of the Project for which you want to export labels.
COCO Export