Skip to content

Allow non-tensor labels in SanitizeBoundingBoxes and SanitizeKeyPoints - #9656

Open
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:feat/sanitize-indexable-labels
Open

Allow non-tensor labels in SanitizeBoundingBoxes and SanitizeKeyPoints#9656
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:feat/sanitize-indexable-labels

Conversation

@YeonwooSung

Copy link
Copy Markdown

Description

Honor the existing TODOs in SanitizeBoundingBoxes and SanitizeKeyPoints: labels no longer need to be tensors. They only need to be bool-indexable, or sequences that can be subset with the validity mask.

labels_getter may now return:

  • a single torch.Tensor, numpy.ndarray, or sequence (list/tuple) of per-box / per-keypoint values
  • a tuple/list of such entries (for sanitizing extra fields such as COCO iscrowd or area)

Length is taken from entry.shape[0] when a leading dimension exists, otherwise len(entry). Tensors and ndarrays are indexed with the 1-D bool validity mask; lists and tuples are reconstructed as the same type, keeping only the valid items. None entries and non-indexable objects (for example a bare int) are still rejected.

Box and mask sanitization is unchanged. Sequence labels are treated as pytree leaves so they are subset as a whole rather than flattened into individual values.

Test plan

  • python -m pytest test/test_transforms_v2.py -k "SanitizeBoundingBoxes or SanitizeKeyPoints or sanitize" -q --tb=short
  • Covers existing tensor labels, list/tuple labels, numpy int arrays, mixed multi-entry labels, and the updated error cases for non-indexable / None entries.

@pytorch-bot

pytorch-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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.

@meta-cla meta-cla Bot added the cla signed label Sep 5, 2026
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.

1 participant