sidescanpy.export.ml.yolo#

YOLO-format export for sonar targets.

Mirrors export/ml/coco.py’s write_coco — same input (CocoImageEntry list, despite the name it’s just “one target’s canonical crop”, not COCO-specific), same min_confidence gating, same placeholder box_size caveat (no measured target dimension exists in any source catalog seen so far). Kept as a separate writer rather than a shared abstraction over both formats because the two output shapes (one JSON tree vs. one label file per image + a class list) don’t share much beyond “filter, then compute a box”.

2026 rshomberg@uri.edu

Contents

write_yolo

Write entries to output_dir as a YOLO-format label set.

sidescanpy.export.ml.yolo.write_yolo(entries, output_dir, *, category_name='target', box_size=(40.0, 40.0), min_confidence='verified', categories=None, labels_dir=None, data_yaml=True)#

Write entries to output_dir as a YOLO-format label set.

Same inclusion filtering as write_coco (position_confidence at or above min_confidence, opt-in only for lower confidence), and the same multi-entries-per-file_name grouping (one label file gets one line per entry sharing that file_name, instead of the last one silently overwriting the rest) — see CocoImageEntry’s own docstring. Writes one label file per image at output_dir/labels/<Path(file_name).stem>.txt — one class_id cx cy w h line per box, normalized to [0, 1] by that image’s own width/height (the YOLO convention) — plus a output_dir/data.yaml naming the single class. Each entry’s own bbox_size (if set) is used for its box, else the shared box_size. An entry with target=None contributes an image with an empty label file (a background image).

labels_dir overrides where label files go (default output_dir/labels); data_yaml=False skips data.yaml (for callers that write their own dataset file, e.g. per split).

Returns a dict of what was written ({"names": [...], "images": [...]}, one entry per included image with its label path), for inline inspection/testing — YOLO has no single canonical in-memory representation the way COCO’s JSON dict does.

Class index is the position in the sorted set of Target.category names present (uncategorized -> category_name), or in the explicit ordered categories list if given; data.yaml lists the same order. See resolve_categories.

Raises:
ValueError

If two entries share a file_name but disagree on width/height.