Skip to content

Commit

Permalink
precommit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
calcoloergosum committed Aug 27, 2024
1 parent 9301577 commit 3c32830
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions mmrotate/core/bbox/coder/angle_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ def __init__(self, angle_version, omega=1, window='gaussian', radius=6):
self.angle_version = angle_version
assert angle_version in ['oc', 'le90', 'le135', 'full360']
assert window in ['gaussian', 'triangle', 'rect', 'pulse']
self.angle_range = 90 if angle_version == 'oc' else (360 if angle_version == 'full360' else 180)
self.angle_offset_dict = {'oc': 0, 'le90': 90, 'le135': 45, 'full360': 0}
self.angle_range = 90 if angle_version == 'oc' else \
(360 if angle_version == 'full360' else 180)
self.angle_offset_dict = {
'oc': 0,
'le90': 90,
'le135': 45,
'full360': 180
}
self.angle_offset = self.angle_offset_dict[angle_version]
self.omega = omega
self.window = window
Expand Down
6 changes: 3 additions & 3 deletions mmrotate/core/bbox/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def poly2obb_full360(polys):
torch.pow(pt2[..., 0] - pt3[..., 0], 2) +
torch.pow(pt2[..., 1] - pt3[..., 1], 2))
angles = torch.atan2((pt1[..., 1] - pt2[..., 1]),
(pt1[..., 0] - pt2[..., 0]))
(pt1[..., 0] - pt2[..., 0]))
angles = norm_angle(angles, 'full360')
x_ctr = (pt1[..., 0] + pt3[..., 0]) / 2.0
y_ctr = (pt1[..., 1] + pt3[..., 1]) / 2.0
Expand Down Expand Up @@ -460,8 +460,8 @@ def poly2obb_np_le90(poly):


def poly2obb_np_full360(poly):
"""Convert polygons to oriented bounding boxes.
Assumes head points then tail points.
"""Convert polygons to oriented bounding boxes. Assumes head points then
tail points.
Args:
polys (ndarray): [x0,y0,x1,y1,x2,y2,x3,y3]
Expand Down
11 changes: 7 additions & 4 deletions tests/test_utils/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ def test_transforms():

# test full360
# Check obb2poly and poly2obb is inverse function in full360 rotation
for angle in np.linspace(- .9 * np.pi, .9 * np.pi, 4):
for angle in np.linspace(-.9 * np.pi, .9 * np.pi, 4):
# numpy version
box_np = np.array((100, 100, 80, 50, angle), dtype=np.float32)
pts_np = rtf.obb2poly_np(box_np[None], version='full360')[0]
box2_np = rtf.poly2obb_np(pts_np, version='full360')
np.testing.assert_almost_equal(box_np, box2_np, decimal=4)

# torch version
box_torch = torch.tensor((100, 100, 80, 50, angle), dtype=torch.float32)
box_torch = torch.tensor((100, 100, 80, 50, angle),
dtype=torch.float32)
pts_torch = rtf.obb2poly(box_torch[None], version='full360')[0]
box2_torch = rtf.poly2obb(pts_torch, version='full360')[0]
torch.testing.assert_close(box_torch, box2_torch, rtol=1e-4, atol=1e-4)

# compatibility
torch.testing.assert_close(box_torch, torch.from_numpy(box_np), rtol=1e-4, atol=1e-4)
torch.testing.assert_close(pts_torch, torch.from_numpy(pts_np), rtol=1e-4, atol=1e-4)
torch.testing.assert_close(
box_torch, torch.from_numpy(box_np), rtol=1e-4, atol=1e-4)
torch.testing.assert_close(
pts_torch, torch.from_numpy(pts_np), rtol=1e-4, atol=1e-4)

0 comments on commit 3c32830

Please sign in to comment.