Manual:Command-line tools
Alongside the graphical window, Hydrofon includes six command-line modules for training models, creating dataset splits, validating data manifests, running blind manual label review, replaying the event engine, and building this wiki. Run every command from the project root with the virtual environment interpreter .\.venv\Scripts\python.exe -m <module>; every flag listed here matches the module's actual --help output. You can also launch the desktop app with a console window for debugging via .\.venv\Scripts\python.exe -m app (the same command start_debug.bat runs).
Training and evaluation (app.train)¶
app.train is both the backend behind the graphical Training suite and a standalone CLI. It provides four subcommands: data, split, train and evaluate.
Pass the global --data-dir option before the subcommand. When omitted, the data folder path is read from settings.json (general.data_dir).
.\.venv\Scripts\python.exe -m app.train [--data-dir DIR] data|split|train|evaluate ...
data — list recordings¶
Lists all labelled recordings quickly without extracting YAMNet or frequency-band features.
| Flag | Default | Meaning |
|---|---|---|
--sources SOURCES |
recordings,wolfset |
Comma-separated subset of recordings, wolfset. |
.\.venv\Scripts\python.exe -m app.train data --sources recordings,wolfset
split — generate saved splits¶
Builds a dataset split and writes split.json without running feature extraction. Saved splits can be passed to train --split and evaluate --split-from.
| Flag | Default | Meaning |
|---|---|---|
--protocol |
required | Split protocol: holdout-legacy, group-kfold, or loeo. |
--out DIR |
required | Output folder (group-kfold writes DIR/foldN/split.json; loeo --negatives rotating_3fold_seed9 writes DIR/nf0/..DIR/nf2/). |
--sources SOURCES |
recordings,wolfset |
Comma-separated subset of sources. |
--exclude ID [ID ...] |
none | Recording IDs omitted from both train and test (not leave-one-engine-out). |
--test-fraction |
0.25 |
Target test share (holdout-legacy and loeo --negatives legacy). |
--seed |
0 |
Random seed. |
--k |
3 |
Number of folds for group-kfold. |
--motor |
none | Motor index 1–5 to hold out (required for loeo; 5 is the electric motor). |
--negatives |
legacy |
Negative groups for loeo: legacy (one split using the legacy holdout's no-motor test groups) or rotating_3fold_seed9 (three splits in DIR/nf0..nf2). |
.\.venv\Scripts\python.exe -m app.train split --protocol group-kfold --k 3 --seed 9 --out data\splits\cv3
.\.venv\Scripts\python.exe -m app.train split --protocol loeo --motor 5 --negatives rotating_3fold_seed9 --out data\splits\loeo_m5
train — train a model¶
Fits feature standardisation and balanced multinomial logistic regression, then saves model.json, weights.npz and split.json atomically to <data_dir>/models/<NAME>/ (see Model files).
| Flag | Default | Meaning |
|---|---|---|
--name NAME |
required | Model name (1–64 characters from A–Z a–z 0–9 . _ -, cannot start or end with ., cannot be yamnet). |
--features |
required | Feature kind: yamnet (1024-d YAMNet embeddings) or bands (30 one-third-octave bands + spectral flatness + crest factor; requires sample rate >= 35 919 Hz). |
--sources SOURCES |
recordings,wolfset |
Comma-separated subset of sources. |
--exclude ID [ID ...] |
none | Recording IDs left out of both sides; cannot be combined with --split. |
--test-fraction |
0.25 |
Target test share when --split is not given. |
--seed |
0 |
Random seed when --split is not given. |
--split SPLIT_JSON |
none | Path to a saved split.json file or folder holding one. |
--C |
1.0 |
Inverse regularisation strength (must be > 0). |
--overwrite |
off | Replace an existing model with the same name. |
.\.venv\Scripts\python.exe -m app.train train --name test-bands --features bands --sources wolfset --seed 0 --C 1.0
.\.venv\Scripts\python.exe -m app.train train --name loeo-m5-nf0 --features bands --split data\splits\loeo_m5\nf0\split.json
evaluate — evaluate on a test split¶
Evaluates a trained model or built-in yamnet on a test split. If a trained model saw any recording, group, identical-SHA-256 audio file or shared parent recording from that test set during training, evaluation is refused with exit code 1.
| Argument / flag | Default | Meaning |
|---|---|---|
model |
required | Trained model name under <data_dir>/models/ or yamnet. |
--split-from |
required | Another trained model's name, or a path to split.json (file or folder). |
.\.venv\Scripts\python.exe -m app.train evaluate yamnet --split-from wolfset-bands-v1
.\.venv\Scripts\python.exe -m app.train evaluate loeo-m5-nf0 --split-from data\splits\loeo_m5\nf0\split.json
JSON-lines protocol¶
stdout carries only one-line JSON objects so the Training suite can parse events live. On startup main() redirects Python's sys.stdout to stderr, preventing stray library prints from corrupting the stream. Human-readable progress and warnings go to stderr. A successful run exits with 0; failures emit an error event and exit with 1.
Event (event) |
Subcommands | Key fields |
|---|---|---|
recording |
data |
id, source, path, group, duration_s, seconds, note |
summary |
data |
recordings, seconds |
progress |
train, evaluate |
stage (features or fit); during features also done, total, id |
split |
train, split |
train, test, split_id; in split also path, coverage, warnings |
done |
train, evaluate, split |
train: name, path, metrics; evaluate: name, metrics, split_id; split: paths |
error |
all | message (unexpected errors also write a traceback to stderr) |
Data manifest and QC (app.manifest)¶
app.manifest produces a deterministic manifest (manifest.jsonl) and quality-control report (qc.json) over all recordings. Nothing is repaired automatically: every problem is reported.
| Flag | Default | Meaning |
|---|---|---|
--data-dir DATA_DIR |
settings.json (general.data_dir) |
Data folder path. |
--out OUT |
<data_dir>/manifest/manifest.jsonl |
Manifest file path; qc.json is written alongside it. |
.\.venv\Scripts\python.exe -m app.manifest
.\.venv\Scripts\python.exe -m app.manifest --data-dir C:\path\data --out C:\path\manifest.jsonl
stdout prints a JSON summary (manifest, manifest_sha256, recordings, skipped, errors, counts). Exit code is 0 when qc.json lists no errors and 1 when errors are present (both files are written either way).
Blind manual review (app.annotation)¶
app.annotation drives the manual review workflow with two subcommands: export cuts anonymous clips and reviewer sheets from Wolfset, and import validates completed sheets and computes inter-annotator agreement.
export — create a blind review set¶
Clips are selected solely from file names, Wolfset_Index.csv, frozen label rules and the historical seed-0 test list — never from model predictions.
| Flag | Default | Meaning |
|---|---|---|
--out OUT |
required | New or empty output folder (never overwrites filled sheets). |
--data-dir DATA_DIR |
settings.json (general.data_dir) |
Data folder path. |
--seed |
0 |
Seed for stratified sampling and clip order. |
--n-per-stratum |
6 |
Clips requested per stratum. |
--clip-s |
5.0 |
Length of the central span to label (seconds). |
--pad-s |
1.0 |
Context audio before and after the span (0 = none). |
--overlap-fraction |
0.2 |
Share of clips assigned to two reviewers (0–1). |
--reviewers |
A,B |
Comma-separated reviewer names (letters, digits, _ or -); one CSV sheet each. |
Reviewers receive OUT/review/ (clips/c001.wav..., sheet_<name>.csv and instructions in LOEMIND.txt). The private mapping back to source files and weak labels stays in OUT/key.json.
import — validate sheets and compute agreement¶
| Argument | Default | Meaning |
|---|---|---|
dir |
required | Export folder containing key.json and review/. |
import reads review/sheet_*.csv (accepting , or ; delimiters and UTF-8 or cp1252, matching Excel output). On any validation error nothing is written and exit code is 1. When valid, it writes reviewed_segments.jsonl and agreement.json (observed agreement, Cohen's kappa, weak-label comparison and disputed/pending lists) inside dir.
.\.venv\Scripts\python.exe -m app.annotation export --out data\review_run1 --reviewers A,B --seed 0
.\.venv\Scripts\python.exe -m app.annotation import data\review_run1
Event engine replay (app.replay)¶
app.replay runs a timeline of engine scores through app/events.py (see Alarms and events) and prints JSON lines: first the rule ({"type": "rule", ...}), then every emitted item in order (event_started, event_ended, notify, gap, reset), and finally a summary ({"type": "summary", ...}).
| Argument / flag | Default | Meaning |
|---|---|---|
scores |
optional | CSV with t_start (or t_start_s), t_end (or t_end_s) and score_engine; optional run_id, model_id, recording_id start a new source when they change. Empty or non-numeric scores count as missing windows. |
--wav WAV |
optional | Mono WAV file to score with --model instead of reading a CSV. |
--model MODEL |
optional | Model name (yamnet or a trained model); required with --wav. |
--rule RULE |
event |
event, legacy, an inline JSON object or a path to a JSON file. event and legacy take defaults from app/settings.py. |
.\.venv\Scripts\python.exe -m app.replay scores.csv --rule event
.\.venv\Scripts\python.exe -m app.replay --wav data\wolfset\A00020T16N00.wav --model wolfset-bands-v1 --rule '{"on_threshold": 0.5, "off_threshold": 0.3, "release_s": 2.0}'
Known limitations
--wav currently accepts mono files only and runs whole-file model.predict rather than the block-by-block stream processor. In addition, the live GUI alarm still uses the legacy Alarm rule (threshold + consecutive windows + cooldown); the new event engine in app/events.py is not yet wired to the live view.
Building the wiki and screenshots (wiki.build and wiki.screens)¶
Two modules build this manual and regenerate its screenshots (see Building this wiki for full details).
wiki.build — build the static wiki¶
| Flag | Default | Meaning |
|---|---|---|
--out OUT |
wiki/dist |
Output folder for the static site (replaces any existing folder at that path). |
.\.venv\Scripts\python.exe -m wiki.build
.\.venv\Scripts\python.exe -m wiki.build --out C:\temp\hydrofon-wiki
wiki.screens — capture app screenshots¶
Drives the real MainWindow offscreen (QT_QPA_PLATFORM=offscreen) against a temporary demo folder, plays a Wolfset recording live, records and labels it, runs Clip analysis and writes all six PNG screenshots to wiki/static/img/<lang>/.
| Argument | Default | Meaning |
|---|---|---|
[et|en] |
both (et and en) |
Optional positional language code(s). |
No --help flag
wiki.screens does not use argparse; it reads language codes directly from sys.argv[1:]. Passing --help will treat --help as a language code instead of printing usage text.
.\.venv\Scripts\python.exe -m wiki.screens
.\.venv\Scripts\python.exe -m wiki.screens en
See also¶
- Architecture — how the CLI modules and GUI fit together
- Training a model — training through the graphical interface
- Splits —
holdout-legacy,group-kfoldandloeoprotocols - Labels and provenance — manifest fields and QC flags
- Manual review — blind review workflow
- Alarms and events — event engine vs legacy alarm
- Building this wiki — wiki syntax, build pipeline and deployment
- Tests — running the test suite from the command line