Repository navigation
Correspondences: candidate buffer grows instead of silently dropping candidates - #48
Conversation
…ing candidates The matching stages wrote their candidates into a buffer of 4 * NMAX = 80960 rows and returned the moment it was full. Targets are visited in camera-1 order, so every candidate of the targets visited last was lost, without any warning: with a wide epipolar band (criteria.eps0) and dense seeding the particles at the end of that order were never matched and their trajectories ended mid-volume. - _run_matching_stage: a stage that fills its buffer runs again on a larger one, up to MAX_CANDIDATE_ROWS = 2**23 (about 0.4 GB); at the cap the rest is dropped with a RuntimeWarning that names eps0. - Growth is sized from the data: never beyond an upper bound computed from the per-target candidate counts (_bound_quads/_triplets/_pairs), and projected from how far the full stage got (the last row written names the target; _progress_*), so a very full stage is rerun once, not once per doubling. Doubling stays the floor. - Warning (once) when a stage finds >= 100000 candidates and >= 20 per target: the epipolar band is far too wide for the data (about 0.5 per target is normal). - The target-usage table and the result list are sized from the number of targets (never below NMAX); the 3- and 2-camera stages check bounds against the real table width. More than NMAX targets in a camera used to index past the table. - take_best_candidates: typed contiguous order array, same order (ties included), no Python-object indexing per candidate. Reproduced on the compiled code: 150 matchable particles, eps0 = 1.0: 66 quads + 93 triplets (mostly wrong) instead of 150 quads; with a 600-row buffer, 7 matches instead of 150. Wide band, 150 particles: 2.7 M candidates at eps0 = 2.0, 1.48 s -> 0.65 s (one pre-sized run: 0.64 s); 828 k at 1.5: 0.39 s -> 0.20 s. At default settings nothing changes: 20 real and synthetic frames give the same blob ids, no stage grows its buffer, the bounds cost 0.02 ms per frame. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d case with truth (syn1), new candidate buffer against the old fixed one Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Real-recording wide-band test (the check that was still open)
Real recording wp2, frame 100 (about 1500 targets per camera, default
This is the reported symptom on real detections: at the reported band (0.15 mm) the old buffer leaves the last x-quartile of camera 1 two thirds unmatched; at 0.25 mm everything after the first quartile. Time with the new buffer: 0.27 s (0.15 mm), 0.94 s (0.25 mm). At 0.40 mm (5,600 candidates per target) the 8.4 M-row cap is reached and the cap warning fires, as designed. Rendered case with truth, syn1 frame 100 (a quad counts as correct when its four blobs belong to one true particle; merged blobs are counted wrong, so absolute shares are low, the comparison is what matters)
The new buffer keeps every correct match as the band widens (549 at 0.10, 0.15 and 0.25). The extra quads at wider bands are false matches that the band itself allows (precision 57 % to 49 %), which is what the new wide-band warning (fires at 0.15 mm: 146 k to 165 k candidates for about 1500 targets) is for: the result is complete, but narrowing the band is better. The old buffer loses half the correct matches at 0.15 and nearly all of them at 0.25. |
…r skips releases without Windows wheels loro 1.19.0 (via marimo) was published on 2026-11-23 with no Windows wheel; uv sync picks the newest release for the universal lock and then cannot install it on Windows, so both Windows test jobs failed in 'Install dependencies' (main too). With required-environments the lock uses loro 1.18.0 for Windows and keeps 1.19.0 elsewhere. Python 3.14 is excluded: optv has no Windows wheel for it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… viz extra Only the marimo notebooks (openptv2/gui/*_nb.py, optimize_calibration.py) and one script import marimo; nothing in the headless batch runtime does, and self_check already treats it as optional. As a core dependency it pulled marimo and its tree (loro, ...) into every install, including the batch/cloud image, and made a release without wheels on one platform (loro 1.19.0, Windows) break plain installs of the lock. The viz extra (included in dev, so CI and contributors are unchanged) now carries marimo>=0.24.0 and nbformat>=5.11.1, the minimums the core list had. The Windows lock requirement stays for CI (dev includes viz). Checked in a venv without marimo, loro, nbformat, Qt or TraitsUI: the unit suite gives the same results as with them. The 4 differences from the full environment (autocalibrate_cavity, 2 residual-field tests, self_check main) fail identically with marimo and nbformat installed: they need matplotlib / imagecodecs, which are gui/viz extras, not core. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Problem
The correspondence stages (4-, 3- and 2-camera) write their candidate matches into a buffer of
4 * NMAX = 80960rows and return the moment it is full. Targets are visited in camera-1 order, so every candidate of the targets visited last is lost, with no warning. With a wide epipolar band (criteria.eps0) and dense seeding the particles at the end of that order are never matched and their trajectories end mid-volume. A user report:eps0 = 0.15 mm, upper aorta never matched; narrowing the band to 0.08 mm hid it.Reproduction (compiled code, before the fix)
eps0 = 1.0: 66 quads + 93 triplets (mostly wrong) instead of 150 quads, i.e. the default 80960 rows overflowed.Fix (
algorithms/correspondences.py)_run_matching_stage: a stage that fills its buffer runs again on a larger one, up toMAX_CANDIDATE_ROWS = 2**23(about 0.4 GB). At the cap the remaining candidates are dropped with aRuntimeWarningthat nameseps0._bound_quads/_triplets/_pairs), and is projected from how far the full stage got (its last row names the target it reached:_progress_*), so a very full stage is rerun once instead of once per doubling. Doubling stays the floor and the retry stays the guarantee.tusage) and the result list are sized from the number of targets (never belowNMAX); the 3- and 2-camera stages check bounds against the real table width. More thanNMAXtargets in a camera used to index past the table (boundscheck is off) and every target fromNMAXon was skipped.take_best_candidates: typed contiguous order array (same order, ties included), no Python-object indexing per candidate._stage_four/three/pairbecause theccallstages cannot be passed around as objects.Speed (150 particles, wide band, same results)
take_best_candidatesat 2.7 M candidates: 0.34 s to 0.22 s. Default settings: unchanged (a real frame takes 107 ms; the bounds add 0.02 ms).Checks
TestCandidateBuffer,TestCandidateBufferEstimates,take_best_candidatesagainst the previous loop with ties): wide band at the default size gives 150 quads with consistent identities; a 16-row initial buffer and anNMAX = 8table give identical matches to the default; the cap and the wide-band warning; the stage runner (doubling, bound, projection); the bounds against a brute-force count; progress readers; attempts per frame.test_correspondences.py+test_correspondences_coverage.pypass in both (82 tests).test_sequence_triangulation_method::test_lsq_triangulation_reprojects_better_than_pairs(run.zarr does not exist), which also fails onmainwithout this change.eps0widened, new buffer against the old fixed one); results will follow as a comment.CI note
The Windows test jobs fail in Install dependencies (
loro==1.19.0has no Windows wheel);mainis red for the same reason, independent of this change.