Skip to content

Fix tv_tensors.wrap to preserve subclass types for BoundingBoxes and KeyPoints#9332

Merged
NicolasHug merged 5 commits intopytorch:mainfrom
raimbekovm:fix/wrap-subclass-preservation
Jan 23, 2026
Merged

Fix tv_tensors.wrap to preserve subclass types for BoundingBoxes and KeyPoints#9332
NicolasHug merged 5 commits intopytorch:mainfrom
raimbekovm:fix/wrap-subclass-preservation

Conversation

@raimbekovm
Copy link
Copy Markdown
Contributor

@raimbekovm raimbekovm commented Jan 8, 2026

Summary

Fixes tv_tensors.wrap() to preserve subclass types when wrapping instances of custom subclasses of BoundingBoxes or KeyPoints.

The bug: The function used hardcoded class names (BoundingBoxes._wrap() and KeyPoints._wrap()) instead of type(like)._wrap(), causing it to return base class instances instead of the actual subclass type.

The fix: Replace BoundingBoxes._wrap() with type(like)._wrap() and similarly for KeyPoints._wrap(). This is consistent with how other TV tensor types are already handled (line 39).

Fixes #9328

cc @vfdev-5

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Jan 8, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9332

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 1dfd61b with merge base 7a78e54 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the cla signed label Jan 8, 2026
@zy1git
Copy link
Copy Markdown
Contributor

zy1git commented Jan 13, 2026

@raimbekovm Thank you for the PR. Could you please add the non-regression test to test your implementation? Feel free to let me know if you need more guidance for that.

Test that tv_tensors.wrap() preserves subclass types for BoundingBoxes
and KeyPoints instead of returning base class instances.
@raimbekovm
Copy link
Copy Markdown
Contributor Author

Done, added the regression test in 1ef69bf

Copy link
Copy Markdown
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @raimbekovm and @zy1git for the review!

@NicolasHug NicolasHug merged commit 894601f into pytorch:main Jan 23, 2026
64 checks passed
@github-actions
Copy link
Copy Markdown

Hey @NicolasHug!

You merged this PR, but no labels were added.
The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

@raimbekovm
Copy link
Copy Markdown
Contributor Author

Thank you for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tv_tensors.wrap doesn't work with subclasses of BoundingBoxes or KeyPoints

3 participants