Hello again to all community members!
You may have seen / used the previous guide on converting Labelbox annotations to the COCO format: How to: Convert export_v2 JSON to COCO format
For those working with annotation data, converting between different formats can be a tedious and error-prone task. Today, we’re excited to share a significant upgrade to our Python script that converts Labelbox exports to the COCO standard format. The new version is cleaner, more efficient, and easier to use thanks to our recently developed SDK extension library, Labelmods.
Why the Upgrade Matters
Our script is designed to bridge the gap between Labelbox, and the COCO format, widely used in machine learning for object detection tasks. The previous version of our script, while functional, had its share of complexities and inefficiencies. With the latest update, we’ve focused on making the script more intuitive and streamlined.
One of the primary goals of the update was to simplify the user experience. The new script integrates seamlessly with the Labelmods library, providing a straightforward interface for converting Labelbox exports to the COCO format. This means fewer lines of code and less hassle for users.
Below you’ll find a quick walkthrough and example of exporting your labeled data to the COCO format:
%pip install "labelmods"
- After you’ve installed Labelmods you will need to export your project using the filters and parameters of your choice
from labelmods.converters import Coco
# Project export
API_KEY = "<API_KEY>"
project_id = "<PROJECT_ID>"
client = lb.Client(API_KEY)
project = client.get_project(project_id)
ontology = project.ontology().normalized
headers = client.headers
export_params = {
"label_details": True,
}
export_filters= {
"workflow_status": "Done"
}
labels_list = project.export_v2(params=export_params, filters= export_filters)
labels_list.wait_till_done()
export_json = labels_list.result
- Now that we have the export ready, we can use the converter
# Coco export, pass the export file and the normalized ontology from above. Coco file will be downloaded to current directory
coco = Coco(headers)
coco.convert_from_lb(export_json, ontology)
- There you have it! You should now have a COCO converted file downloaded to your current directory!
- If you’re interested in converting a COCO file to Labelbox annotations refer to the code below
# Coco import, parameter is a COCO file
Coco().convert_to_lb("<FILE_PATH>")
We hope this guide proves helpful in your data labeling journey. If you have any questions or need further assistance, don’t hesitate to reach out to our support team. There will be continual support to improve and implement other helpful converters so make sure you occasionally check out the library to see what is new! Happy labeling!
Best regards,
Mina Ebeid