[Relax][Vision] Add get_valid_counts and classic NMS#18943
[Relax][Vision] Add get_valid_counts and classic NMS#18943tlopex merged 7 commits intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the get_valid_counts and non_max_suppression operators to the Relax vision dialect. The implementation includes C++ operator registration with structural information inference, Python FFI bindings, and legalization passes to TOPI. Additionally, it provides TIR-based implementations for both operators in TOPI, along with corresponding NumPy reference implementations and comprehensive unit tests covering shape inference, legalization, and end-to-end execution. I have no feedback to provide.
tlopex
left a comment
There was a problem hiding this comment.
Still some points to be improved
- The
iou_thresholdtype check only handlesfloat, soiou_threshold=0will not be converted to a TIR constant. Please useisinstance(iou_threshold, (float, int)), consistent withget_valid_counts. - When
id_index < 0, there are no class IDs in the input, soforce_suppress=Falsecannot actually enforce same-class-only suppression. In practice it ends up behaving the same asforce_suppress=True. This is probably fine for compatibility, but it would be helpful to call it out in the docstring. - Test coverage still seems incomplete: no case for
force_suppress=True, no case wheremax_output_size > 0actually truncates outputs, no multi-batch NMS test, and no coverage for thereturn_indices=False, invalid_to_bottom=Falsepath.
|
PTAL @tlopex |
|
A few follow-ups:
You can have a look and resolve the existed conflicts |
|
Thanks for the detailed follow-ups, @tlopex ! I'm currently digesting these suggestions and working on the fixes. It might take me a little bit of time to get everything updated, tested properly, and resolve the conflicts. I'll ping you once the new commits are ready. |
ed3cef2 to
34d6a45
Compare
|
PTAL @tlopex |
Summary
Add
relax.vision.get_valid_countsand classicrelax.vision.non_max_suppressionfor object-detection post-processing pipelines.get_valid_countsperforms score-based bounding box filtering and compacts valid boxes to the front of each batch. Classicnon_max_suppressionperforms flexible IoU-based suppression on filtered boxes, complementing existingall_class_non_max_suppressionfor custom post-processing workflows.This PR implements the Relax-level registration, legalization, TOPI compute, and test coverage for both operators tracked in #18928.
Changes
Relax op registration and legalization:
vision.h,vision.cc)vision.py)topi.vision.get_valid_countsandtopi.vision.non_max_suppressionscore_index,id_index, andcoord_startwhenelem_lengthis statically knownTOPI and testing:
get_valid_countsnon_max_suppressionin TOPItvm.topi.testingfor both operatorsrelax.call_tirintroduction and removal of the original Relax vision opLimitations
score_index,id_index, andcoord_startis only enforced when the inputelem_lengthis statically known during struct-info inference.non_max_suppressionfollows the existing Relax / TOPI API shape and is intended for single-class or class-aware custom post-processing flows, distinct fromall_class_non_max_suppression.Validation
All related tests passed.