Fix numpy swap

pull/4484/head
Glenn Jocher 2 years ago
parent 0072942607
commit 89992ade15
  1. 2
      tests/test_python.py
  2. 4
      ultralytics/utils/ops.py

@ -353,7 +353,7 @@ def test_utils_ops():
make_divisible(17, torch.tensor([8]))
boxes = torch.rand(10, 4) # xywhn
boxes = torch.rand(10, 4) # xywh
torch.allclose(boxes, xyxy2xywh(xywh2xyxy(boxes)))
torch.allclose(boxes, xyxy2xywhn(xywhn2xyxy(boxes)))
torch.allclose(boxes, ltwh2xywh(xywh2ltwh(boxes)))

@ -473,7 +473,7 @@ def xyxyxyxy2xywhr(corners):
(numpy.ndarray | torch.Tensor): Converted data in [cx, cy, w, h, rotation] format of shape (n, 5).
"""
is_numpy = isinstance(corners, np.ndarray)
atan2, sqrt = (torch.atan2, torch.sqrt) if is_numpy else (np.arctan2, np.sqrt)
atan2, sqrt = (np.arctan2, np.sqrt) if is_numpy else (torch.atan2, torch.sqrt)
x1, y1, x2, y2, x3, y3, x4, y4 = corners.T
cx = (x1 + x3) / 2
@ -501,7 +501,7 @@ def xywhr2xyxyxyxy(center):
(numpy.ndarray | torch.Tensor): Converted corner points of shape (n, 8).
"""
is_numpy = isinstance(center, np.ndarray)
cos, sin = (torch.cos, torch.sin) if is_numpy else (np.cos, np.sin)
cos, sin = (np.cos, np.sin) if is_numpy else (torch.cos, torch.sin)
cx, cy, w, h, rotation = center.T
rotation *= math.pi / 180.0 # degrees to radians

Loading…
Cancel
Save