[Relax][Frontend][TFLite] Implement DETECTION_POSTPROCESS tflite operator#19345
[Relax][Frontend][TFLite] Implement DETECTION_POSTPROCESS tflite operator#19345Aharrypotter wants to merge 2 commits intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the DETECTION_POSTPROCESS operator in the TFLite frontend for Relax, including attribute validation and NMS logic. Feedback highlights several critical issues: invalid Python unpacking of relax.Call objects (e.g., from topk), premature access to struct_info.dtype before normalization, a potential shape mismatch in mask generation, and robustness concerns regarding dynamic batch sizes in slicing operations.
|
Several issues that need to be addressed:
Relax ops return
Please emit the call first, then extract the fields with
The
Here:
The single-line reformatting of
Please add an end-to-end correctness test against a TFLite model that uses |
|
Currently thinking about how to write appropriate test cases. |
tlopex
left a comment
There was a problem hiding this comment.
btw, please have a look at those gemini reviews, which I think maybe helpful
|
@Aharrypotter Could you have a look and fix the issue? |
|
Sure, will push the fix today. |
…ator This commit wires up the TFLite_Detection_PostProcess custom operator in the Relax TFLite frontend. Key changes include: - Implemented conversion logic using multibox_transform_loc and all_class_non_max_suppression. - Added support for both regular NMS and class-agnostic NMS paths via 'use_regular_nms'. - Properly formatted outputs (boxes, classes, scores, num_detections) to match TFLite spec. - Added strict validation for required custom options (num_classes, scales, etc.).
488d252 to
a0dc24b
Compare
|
I also fixed a bug in Please take a look @tlopex |
Wire up the DETECTION_POSTPROCESS frontend lowering more robustly and cover the main semantic paths in test_frontend_tflite.py. This change: - fixes tuple handling and output post-processing in the TFLite frontend DETECTION_POSTPROCESS converter - masks selected scores using the actual selected-score slots before topk and aligns class padding dtypes - updates all_class_non_max_suppression legalization so the tensorflow output_format keeps the TOPI 3-tensor contract - adds DETECTION_POSTPROCESS frontend tests for IR structure, option validation, semantic reference coverage, LegalizeOps coverage, and the zero-valid-detection case Validation: - python -m ruff check python/tvm/relax/frontend/tflite/tflite_frontend.py python/tvm/relax/transform/legalize_ops/vision.py tests/python/relax/test_frontend_tflite.py - PRE_COMMIT_HOME=.cache/pre-commit python -m pre_commit run --files python/tvm/relax/frontend/tflite/tflite_frontend.py python/tvm/relax/transform/legalize_ops/vision.py tests/python/relax/test_frontend_tflite.py Result: - ruff check passed - pre-commit passed
a0dc24b to
d52742c
Compare
|
I will debug the error later. |
Summary
DETECTION_POSTPROCESSoperator conversion to Relax IR.Changes
convert_detection_postprocessinpython/tvm/relax/frontend/tflite/tflite_frontend.py.multibox_transform_locfor coordinate decoding and variance scaling.use_regular_nmsattribute to switch between all-class NMS and class-agnostic NMS paths.all_class_non_max_suppressionfor efficient box filtering.topk,gather_nd, andwhereoperators to ensure the output tensors (boxes, classes, scores, num_detections) match the TFLite specification in terms of shape and layout.num_classes,max_detections, and scaling factors.Validation
Verified with linting and pre-commit hooks:
Result: