PyTorch: Speed up DEKR predictor#3121
Merged
MMathisLab merged 6 commits intoDeepLabCut:mainfrom Nov 4, 2025
Merged
Conversation
Improve the performance of DEKR predictor. Use advanced indexing instead of for loops and remove TODO.
maximpavliv
approved these changes
Oct 14, 2025
Contributor
maximpavliv
left a comment
There was a problem hiding this comment.
The refactoring looks great — the vectorized version is much cleaner.
I’ve run the full integration testing suite on my side, and everything passes without issues. Nice work on this improvement!
deruyter92
reviewed
Nov 4, 2025
Collaborator
deruyter92
left a comment
There was a problem hiding this comment.
I ran the code step-by step and confirmed that evaluation results are close to previous implementation. The vectorization looks great, also happy that you added the tensor shapes in the comments. Looks all good to me!
deruyter92
added a commit
to deruyter92/DeepLabCut-live
that referenced
this pull request
Jan 21, 2026
This commit updates the DEKRPredictor to follow the DeepLabCut implementation in version 3.0.0rc13. see DeepLabCut/DeepLabCut#3121
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.
Summary
This PR improves the performance of DEKR predictor.
forloops.Details
Profiling the DEKR predictor's forward call, shows a significant increase in speed. But the overall inference time of the architecture remains mostly unchanged (very minor improvements) since it is largely dominated by HRNet and torch native modules. (thanks to @maximpavliv for running the benchmark)
Below shows (the rectangle in blue) that most of the inference time is spent in the HRNet and PyTorch native inference procedures.
I have optimized the rest of it (the rectangle in red) as much as I could.