sanitize_bounding_boxes computes the wrong height for rotated boxes

Aperta Adatta ai principianti
#9,689 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@u7k4rs6 ci sta già lavorando.

Dal 30/9/2026.

  • #9690 di @u7k4rs6 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Inizia in torchvision/transforms/v2/functional/_misc.py, in _get_sanitize_bounding_boxes_mask, quindi esamina i test di sanitize esistenti. Esegui i test pertinenti e aggiungi una copertura di regressione per i box ruotati CXCYWHR, XYWHR e XYXYXYXY, preservando il comportamento esistente di XYXY.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 Describe the bug

sanitize_bounding_boxes (and SanitizeBoundingBoxes) don't filter rotated boxes correctly. Thin boxes survive min_size, and min_area sees an inflated area.

Looks like an off-by-one in _get_sanitize_bounding_boxes_mask in torchvision/transforms/v2/functional/_misc.py. After converting to XYXYXYXY it computes:

dx23 = bounding_boxes[..., 3] - bounding_boxes[..., 5]  # y2 - y3
dy23 = bounding_boxes[..., 4] - bounding_boxes[..., 6]  # x3 - x4

so the "height" mixes coordinates from different corners (for an axis-aligned box it ends up being the diagonal). It should be indices 2/4 and 3/5.

Repro:

import torch
from torchvision import tv_tensors
from torchvision.transforms.v2 import functional as F

boxes = tv_tensors.BoundingBoxes(
    torch.tensor([[20, 20, 10, 0.5, 0], [20, 20, 10, 0.5, 30], [20, 20, 10, 10, 0]]),
    format="CXCYWHR", canvas_size=(40, 40),
)
print(F.sanitize_bounding_boxes(boxes, min_size=1)[1])
# tensor([True, True, True]), expected tensor([False, False, True])

xyxy = tv_tensors.BoundingBoxes(torch.tensor([[15, 19.75, 25, 20.25]]), format="XYXY", canvas_size=(40, 40))
print(F.sanitize_bounding_boxes(xyxy, min_size=1)[1])
# tensor([False]), same box as the first one above, correctly removed

It hits CXCYWHR, XYWHR and XYXYXYXY. The existing sanitize tests only use XYXY, which is probably why it slipped through. Happy to send a PR with the fix and a test.

Versions

torch 2.14.0+cpu, torchvision 0.29.0+cpu, Python 3.14, Linux. The same code is on main (6da25ff).

Lingua principale
Python
Stelle
18k
Fork
7.3k
Merge medio
4h 56m
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytorch/vision

Tutte le issue di pytorch/vision

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.