W1b: `Boxes.from_tensor(..., validate_boxes=True)` never validates the vertex modes; `'vertices'` deforms a non-rectangular or reordered quadrilateral instead of rejecting it
Summary
Boxes.from_tensor(boxes, mode, validate_boxes=True) documents validate_boxes as "check if boxes are valid rectangles or not. Valid rectangles are those with width and height >= 1 (>= 2 when mode ends with '_plus' suffix)" (kornia/geometry/boxes.py:524 at e0969438). The check exists only for the 'xyxy', 'xyxy_plus' and 'xywh' modes (_boxes_to_quadrilaterals, boxes.py:139-143). The two vertex modes are never validated, and 'vertices' goes further: its exclusive-to-inclusive import subtracts one from fixed vertex slots — x of vertices 1 and 2, y of vertices 2 and 3 — so a non-rectangular or non-canonically-ordered quadrilateral is silently deformed instead of rejected.
Reproduction
import torch
from kornia.geometry.boxes import Boxes
q = torch.tensor([[[0., 0.], [9., 0.], [3., 7.], [0., 1.]]]) # not a rectangle
Boxes.from_tensor(q, mode="vertices", validate_boxes=True).data # accepted
Boxes.from_tensor(q, mode="vertices_plus", validate_boxes=True).data # accepted, stored verbatim
inv = torch.tensor([[[5., 5.], [1., 5.], [1., 1.], [5., 1.]]]) # axis-aligned, vertices in reversed order
Boxes.from_tensor(inv, mode="vertices", validate_boxes=True).to_tensor("xywh")
Boxes.from_tensor(torch.tensor([[5., 5., 1., 1.]]), mode="xyxy", validate_boxes=True) # the xy* modes do rejectObserved
vertices -> data = [[[0., 0.], [8., 0.], [2., 6.], [0., 0.]]] # fourth vertex collapsed onto the first, no error
vertices_plus -> data = [[[0., 0.], [9., 0.], [3., 7.], [0., 1.]]] # no error
inverted 'vertices' -> xywh [[0., 0., 6., 6.]] # the box spans x=1..5; width 6 comes from subtracting at the wrong slots
xyxy -> ValueError: Some boxes have negative widths or 0.validate_bbox from kornia.geometry.bbox returns False for q and True for inv, so neither of the existing checks is what validate_boxes applies here; it applies nothing.
Expected
Either validate_boxes=True rejects vertex input that is not an axis-aligned rectangle in the documented clockwise order (a parallel-edges check plus the same extent test the 'xy*' modes run), or the docstring says that the flag is a no-op for the vertex modes and that 'vertices' assumes the canonical layout. Making the flag validate would start raising on inputs that are accepted today, so it is a Repair & Deprecation window item; the docstring correction is not.
Disposition
n/a — single symbol.
Context
Found in review of #4060, which documents the current behavior in the Boxes Convention block ("Vertex modes are not validated, and 'vertices' additionally deforms a non-rectangular quadrilateral") and pins it with test_convention_vertices_import_deforms_a_non_rectangular_quadrilateral. That prose and pin should carry this issue as a wart anchor, so the eventual fix has a pin to flip and the AGENTS.md blast-radius grep finds the sentence. The deformation arithmetic itself is the #3934 +1; this issue is about the missing validation, which survives #3934 unchanged. Sub-unit extents on the 'xy*' modes are #4061, a different hole.
Environment
kornia 0.9.0rc1 @ e0969438 (main), torch 2.9.1, python 3.11, cpu.
Posted on behalf of @ducha-aiki by Claude (Fable 5.1).
Source: kornia/kornia