PyTorch: Speed up single animal models#3110
Merged
AlexEMG merged 3 commits intoDeepLabCut:mainfrom Oct 18, 2025
Merged
Conversation
Replace nested loops with vectorized PyTorch operations to extract heatmap scores and locref offsets in parallel.
8d4decb to
e9d1b2c
Compare
maximpavliv
approved these changes
Oct 14, 2025
Contributor
maximpavliv
left a comment
There was a problem hiding this comment.
Thanks a lot for this improvement — great work! 🙌
The vectorized implementation looks clean and efficient, and it passes all integration tests on my side.
Just one small suggestion: the Example section in the docstring should be updated for consistency with the tensor layout assumed by the code. Specifically, the example
>>> heatmap = torch.rand(32, 17, 64, 64)
>>> locref = torch.rand(32, 17, 64, 64, 2)
should be changed to
>>> heatmap = torch.rand(32, 64, 64, 17)
>>> locref = torch.rand(32, 64, 64, 17, 2)
so it matches the (batch_size, height, width, num_joints) format used in the implementation.
AlexEMG
approved these changes
Oct 14, 2025
AlexEMG
approved these changes
Oct 18, 2025
2 tasks
deruyter92
added a commit
to deruyter92/DeepLabCut-live
that referenced
this pull request
Jan 21, 2026
This commit updates the `HeatmapPredictor` in single_predictor.py to follow the implementation in DeepLabCut 3.0.0rc13. See DeepLabCut/DeepLabCut#3110
MMathisLab
pushed a commit
to DeepLabCut/DeepLabCut-live
that referenced
this pull request
Jan 22, 2026
* DEKRPredictor: add non-maximum suppression (NMS) This commit Updates the DEKR predictor to follow the DeepLabCut implementation in version 3.0.0rc7, see DeepLabCut/DeepLabCut#2907 * DEKRPredictor: speed up with vectorized operations This commit updates the DEKRPredictor to follow the DeepLabCut implementation in version 3.0.0rc13. see DeepLabCut/DeepLabCut#3121 * PartAffinityFieldPredictor (PAF): Speed up cost computation This commit updates the PAF predictor to follow the DeepLabCut implementation in version 3.0.0.rc13. See DeepLabCut/DeepLabCut#3117 * HeatmapPredictor (single animal): speed up with vecorized operations This commit updates the `HeatmapPredictor` in single_predictor.py to follow the implementation in DeepLabCut 3.0.0rc13. See DeepLabCut/DeepLabCut#3110
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the prediction performance of various single animal PyTorch models.
The
forloops for extracting values out of theheatmaptensor were replaced with advanced indexing.Details
Profiling results showed
HeatmapPredictor.get_pose_predictionas a major hot spot in single animal inference procedure.After this change, we see a massive speed-up in the major single animal models as shown below (thanks to @maximpavliv for running the benchmark)