[detection] Faster R-CNN accepts negative box_detections_per_img and applies Python slicing

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

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia dall’implementazione del rilevamento Faster R-CNN di TorchVision e segui come box_detections_per_img viene applicato agli indici successivi a NMS; l’issue individua il comportamento dello slicing negativo, ma non indica alcun file o test. Controlla i test di rilevamento esistenti ed esegui un test mirato per i limiti negativi. Il lavoro è completato quando il comportamento previsto dal progetto è esplicito e i valori negativi funzionano come previsto oppure generano un ValueError chiaro.

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

Descrizione

🐛 Describe the bug

The Faster R-CNN factory accepts a negative box_detections_per_img. On the tested build, the value is applied as a Python negative slice to the post-NMS detection indices. For example, with 46 baseline detections, -1 returns 45 and -2 returns 44. This is surprising for a parameter documented as the maximum number of detections per image.

Could the project clarify whether negative values are intended to be supported? If not, would it be preferable to reject them with a ValueError instead of silently dropping the final detections?

Minimal reproducer
import torch
import torchvision
from torchvision.models.detection import fasterrcnn_mobilenet_v3_large_320_fpn

print("torch:", torch.__version__)
print("torchvision:", torchvision.__version__)

image = torch.linspace(0, 1, 3 * 64 * 64).reshape(3, 64, 64)
with torch.no_grad():
    for limit in (100, -1, -2, 0):
        torch.manual_seed(109150)
        model = fasterrcnn_mobilenet_v3_large_320_fpn(
            weights=None,
            weights_backbone=None,
            num_classes=2,
            box_score_thresh=0.0,
            box_nms_thresh=1.0,
            box_detections_per_img=limit,
            min_size=64,
            max_size=64,
        ).eval()
        result = model([image])[0]
        print(limit, len(result["scores"]))

On the reported CPU configuration, output counts were 100 -> 46, -1 -> 45, -2 -> 44, and 0 -> 0. Same-model comparisons found the negative-limit boxes, scores, and labels equal to Python slices of the positive-limit result.

Expected behavior

Please clarify the intended behavior for negative values. If they are invalid, rejecting them explicitly would avoid silently interpreting a configuration error as Python slicing.


### Versions

### Environment

- Linux x86_64, Python 3.12.7, PyTorch 2.14.1+cpu, TorchVision 0.29.1+cpu.
- Also reproduced on PyTorch 2.5.1+cpu / TorchVision 0.20.1+cpu and PyTorch 2.10.0+cu128 / TorchVision 0.25.0+cu128; the CUDA build was tested with CPU input.
- Randomly initialized model; no checkpoint download required.
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.