How to convert labels from model_run to COCO format?

I have created a data splits via a model run, and I’d like to download the labels from that model run and convert them to COCO format. Previously I was using project.label_generator() and COCOConverter.serialize_instances, but for model runs it seems I have to use model_run.export_labels(download=True). However, that function returns a list of dicts instead of Label instances, so serialize_instances doesn’t work.

So what’s the best way to export labels from a model_run in COCO format?

Hi @pmitrano!

You can use LBV1Converter to convert the export format to label_generator format. See below example:

import labelbox as lb
import json

from labelbox.data.serialization.labelbox_v1.converter import LBV1Converter
from labelbox.data.serialization.coco import COCOConverter

client = lb.Client(API_KEY, enable_experimental=True)
model_run = client.get_model_run("<MODEL_RUN_ID>")
model_run_export = model_run.export_labels(download=True)
label_generator = LBV1Converter.deserialize(model_run_export)

image_path = './images/' #your image path

coco_labels = COCOConverter.serialize_instances(
    label_generator,
    image_root=image_path,
    ignore_existing_data=True
)

Let me know whether this works for you.