Beispiel #1
0
    def transform_points_to_voxels(self,
                                   data_dict=None,
                                   config=None,
                                   voxel_generator=None):
        if data_dict is None:
            from spconv.utils import VoxelGenerator

            voxel_generator = VoxelGenerator(
                voxel_size=config.VOXEL_SIZE,
                point_cloud_range=self.point_cloud_range,
                max_num_points=config.MAX_POINTS_PER_VOXEL,
                max_voxels=config.MAX_NUMBER_OF_VOXELS[self.mode])
            grid_size = (self.point_cloud_range[3:6] -
                         self.point_cloud_range[0:3]) / np.array(
                             config.VOXEL_SIZE)
            self.grid_size = np.round(grid_size).astype(np.int64)
            self.voxel_size = config.VOXEL_SIZE
            return partial(self.transform_points_to_voxels,
                           voxel_generator=voxel_generator)
        points = data_dict['points']
        voxels, coordinates, num_points = voxel_generator.generate(points)
        if not data_dict['use_lead_xyz']:
            voxels = voxels[..., 3:]  # remove xyz in voxels(N, 3)

        data_dict['voxels'] = voxels
        data_dict['voxel_coords'] = coordinates
        data_dict['voxel_num_points'] = num_points
        return data_dict
Beispiel #2
0
def noise_robustness(batch_size, ret):
    """
    Add noise points around every ground truth box for SECOND and Point-RCNN.
    The idea is proposed in TANet (AAAI 2020), https://arxiv.org/pdf/1912.05163.pdf.

    How to use:
    For now, this function should be added to line 179 of pcdet/datasets/dataset.py
    TODO: Integrate with pcdet/datasets/dataset.py
    Change no_of_pts to number of uniformly generated noise points desired
    around each GT bounding box.

    :param batch_size:
    :param ret:
    :return:
    """
    if True:
        np.random.seed(0)  # Numpy module.
        voxels_flag = True
        no_of_pts = 100
        voxel_list = []
        coords_list = []
        num_points_list = []
        for k in range(batch_size):
            for i_box in range(len(ret['gt_boxes'][k])):
                bbox = ret['gt_boxes'][k][i_box]
                cx = bbox[0]
                cy = bbox[1]
                cz = bbox[2]
                l = bbox[3]
                w = bbox[4]
                h = bbox[5]
                z1 = np.random.uniform(cx + l // 2, cx + 3 * l,
                                       (no_of_pts // 2, 1))
                z2 = np.random.uniform(cx - l // 2, cx - 3 * l,
                                       (no_of_pts // 2, 1))
                z = np.concatenate([z1, z2], 0)
                y1 = np.random.uniform(cy + w // 2, cy + 3 * w,
                                       (no_of_pts // 2, 1))
                y2 = np.random.uniform(cy - w // 2, cy - 3 * w,
                                       (no_of_pts // 2, 1))
                y = np.concatenate([y1, y2], 0)
                x1 = np.random.uniform(cz + h // 2, cz + 3 * h,
                                       (no_of_pts // 2, 1))
                x2 = np.random.uniform(cz - h // 2, cz - 3 * h,
                                       (no_of_pts // 2, 1))
                x = np.concatenate([x1, x2], 0)
                r = np.ones([no_of_pts, 1])
                b = np.zeros([no_of_pts, 1]) + k
                noise = np.concatenate([b, z, y, x, r], 1)
                ret['points'] = np.concatenate([ret['points'], noise], 0)

            if voxels_flag:
                voxel_generator = VoxelGenerator(
                    voxel_size=[0.05, 0.05, 0.1],
                    point_cloud_range=[0, -40, -3, 70.4, 40, 1],
                    max_num_points=5,
                    max_voxels=40000,
                )
                batch_mask = ret['points'][:, 0] == k
                points_extract = ret['points'][batch_mask, :]
                voxels, coordinates, num_points = voxel_generator.generate(
                    points_extract[:, 1:])
                voxel_list.append(voxels)
                coords_list.append(coordinates)
                num_points_list.append(num_points)

        if voxels_flag:
            ret['voxels'] = np.concatenate(voxel_list, axis=0)
            ret['voxel_num_points'] = np.concatenate(num_points_list, axis=0)
            coors = []
            for i, coor in enumerate(coords_list):
                coor_pad = np.pad(coor, ((0, 0), (1, 0)),
                                  mode='constant',
                                  constant_values=i)
                coors.append(coor_pad)
            ret['voxel_coords'] = np.concatenate(coors, axis=0)

    return ret