avoid duplicate computation during classification #265
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.
Optimize Classification Performance (~2x Faster)
Summary
This PR optimizes classification performance by eliminating redundant classifier calls during prediction. Both GUI and command-line classification are now approximately 2x faster with identical results.
Performance Improvement
Problem
During classification, the code was calling both
predict()andpredict_proba()separately on the same data:This caused the classifier to run twice per identity because
predict()internally computes probabilities and then thresholds them at 0.5. For large pose files with multiple identities, this resulted in unnecessarily slow classification.Solution
Call
predict_proba()once and derive predictions usingnp.argmax():The
np.argmax(probabilities, axis=1)returns the index of the class with the highest probability for each frame, which for binary classification is 0 (not behavior) or 1 (behavior) - exactly whatpredict()would return.Files Changed
src/jabs/ui/classification_thread.py- GUI classification in the main JABS applicationsrc/jabs/scripts/classify.py- Command-linejabs-classifytoolCorrectness
✅ Results are identical -
np.argmax(predict_proba())produces the exact same predictions aspredict()✅ No breaking changes - All existing code continues to work
✅ Tested - Classification produces identical results with the optimization