Skip to content

Commit

Permalink
Fix init in cam_box3d (wrong default box origin) (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tai-Wang authored Oct 7, 2020
1 parent edebb3e commit 733df01
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mmdet3d/core/bbox/structures/cam_box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ class CameraInstance3DBoxes(BaseInstance3DBoxes):
boxes.
"""

def __init__(self,
tensor,
box_dim=7,
with_yaw=True,
origin=(0.5, 1.0, 0.5)):
if isinstance(tensor, torch.Tensor):
device = tensor.device
else:
device = torch.device('cpu')
tensor = torch.as_tensor(tensor, dtype=torch.float32, device=device)
if tensor.numel() == 0:
# Use reshape, so we don't end up creating a new tensor that
# does not depend on the inputs (and consequently confuses jit)
tensor = tensor.reshape((0, box_dim)).to(
dtype=torch.float32, device=device)
assert tensor.dim() == 2 and tensor.size(-1) == box_dim, tensor.size()

if tensor.shape[-1] == 6:
# If the dimension of boxes is 6, we expand box_dim by padding
# 0 as a fake yaw and set with_yaw to False.
assert box_dim == 6
fake_rot = tensor.new_zeros(tensor.shape[0], 1)
tensor = torch.cat((tensor, fake_rot), dim=-1)
self.box_dim = box_dim + 1
self.with_yaw = False
else:
self.box_dim = box_dim
self.with_yaw = with_yaw
self.tensor = tensor

if origin != (0.5, 1.0, 0.5):
dst = self.tensor.new_tensor((0.5, 1.0, 0.5))
src = self.tensor.new_tensor(origin)
self.tensor[:, :3] += self.tensor[:, 3:6] * (dst - src)

@property
def height(self):
"""torch.Tensor: A vector with height of each box."""
Expand Down

0 comments on commit 733df01

Please sign in to comment.