Skip to content

Fix wrong multi-animal tracking when ellipse fit fails on one animal - #3544

Merged
deruyter92 merged 2 commits into
DeepLabCut:devfrom
Ayskin:yann/fix-untracked-animal-assignment
Oct 21, 2026
Merged

deruyter92 merged 2 commits into
DeepLabCut:devfrom
Ayskin:yann/fix-untracked-animal-assignment

Conversation

@Ayskin

@Ayskin Ayskin commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Bug

Fixes a bug in SORTEllipse.track where the tracking assigns ellipses to the wrong animals when an ellipse fit fails on one animal. Indices of tracked ellipses were not aligned with the input animal indices. Subsequent function fill_tracklets is then assigning the wrong poses to the wrong animals on that failing frame.

Fix

Add an additional record pose_inds of animal indices from the input poses array and use it to write the animalindex instead of ellipses indices.

In case of given identities, directly read the tracker id from pred_ids as it is only updated on successful ellipse fit.

Test

The test function test_sort_ellipse_unfitted_pose_keeps_animal_index simulates calling SORTEllipse.track twice on two mock frames with two mock animals (0 and 1), where the second frame of the animal 0 has all but 2 bodyparts with Nan detected coordinates. This makes the ellipse fit fail, and prior to the fix, assign pose from animal 1 to animal 0 in the tracklets.

Related

Fixes #3493.
Mentioned in #3089.

@Ayskin
Ayskin changed the base branch from main to dev October 6, 2026 09:30
@deruyter92
deruyter92 requested review from deruyter92 and a balanced review from Copilot October 6, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The unrelated documentation changes should be split out, and the identity-specific regression path needs test coverage.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Fixes incorrect multi-animal pose assignment when ellipse fitting skips a detection. The branch also includes an unrelated napari documentation refresh.

Changes:

  • Maps fitted ellipses back to original pose indices.
  • Adds regression coverage for failed ellipse fitting.
  • Expands napari usage and troubleshooting documentation.
File Description
deeplabcut/​core/​trackingutils.py Preserves original animal indices during ellipse tracking.
tests/​test_trackingutils.py Tests skipped ellipse-fit behavior.
_toc.yml Adds troubleshooting documentation.
docs/​gui/​napari/​troubleshooting.md Adds troubleshooting guidance.
docs/​gui/​napari/​basic_usage.md Refreshes annotation workflows.
docs/​gui/​napari/​advanced_usage.md Updates documentation metadata.
docs/​gui/​napari/​tracking/​basic_usage.md Updates title and metadata.
docs/​gui/​napari_GUI.md Refreshes the napari documentation landing page.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_trackingutils.py Resolved
Comment thread _toc.yml Resolved
Comment thread docs/gui/napari/troubleshooting.md Resolved

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix! Great that you added the regression test as well.

Just minor comments. I agree with copilot that the regression test now does not cover the entire failure mode.

Out of scope:
We should definitely look into the entire pipeline for other things that could be improved. E.g. the pickle saving that we discussed already (that would be a big migration). But also the config handling, which is a smaller fix. (now re-written as a side-effect; parameters not easily customizable). Maybe for some follow-up PRs. Let's discuss

Comment thread tests/test_trackingutils.py Resolved
Comment thread tests/test_trackingutils.py Resolved
@Ayskin
Ayskin force-pushed the yann/fix-untracked-animal-assignment branch from ce318d6 to 6049de4 Compare October 7, 2026 09:53
@deruyter92
deruyter92 merged commit 156bf8a into DeepLabCut:dev Oct 21, 2026
37 checks passed
@C-Achard C-Achard added the 3.0.3 label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-animal ellipse tracker can assign poses to the wrong animal when ellipse fitting fails for one detection

4 participants