Improve RPN error messages for anchor/head count mismatches - #9599
Improve RPN error messages for anchor/head count mismatches#9599tonycoder-hub wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9599
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @tonycoder-hub! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Fixes #1539
Summary
When an
AnchorGeneratoris configured with a different number of anchors perlocation than the
RPNHeadexpects (or with a different number of featurelevels), the RPN previously failed with an opaque
RuntimeErrorfromBoxCoder.decode's reshape, or with an internalAssertionErrorfromAnchorGenerator.grid_anchors. Neither message explained which configurationhad to change.
This change adds an early, per-feature-level validation in
RegionProposalNetwork.forwardthat runs immediately after the RPN headproduces its
objectnessandpred_bbox_deltasoutputs and before theanchor generator is invoked. For each level it checks:
anchor generator was configured for.
objectnesschannel count)matches
AnchorGenerator.num_anchors_per_location()for that level.anchor on that level.
On any mismatch a clear
ValueErroris raised that names the offending level,the generator's per-location counts, and the head's expected count, so users
can correct the
sizes/aspect_ratiosof the anchor generator or thenum_anchorsof the RPN head.Behavior
computation are unchanged.
the output tensor shapes, not from private head attributes.
matching strictly implies total matching.
Verification
test_rpn_anchor_count_mismatchtest_rpn_anchor_count_mismatch_per_level_cancellationtest_rpn_anchor_level_count_mismatchtest/test_models_detection_utils.pypassed (14 tests; six pre-existingwarnings).
git diff --checkpassed.AI assistance
This change was produced with Claude Code (
alwaysday1_maxthroughsuper-relay), then independently tested and reviewed before submission.