refactor(object-detection): vectorize postprocessing#1884
Open
DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
Open
refactor(object-detection): vectorize postprocessing#1884DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
Conversation
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 object detection hot path by reducing Python-side postprocessing overhead in Robotoff's wrapper around the upstream detector.
The original #1706 report pointed at ML performance issues. On current code, I could not reproduce the historical preprocessing slowdown from the issue text as-is, but I did confirm that object detection postprocessing is still loop-heavy and measurable on the latest code. This change targets that current bottleneck.
What Changed
OptimizedObjectDetectorin Robotoff's object detection wrapperoutput_image=TrueRemoteModelto reuse the optimized detector instanceWhy
The previous implementation still relied on Python loops over every candidate detection during postprocessing. For object detection outputs with many candidates, that adds avoidable CPU overhead on the Robotoff side.
This PR keeps the same output format and behavior while moving the expensive extraction work to NumPy.
Validation
Ran:
./.venv/bin/pytest tests/unit/prediction/object_detection/test_core.py./.venv/bin/flake8 robotoff/prediction/object_detection/core.py tests/unit/prediction/object_detection/test_core.pyLocal synthetic benchmark on an 8,400-candidate YOLO-shaped output:
6.43 ms -> 0.17 ms6.83 ms -> 0.60 msNotes
openfoodfactsPython package to avoid duplication.