Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Change axis=1 behaviour of rotation_3d_in_axis #906

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions mmdet3d/core/bbox/structures/cam_box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ def corners(self):
corners_norm = corners_norm - dims.new_tensor([0.5, 1, 0.5])
corners = dims.view([-1, 1, 3]) * corners_norm.reshape([1, 8, 3])

# positive direction of the gravity axis
# in cam coord system points to the earth
# so the rotation is clockwise if viewed from above
corners = rotation_3d_in_axis(
corners, self.tensor[:, 6], axis=self.YAW_AXIS, clockwise=True)
corners, self.tensor[:, 6], axis=self.YAW_AXIS)
corners += self.tensor[:, :3].view(-1, 1, 3)
return corners

Expand Down Expand Up @@ -182,11 +179,7 @@ def rotate(self, angle, points=None):
self.tensor[:, 0:3],
angle,
axis=self.YAW_AXIS,
return_mat=True,
# positive direction of the gravity axis
# in cam coord system points to the earth
# so the rotation is clockwise if viewed from above
clockwise=True)
return_mat=True)
else:
rot_mat_T = angle
rot_sin = rot_mat_T[2, 0]
Expand Down
4 changes: 2 additions & 2 deletions mmdet3d/core/bbox/structures/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def rotation_3d_in_axis(points,
if points.shape[-1] == 3:
if axis == 1 or axis == -2:
rot_mat_T = torch.stack([
torch.stack([rot_cos, zeros, rot_sin]),
torch.stack([rot_cos, zeros, -rot_sin]),
torch.stack([zeros, ones, zeros]),
torch.stack([-rot_sin, zeros, rot_cos])
torch.stack([rot_sin, zeros, rot_cos])
])
elif axis == 2 or axis == -1:
rot_mat_T = torch.stack([
Expand Down
3 changes: 2 additions & 1 deletion mmdet3d/models/dense_heads/ssd_3d_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def get_targets_single(self,
# LiDARInstance3DBoxes and DepthInstance3DBoxes
canonical_xyz = rotation_3d_in_axis(
canonical_xyz.unsqueeze(0).transpose(0, 1),
-gt_bboxes_3d.yaw[assignment], 2).squeeze(1)
-gt_bboxes_3d.yaw[assignment],
axis=2).squeeze(1)
distance_front = torch.clamp(
size_res_targets[:, 0] - canonical_xyz[:, 0], min=0)
distance_back = torch.clamp(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_models/test_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ def test_imvoxelnet():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')

imvoxelnet_cfg = _get_detector_cfg('imvoxelnet/imvoxelnet_kitti-3d-car.py')
imvoxelnet_cfg = _get_detector_cfg(
'imvoxelnet/imvoxelnet_4x8_kitti-3d-car.py')
self = build_detector(imvoxelnet_cfg).cuda()
imgs = torch.rand([1, 3, 384, 1280], dtype=torch.float32).cuda()
gt_bboxes_3d = [LiDARInstance3DBoxes(torch.rand([3, 7], device='cuda'))]
Expand Down
26 changes: 25 additions & 1 deletion tests/test_utils/test_box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,13 +1553,37 @@ def test_rotation_3d_in_axis():
[[-0.2555, -0.2683, 0.0000],
[-0.2555, -0.2683, 0.9072]]])
angles = [np.pi / 2, -np.pi / 2]
rotated = rotation_3d_in_axis(points, angles, axis=0)
rotated = rotation_3d_in_axis(points, angles, axis=0).numpy()
expected_rotated = np.array([[[-0.4599, 0.0000, -0.0471],
[-0.4599, -1.8433, -0.0471]],
[[-0.2555, 0.0000, 0.2683],
[-0.2555, 0.9072, 0.2683]]])
assert np.allclose(rotated, expected_rotated, atol=1e-3)

points = torch.tensor([[[-0.4599, -0.0471, 0.0000],
[-0.4599, -0.0471, 1.8433]],
[[-0.2555, -0.2683, 0.0000],
[-0.2555, -0.2683, 0.9072]]])
angles = [np.pi / 2, -np.pi / 2]
rotated = rotation_3d_in_axis(points, angles, axis=1).numpy()
expected_rotated = np.array([[[0.0000, -0.0471, 0.4599],
[1.8433, -0.0471, 0.4599]],
[[0.0000, -0.2683, -0.2555],
[-0.9072, -0.2683, -0.2555]]])
assert np.allclose(rotated, expected_rotated, atol=1e-3)

points = torch.tensor([[[-0.4599, -0.0471, 0.0000],
[-0.4599, 0.0471, 1.8433]],
[[-0.2555, -0.2683, 0.0000],
[0.2555, -0.2683, 0.9072]]])
angles = [np.pi / 2, -np.pi / 2]
rotated = rotation_3d_in_axis(points, angles, axis=2).numpy()
expected_rotated = np.array([[[0.0471, -0.4599, 0.0000],
[-0.0471, -0.4599, 1.8433]],
[[-0.2683, 0.2555, 0.0000],
[-0.2683, -0.2555, 0.9072]]])
assert np.allclose(rotated, expected_rotated, atol=1e-3)

points = torch.tensor([[[-0.0471, 0.0000], [-0.0471, 1.8433]],
[[-0.2683, 0.0000], [-0.2683, 0.9072]]])
angles = [np.pi / 2, -np.pi / 2]
Expand Down