Skip to content

PANNs picks its device, and tags a whole recording frame by frame - #12

Merged
alexarje merged 3 commits into
mainfrom
panns-device-and-frames
Sep 12, 2026
Merged

alexarje merged 3 commits into
mainfrom
panns-device-and-frames

Conversation

@alexarje

Copy link
Copy Markdown
Contributor

Summary

  • device= on ml.tag_window / ml.tag_probabilities, ml.PANNS_DEVICE for the session default, ml.resolve_device ("auto" → CUDA when torch sees one). PANNs was hardcoded to CPU; the cached model is rebuilt when a different device is requested.
  • New ml.tag_frames(x, fs, win_s=4, hop_s=2, wanted=None, device=None, batch=32) -> (times, probs, names): frame-wise AudioSet posteriors for a whole recording, tiled and batched. On a 90-minute concert this is ~1 min on a laptop GPU against ~30 min on CPU.
  • Guide (docs/guide/ml.md) and CHANGELOG updated.

Motivation: segmenting IMV concert videos (music / applause / talk) for the DAM catalog needed exactly this; the caller had to monkeypatch ml._panns_model to reach the GPU and write the tiling loop by hand.

Test plan

  • tests/test_ml_frames.py (new, stubbed model): tiling and window centres, wanted column order, short input = one window, unknown label raises, device change rebuilds the model, resolve_device.
  • Existing tests/test_ml_tags.py unchanged and passing.
  • Full suite: 535 passed.
  • Real run: tag_frames on an 87-minute concert at 32 kHz, device="cuda", 2622 windows in 54 s; posteriors identical to the per-window tag_probabilities loop.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PcjBSXbXjqdj1tmYHoLiKd

`ml.tag_window` and `ml.tag_probabilities` built CNN14 on the CPU with no way to
say otherwise, which is fine for the forty windows `draft` tags around events and
not for a concert every two seconds. Both take `device=` now, `ml.PANNS_DEVICE`
sets the session default and `"auto"` takes a CUDA GPU when torch sees one; the
cached model is rebuilt when a different device is asked for.

`ml.tag_frames` tiles a recording into windows and batches them through the model,
returning (times, probs, names) with the columns in the caller's order. It is the
array a segmenter wants, and the piece that every caller so far had to write itself.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PcjBSXbXjqdj1tmYHoLiKd
alexarje and others added 2 commits September 12, 2026 22:43
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PcjBSXbXjqdj1tmYHoLiKd
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PcjBSXbXjqdj1tmYHoLiKd
@alexarje
alexarje merged commit ef0b345 into main Sep 12, 2026
2 checks passed
@alexarje
alexarje deleted the panns-device-and-frames branch September 12, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant