Skip to content

fix(tracking): named-target drift + occlusion chase; perf: ReID on GPU#101

Closed
TCVinNYC wants to merge 5 commits into
mainfrom
fix/target-lock-and-perf
Closed

fix(tracking): named-target drift + occlusion chase; perf: ReID on GPU#101
TCVinNYC wants to merge 5 commits into
mainfrom
fix/target-lock-and-perf

Conversation

@TCVinNYC

Copy link
Copy Markdown
Member

Three root-cause fixes from a systematic debugging pass on the user's report (each TDD'd, full suite green). These are pre-existing issues on main/rc2, independent of PR #100.

Fixes

  1. Named-target drift (identity lock) — when a target selected by name was lost, the appearance-only ReID recovery re-bound the lock to whoever's body matched best → it drifted onto the next visually-similar person, then any track. A named-identity target now re-binds via ReID only to a face-confirmed match of the same identity (_reid_rebind_allows); otherwise it stays searching. Manual/clicked targets keep appearance re-bind.
  2. Occlusion chase — when the subject was covered, the box collapsed to the visible part (legs) but stayed non-lost, so the PTZ chased it down to the last-known partial position. The drive loop now tracks a slow "healthy height" reference and coasts on a sudden collapse (occlusion) while a gradual shrink (walking away) keeps following — distinguished so normal following is unaffected.
  3. Perf: ReID on GPU — OSNet ReID was pinned to device="cpu" (a major per-frame cost on the M4 Pro that also stalled the inference thread via the GIL). It now auto-selects mps/CUDA with a CPU fallback; AUTOPTZ_REID_DEVICE overrides.

Why these

Measured on an M4 Pro: detector = 11ms (CoreML, accelerated). The 148ms with all services on is face (forced CPU) + ReID (CPU)#3 gets ReID onto the GPU. #1/#2 are the "loses my person / chases the wrong box" report.

Tests

New tests/test_target_lock.py, tests/test_reid_device.py. Full suite 1046 passing, ruff clean.

Validate on real cameras before merge

  • Select a person by name; have them occluded/leave → camera should hold/search, not grab someone else or chase legs.
  • Confirm ReID still works on mps and the per-frame budget drops (set AUTOPTZ_REID_DEVICE=cpu to compare / if mps misbehaves).

🤖 Generated with Claude Code

TCVinNYC and others added 5 commits June 24, 2026 14:34
Bug: when a target was selected by identity (name) and then lost, the
appearance-only ReID recovery (`_maybe_reid_recover`) re-bound the lock to
whatever visible track best matched the body template — so the camera drifted
onto the next visually-similar person, then the next unknown track.

A named-identity target now re-binds via ReID only to a track that
face-recognition has confirmed as the SAME identity (`_reid_rebind_allows`);
otherwise it stays searching until the real person's face is seen again. A
manual/clicked target (no identity) keeps the appearance-based re-bind it relies on.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…luded target

Bug: when the target was covered by something/someone the detector returned only
the visible part (e.g. the legs); the tracker kept that shrinking box as a
confident, non-lost track, so the PTZ chased it down to the last-known partial
position (box + aim dot drifting onto the legs).

The drive loop now tracks a slowly-updated "healthy" target-height reference and
coasts (track_active=False) when the box height suddenly collapses below it — the
occlusion signature — while a gradual shrink (the subject walking away) keeps the
reference in step and is NOT flagged, so normal following is unaffected. The
camera resumes when the subject reappears at full size.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…always CPU

ReID was pinned to device="cpu" — a major per-frame cost on Macs that also stalls
the inference thread through the GIL (the appearance pass holds it during the
torch/numpy work). It now auto-selects the Apple GPU (mps) or CUDA when available
and falls back to CPU if GPU init fails. AUTOPTZ_REID_DEVICE overrides the choice
(e.g. =cpu if an OSNet op misbehaves on mps).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ITS)

On Intel + AMD Macs (e.g. iMac Pro Xeon + Vega 56) CoreML may silently run on the
CPU instead of the discrete GPU. The compute-unit target is now configurable
(default ALL) so it can be verified/forced: run `--bench` with CPUOnly and again
with ALL/CPUAndGPU and compare to see whether the Vega is actually helping.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TCVinNYC

Copy link
Copy Markdown
Member Author

Superseded by #100fix/target-lock-and-perf was merged into feat/cpu-spikes-and-center-stage during development, so all of its commits (named-target identity-drift fix, occlusion-coast, ReID-on-GPU device selection, AUTOPTZ_COREML_UNITS) are included in #100, which merged to main as 9c036aa. Closing to avoid a duplicate/empty re-merge.

@TCVinNYC TCVinNYC closed this Jun 24, 2026
@TCVinNYC TCVinNYC deleted the fix/target-lock-and-perf branch June 24, 2026 23:08
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