ADLab-AutoDrive / BEVFusion

Offical PyTorch implementation of "BEVFusion: A Simple and Robust LiDAR-Camera Fusion Framework"
Apache License 2.0
752 stars 102 forks source link

The question of GlobalRotScaleTransBEV #63

Open hht1996ok opened 1 year ago

hht1996ok commented 1 year ago

Thank you for your contribution to the community. In this data enhanced code, why does the rotation angle of point take a negative value while box takes a positive value.

@PIPELINES.register_module() class GlobalRotScaleTransBEV: def init(self, resize_lim, rot_lim, trans_lim, is_train): self.resize_lim = resize_lim self.rot_lim = rot_lim self.trans_lim = trans_lim self.is_train = is_train

def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
    transform = np.eye(4).astype(np.float32)

    if self.is_train:
        scale = random.uniform(*self.resize_lim)
        theta = random.uniform(*self.rot_lim)
        translation = np.array([random.normal(0, self.trans_lim) for i in range(3)])
        rotation = np.eye(3)

        if "points" in data:
            data["points"].rotate(-theta)
            data["points"].translate(translation)
            data["points"].scale(scale)

        gt_boxes = data["gt_bboxes_3d"]
        # print(gt_boxes.rotate(theta))
hht1996ok commented 1 year ago

@tingtingliangvs

hht1996ok commented 1 year ago

Could you tell me why the rotation matrix of the point cloud is like this when axis==0.

def rotate(self, rotation, axis=None): """Rotate points with the given rotation matrix or angle. Args: rotation (float, np.ndarray, torch.Tensor): Rotation matrix or angle. axis (int): Axis to rotate at. Defaults to None. """ if not isinstance(rotation, torch.Tensor): rotation = self.tensor.new_tensor(rotation) assert rotation.shape == torch.Size([3, 3]) or \ rotation.numel() == 1

    if axis is None:
        axis = self.rotation_axis

    if rotation.numel() == 1:
        rot_sin = torch.sin(rotation)
        rot_cos = torch.cos(rotation)
        if axis == 1:
            rot_mat_T = rotation.new_tensor([[rot_cos, 0, -rot_sin],
                                             [0, 1, 0],
                                             [rot_sin, 0, rot_cos]])
        elif axis == 2 or axis == -1:
            rot_mat_T = rotation.new_tensor([[rot_cos, -rot_sin, 0],
                                             [rot_sin, rot_cos, 0],
                                             [0, 0, 1]])
        elif axis == 0:
            rot_mat_T = rotation.new_tensor([[0, rot_cos, -rot_sin],
                                             [0, rot_sin, rot_cos],
                                             [1, 0, 0]])
        else:
            raise ValueError('axis should in range')
        rot_mat_T = rot_mat_T.T
    elif rotation.numel() == 9:
        rot_mat_T = rotation
    else:
        raise NotImplementedError
    self.tensor[:, :3] = self.tensor[:, :3] @ rot_mat_T