Skip to content

Live multi-animal identity for closed-loop flows - #254

Merged
gbradham merged 22 commits into
devfrom
claude/trusting-roentgen-28f822
Nov 28, 2026
Merged

gbradham merged 22 commits into
devfrom
claude/trusting-roentgen-28f822

Conversation

@gbradham

@gbradham gbradham commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Live multi-animal identity, so a flow can trigger a stimulus for one named animal when several animals share an arena.

Draft until it has been tested on real multi-animal recordings. The matching weights are untuned.

What it adds

  • Identity modes in camera settings: Off (the default; old files load as Off), By appearance (YOLO class names identify the animals) and Name at start (the operator clicks and names each animal on the live view, and a tracker carries the names forward).
  • Assigner (vision/identity_live.py): fixed-count minimum-cost assignment.
    • A hidden animal stays frozen at its last-seen spot.
    • The travel limit scales with elapsed time.
    • Beyond a one-frame reach, a hidden name can only re-attach to a detection that just appeared.
    • In appearance mode, class labels are soft evidence; the name only moves to another animal after the label disagrees for longer than the relabel window (default 0.5 s).
    • Every guessed frame is flagged close, stitched, gap or relabeled.
  • Flow nodes: Zone Input and Behavior Input gain an Animal property (default Any) and a Visible output. While an animal is hidden, its last state holds.
  • Per-animal live behaviour: one classifier per animal that a node references. While identity is on, the CV queue keeps every frame, and the Run page warns when CV falls behind.
  • Export at Stop: files in the Batch Pose layout plus the _identity.csv sidecar. Each row goes to the video frame captured nearest its timestamp, so paused runs line up too.

Known gaps

  • Only Apple-silicon Macs are supported; the Pi and multi-camera setups are out of scope.
  • CVProcessor assumes 30 fps.

Tests

Full suite: 7501 passed, 4 skipped.

The identity assigner now takes the frame timestamp and allows
max_travel_px per elapsed camera frame (at fps), so a CV pipeline that
drops frames no longer loses a fast-moving animal's name. The relabel
window spans camera frames by time too. Without timestamps each update
still counts as one frame.
…on clear

An appearance-mode slot never observed was reported at (0,0) and could
occupy a zone; ZoneTracker now skips hidden objects with age 0.
clear_identity also resets attached per-animal behaviour classifiers.
The export indexed rows by the logger's frame counter, which drifts from
the video when the logger starts first or frames go unlogged. Each row
now lands on video frame round((timestamp - t0) * fps), with t0 the
recorder's first written frame and fps its measured rate (new public
first_frame_timestamp / fps properties). With identity on, frames the CV
queue supersedes still get an empty log row. The export runs in a worker
thread at Stop.
The camera settings dialog now warns and saves nothing when two animals
share a name or Name at start has no animals. CVSettings.from_dict drops
animals with no name.
… time

A mid-run Pause leaves a gap in the raw video that t0 + i/fps cannot see, so
every row after it was shifted (or dropped past the end). The recorder now
keeps each written frame's capture timestamp; rows go to the nearest frame
within half a frame interval, and rows logged while paused are dropped.
@gbradham
gbradham changed the base branch from main to dev November 28, 2026 04:44
@gbradham
gbradham marked this pull request as ready for review November 28, 2026 05:05
@gbradham
gbradham merged commit a26fb1d into dev Nov 28, 2026
7 of 8 checks passed
gbradham added a commit that referenced this pull request Nov 28, 2026
Live multi-animal identity for closed-loop flows
@gbradham
gbradham deleted the claude/trusting-roentgen-28f822 branch November 28, 2026 20:31
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