Fix the RCNN export_onnx path under PIR - #9497
Open
aboccag wants to merge 1 commit into
Open
Conversation
RPNHead carries a __shared__ config key `export_onnx`. With it set, the RCNN
family emits a straight-line, batch-size-1 graph -- a Python loop over FPN
levels, then concat/topk/gather -- instead of the batch loop with TensorArray
accumulation. That is what makes an ONNX export of a two-stage detector
possible at all, and it had simply never been run under PIR.
Two one-liners, each restoring consistency with code a few lines away in the
same function:
* rpn_head: `paddle.shape(onnx_topk_rois)[0]` is a 0-d tensor under PIR, and
the caller indexes rois_num[0] -- IndexError: list index out of range. The
non-ONNX branch three lines up already slices [0:1].
* post_process: concat rejects the 0-d scalars that indexing scale_factor
now yields -- "The axis is expected to be in range of [0, 0)". The
non-ONNX branch already unsqueezes them, and carries a TODO(PIR) comment
saying exactly this.
Without these, faster_rcnn and friends export a graph containing while +
TensorArray + slice_array_dense, which no ONNX exporter can follow.
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.
Two one-liners that make
export_onnx=Truework again on the PIR path.RPNHeadcarries a__shared__config keyexport_onnx. With it set, the RCNNfamily emits a straight-line, batch-size-1 graph — a Python loop over FPN
levels, then concat/topk/gather — instead of the batch loop with TensorArray
accumulation. That is what makes an ONNX export of a two-stage detector possible
at all, and it had simply never been run under PIR.
Each change restores consistency with code a few lines above it in the same
function:
rpn_head.py—paddle.shape(onnx_topk_rois)[0]is a 0-d tensor underPIR and the caller indexes
rois_num[0], so the export fails withIndexError: list index out of range. The non-ONNX branch three lines upalready slices
[0:1].post_process.py—concatrejects the 0-d scalars that indexingscale_factornow yields:ValueError: The axis is expected to be in range of [0, 0). The non-ONNX branch already unsqueezes them, and carries aTODO(PIR)comment asking for exactly this fix.Without these,
faster_rcnnand friends export a graph containingwhile+TensorArray +
slice_array_dense, which no ONNX exporter can follow.Verified on Paddle 3.3 with
FLAGS_enable_pir_api=1: the whole two-stage familyexports, converts with paddle2onnx, and matches Paddle inference. For
faster_rcnn_r50_fpn_1x_coco, over 20 COCO images, 140 boxes compared, worstpairwise IoU 0.999992 and worst score delta 2.7e-06.