File size: 598 Bytes
9b92c75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import torch
from objectmodel_v1.boxes import (
box_cxcywh_to_xyxy,
box_xyxy_to_cxcywh,
generalized_box_iou,
)
def test_box_conversion_roundtrip():
boxes = torch.tensor([[0.5, 0.4, 0.2, 0.6], [0.2, 0.3, 0.1, 0.1]])
restored = box_xyxy_to_cxcywh(box_cxcywh_to_xyxy(boxes))
torch.testing.assert_close(restored, boxes)
def test_generalized_iou_identity_and_separation():
boxes = torch.tensor([[0.1, 0.1, 0.4, 0.4], [0.6, 0.6, 0.9, 0.9]])
giou = generalized_box_iou(boxes, boxes)
torch.testing.assert_close(giou.diag(), torch.ones(2))
assert giou[0, 1] < 0
|