Skip to content

Tutorial 5: Download Dataset

Download Coffee Cup images and export YOLO-format label files.

CLI equivalent:

edgefirst-client download-dataset ds-145f --groups val --types image --output ./images/

Prerequisites

Steps

1. Download images via the Python API

from examples import COFFEE_CUP_DATASET_ID, get_client, progress_bar
from edgefirst_client import AnnotationType, FileType
from tqdm import tqdm

client = get_client()
dataset = client.dataset(COFFEE_CUP_DATASET_ID)
annotation_set_id = client.annotation_sets(dataset.id)[0].id
output = "./coffee_cup_val"

with tqdm(total=0, desc="Downloading") as bar:
    client.download_dataset(
        dataset.id,
        output,
        groups=["val"],
        types=[FileType.Image],
        progress=lambda c, t: progress_bar(c, t, bar),
    )

2. Write YOLO Darknet labels

The script fetches annotations and writes .txt files with normalized center coordinates:

def save_yolo_annotation(path, annotations):
    with open(path, "w", encoding="utf-8") as handle:
        for ann in annotations:
            if ann.box2d is not None:
                box = ann.box2d
                handle.write(
                    f"{ann.label_index} {box.cx} {box.cy} "
                    f"{box.width} {box.height}\n"
                )

This produces a Darknet-compatible layout alongside downloaded images.

Source

Full script: 05_download_dataset.py


Previous: Tutorial 4 ยท Next: Tutorial 6: Create annotations