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 |
- 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
entriestooutput_diras a YOLO-format label set.Same inclusion filtering as
write_coco(position_confidenceat or abovemin_confidence, opt-in only for lower confidence), and the same multi-entries-per-file_namegrouping (one label file gets one line per entry sharing thatfile_name, instead of the last one silently overwriting the rest) — seeCocoImageEntry’s own docstring. Writes one label file per image atoutput_dir/labels/<Path(file_name).stem>.txt— oneclass_id cx cy w hline per box, normalized to [0, 1] by that image’s own width/height (the YOLO convention) — plus aoutput_dir/data.yamlnaming the single class. Each entry’s ownbbox_size(if set) is used for its box, else the sharedbox_size. An entry withtarget=Nonecontributes an image with an empty label file (a background image).labels_diroverrides where label files go (defaultoutput_dir/labels);data_yaml=Falseskipsdata.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.categorynames present (uncategorized ->category_name), or in the explicit orderedcategorieslist if given;data.yamllists the same order. Seeresolve_categories.- Raises:
- ValueError
If two entries share a
file_namebut disagree onwidth/height.