Dataset adapters¶
Dataset adapters load URBAN-SED v2.0.0 and AudioSet Strong annotations into a validated sedmetrics.Dataset with class names, recording durations and integer ids.
Adapters turn on-disk reference data into a sedmetrics.Dataset: validated
reference events with stable integer ids, recording durations, a class
vocabulary and human-readable names. They are separate from the metrics, so the
core never depends on pandas, pyarrow or a file layout.
import sedmetrics as sm
dataset = sm.adapters.load_urban_sed("data/raw/URBAN-SED_v2.0.0.tar.gz", split="test")
result = dataset.event_f1(predictions) # predictions may use names or ids
print(result.f1, result.n_correct, result.n_insertions, result.n_deletions)
Dataset.event_f1 forwards to sm.event.f1 with the dataset's recording
durations, so events outside their recording are rejected rather than clipped.
Names, reports and the command line¶
Predictions can use the dataset's class and recording names:
result = dataset.event_f1(
[("soundscape_test_1", "siren", 1.05, 2.45)],
average="macro",
)
print(dataset.segment_f1(predictions, segment_length=1.0).error_rate)
sedmetrics.report writes a JSON report of event and segment metrics:
report = sm.report.evaluate(dataset, predictions, metrics=["event_f1", "segment_f1"])
sm.report.write_report(report, "results/run.json")
The same report is available from the command line, with predictions in a TSV or CSV table:
sedmetrics evaluate --dataset urban-sed --root data/raw --predictions preds.tsv --out results/run.json
The command covers event and segment metrics. PSDS needs score tracks and is available from Python only. DCASE score files and model checkpoints are not read.
Strictness¶
Adapters never skip data silently. A malformed annotation row, a missing
duration, a non-finite timestamp or an unknown split raises ValueError with
the file and row. The only files ignored are macOS AppleDouble resource forks
(._*.txt, .DS_Store), which are archive metadata rather than annotations.
Current behaviour: null parquet fields
A null audio_len or raw_text in an AudioSet row raises a TypeError
that names neither the file nor the row.
URBAN-SED v2.0.0¶
Input: the extracted release directory (containing annotations/) or the
official URBAN-SED_v2.0.0.tar.gz.
- Annotation files are
annotations/<split>/<clip>.txtwith tab-separatedonset<TAB>offset<TAB>labelrows; the loader acceptstrain,test,validateorall. - Recording ids follow the sorted
split/clipkey, so within one split they follow clip names, and withsplit="all"they follow split first.recording_namesholds the clip stem. Withoutlimit, ids are stable across runs and independent of filesystem order. A clip stem that appears in two splits is rejected. - The class vocabulary is the sorted set of labels in the loaded cohort; ids can
therefore shift when
limitis used. - Clips without events are kept. They appear in
dataset.durationsand can be predicted on; that matters for false-alarm and exposure analysis. - Duration:
clip_duration(default 10 s) is a documented convention, not read from the audio. Some URBAN-SED rows end at10.000000000000002for a 10 s clip. If an annotation ends later than the nominal duration, the clip duration is extended to that offset instead of truncating the annotation. An offset more than 1 s past the duration raises. - Reading the
.tar.gzstreams the archive and stops at the end of theannotations/tree, so the 6.6 GB of audio is not decompressed. This relies on the official layout, which stores annotations before audio; extract the archive if you have a re-ordered copy.
AudioSet strong¶
Input: a directory of *.parquet batches (for example CLAPv2's
audioset_strong export) or a single file. Requires pyarrow
(pip install "sedmetrics[data]").
Used columns:
audio_len: decoded audio duration in seconds.raw_text: list of header lines; the loader reads the line starting withStrong events:, whose entries look like(0.000s - 1.435s) Male speech, man speaking (/m/05zppz).
Mapping decisions:
- Classes are keyed by ontology id (
/m/...), not display name. Two ids can share a display name;Dataset.class_idthen refuses the ambiguous name and asks for the id. - Recording ids follow file order and row order; names are
"<file stem>#<row>". There is no clip identifier in the parquet batches, so ids are positional, not content-derived. - Duration comes from
audio_len, except that a clip whose annotations end later gets the latest annotated offset as its duration. Annotations are on the original segment timeline, and roughly 10 % of the sampled rows end up to 0.43 s past the decoded audio; truncating them would discard labelled audio. A row more than 1 s past its duration is treated as corrupt and raises.
Current behaviour: the 1 s limit moves
Both loaders check each offset, in file order, against the duration already
extended by earlier rows. On a 10 s clip, offsets 10.9, 11.8, 12.7
are all accepted and the duration becomes 12.7 s, while 12.7 alone raises.
- Rows without a
Strong events:line are empty clips and are kept.
Limits and subsampling¶
Both loaders accept limit=<n> to load the first n recordings. This is for
smoke tests: because class ids are assigned from the loaded cohort, a limited
dataset has a different vocabulary than the full one. Never compare results
computed on different limit values.
Current behaviour: limit and URBAN-SED archives
A directory is read in sorted name order, a .tar.gz in stored order. The
same limit can therefore select different clips from the two.
Verification status¶
The adapters are covered by unit tests (parsing, ids, durations, empty clips,
metadata files, archives) and by parity tests that run the loaded data through
both SEDMetrics and sed_eval 0.2.1. Current parity runs use 120 URBAN-SED test
clips (638 reference events, 10 classes) and 60 AudioSet strong clips
(625 reference events, 86 classes), with synthetic predictions derived from the
references. URBAN-SED labels are used as distributed; no split or label
cleaning is applied.
Common questions¶
Are clips without events kept?¶
Yes. They stay in the dataset durations, so false alarms on them and their exposure still count.