fix(anchors): allow flexible anchor size specification across feature maps (issue #2135) - #9596
Open
jlaportebot wants to merge 1 commit into
Open
fix(anchors): allow flexible anchor size specification across feature maps (issue #2135)#9596jlaportebot wants to merge 1 commit into
jlaportebot wants to merge 1 commit into
Conversation
… maps (issue pytorch#2135) - Modified AnchorGenerator to accept flat sizes/aspect_ratios tuples that apply to all feature maps - New API: AnchorGenerator(sizes=(32, 64, 128), aspect_ratios=(0.5, 1.0, 2.0)) applies all sizes to all feature maps - Legacy API: AnchorGenerator(sizes=((32,), (64,), (128,)), aspect_ratios=((0.5, 1.0, 2.0),) * 3) unchanged - Updated RPN, RetinaNet, and FCOS to handle new anchor format (list of lists per image/feature level) - Added comprehensive tests for new flexible API and backward compatibility Closes pytorch#2135
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9596
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. |
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 addresses issue #2135 by allowing users to specify anchor sizes and aspect ratios that apply to ALL feature maps, rather than requiring one sizes tuple per feature map.
Problem
The original AnchorGenerator API required users to specify sizes as a tuple of tuples, where each inner tuple corresponds to a specific feature map:
This was confusing because users expected to specify sizes that apply to all feature maps (as stated in the docs: "sizes[i] and aspect_ratios[i] can have an arbitrary number of elements").
Solution
Added a new flexible API that accepts flat tuples:
The module auto-detects which API is being used and expands flat tuples to all feature maps in the forward pass.
Changes
anchor_utils.py: Modified AnchorGenerator to support both APIs:
rpn.py: Updated RPN to handle new anchor format (list of lists per image/feature level)
retinanet.py: Updated RetinaNet to handle new anchor format
fcos.py: Updated FCOS to handle new anchor format
test_anchor_distribution.py: New comprehensive test suite (10 tests)
test_models_detection_anchor_utils.py: Updated existing tests for compatibility
Testing
Backward Compatibility
Fully backward compatible - existing code using tuple-of-tuples syntax continues to work unchanged.
Closes #2135