Commit 5b7004f4 authored by Yezhen Cong's avatar Yezhen Cong Committed by Tai-Wang
Browse files

Change cam rot_3d_in_axis (#906)

parent 720caedf
......@@ -137,11 +137,8 @@ class CameraInstance3DBoxes(BaseInstance3DBoxes):
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
......@@ -182,11 +179,7 @@ class CameraInstance3DBoxes(BaseInstance3DBoxes):
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]
......
......@@ -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([
......
......@@ -391,7 +391,8 @@ class SSD3DHead(VoteHead):
# 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(
......
......@@ -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'))]
......
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment