| 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 | |