Ejemplo n.º 1
0
    def sample_class_v2(self, name, num, gt_boxes):
        '''
            This func aims to select fixed number of gt boxes from gt database with collision (bev iou) test performed.
        '''

        # sample num gt_boxes from gt_database
        sampled = self._sampler_dict[name].sample(num)
        sampled = copy.deepcopy(sampled)

        num_sampled = len(sampled)
        num_gt = gt_boxes.shape[0]

        # get all boxes: gt_boxes + sp_boxes
        sp_boxes = np.stack([i["box3d_lidar"] for i in sampled],
                            axis=0)  # todo: need modification here
        boxes = np.concatenate([gt_boxes, sp_boxes], axis=0).copy()

        offset = [0.0, 0.0]
        if self.gt_aug_with_context > 0.0:
            offset = [self.gt_aug_with_context, self.gt_aug_with_context]

        # get all boxes_bev: gt_boxes_bev + sampled_boxes_bev
        sp_boxes_new = boxes[num_gt:]
        gt_boxes_bv = box_np_ops.center_to_corner_box2d(
            gt_boxes[:, 0:2], gt_boxes[:, 3:5], gt_boxes[:, -1])
        sp_boxes_bv = box_np_ops.center_to_corner_box2d(
            sp_boxes_new[:, 0:2], sp_boxes_new[:, 3:5] + offset,
            sp_boxes_new[:, -1])
        total_bv = np.concatenate([gt_boxes_bv, sp_boxes_bv], axis=0)

        # collision test on bev (stricter than 3d)
        coll_mat = prep.box_collision_test(total_bv,
                                           total_bv)  # todo: too slow here
        diag = np.arange(total_bv.shape[0])
        coll_mat[diag, diag] = False

        # get valid samples
        valid_samples = []
        for i in range(
                num_gt, num_gt + num_sampled
        ):  # todo: the overall box num may not meet the requirement
            if coll_mat[i].any():
                # i-th sampled box is not considered into auged gt-boxes.
                coll_mat[i] = False
                coll_mat[:, i] = False
            else:
                # i-th sampled box is considered into auged gt-boxes.
                valid_samples.append(sampled[i - num_gt])

        return valid_samples
Ejemplo n.º 2
0
    def sample_class_v2(self, name, num, gt_boxes):
        sampled = self._sampler_dict[name].sample(num)
        sampled = copy.deepcopy(sampled)
        num_gt = gt_boxes.shape[0]
        num_sampled = len(sampled)
        gt_boxes_bv = box_np_ops.center_to_corner_box2d(
            gt_boxes[:, 0:2], gt_boxes[:, 3:5], gt_boxes[:, -1])

        sp_boxes = np.stack([i["box3d_lidar"] for i in sampled], axis=0)

        valid_mask = np.zeros([gt_boxes.shape[0]], dtype=np.bool_)
        valid_mask = np.concatenate(
            [valid_mask,
             np.ones([sp_boxes.shape[0]], dtype=np.bool_)], axis=0)
        boxes = np.concatenate([gt_boxes, sp_boxes], axis=0).copy()
        if self._enable_global_rot:
            # place samples to any place in a circle.
            prep.noise_per_object_v3_(boxes,
                                      None,
                                      valid_mask,
                                      0,
                                      0,
                                      self._global_rot_range,
                                      num_try=100)

        sp_boxes_new = boxes[gt_boxes.shape[0]:]
        sp_boxes_bv = box_np_ops.center_to_corner_box2d(
            sp_boxes_new[:, 0:2], sp_boxes_new[:, 3:5], sp_boxes_new[:, -1])

        total_bv = np.concatenate([gt_boxes_bv, sp_boxes_bv], axis=0)
        # coll_mat = collision_test_allbox(total_bv)
        coll_mat = prep.box_collision_test(total_bv, total_bv)
        diag = np.arange(total_bv.shape[0])
        coll_mat[diag, diag] = False

        valid_samples = []
        for i in range(num_gt, num_gt + num_sampled):
            if coll_mat[i].any():
                coll_mat[i] = False
                coll_mat[:, i] = False
            else:
                if self._enable_global_rot:
                    sampled[i - num_gt]["box3d_lidar"][:2] = boxes[i, :2]
                    sampled[i - num_gt]["box3d_lidar"][-1] = boxes[i, -1]
                    sampled[i - num_gt]["rot_transform"] = (
                        boxes[i, -1] - sp_boxes[i - num_gt, -1])
                valid_samples.append(sampled[i - num_gt])
        return valid_samples
Ejemplo n.º 3
0
    def sample_group(self, name, num, gt_boxes, gt_group_ids):
        sampled, group_num = self.sample(name, num)
        sampled = copy.deepcopy(sampled)
        # rewrite sampled group id to avoid duplicated with gt group ids
        gid_map = {}
        max_gt_gid = np.max(gt_group_ids)
        sampled_gid = max_gt_gid + 1
        for s in sampled:
            gid = s["group_id"]
            if gid in gid_map:
                s["group_id"] = gid_map[gid]
            else:
                gid_map[gid] = sampled_gid
                s["group_id"] = sampled_gid
                sampled_gid += 1

        num_gt = gt_boxes.shape[0]
        gt_boxes_bv = box_np_ops.center_to_corner_box2d(
            gt_boxes[:, 0:2], gt_boxes[:, 3:5], gt_boxes[:, -1])

        sp_boxes = np.stack([i["box3d_lidar"] for i in sampled], axis=0)
        sp_group_ids = np.stack([i["group_id"] for i in sampled], axis=0)
        valid_mask = np.zeros([gt_boxes.shape[0]], dtype=np.bool_)
        valid_mask = np.concatenate(
            [valid_mask,
             np.ones([sp_boxes.shape[0]], dtype=np.bool_)], axis=0)
        boxes = np.concatenate([gt_boxes, sp_boxes], axis=0).copy()
        group_ids = np.concatenate([gt_group_ids, sp_group_ids], axis=0)
        if self._enable_global_rot:
            # place samples to any place in a circle.
            prep.noise_per_object_v3_(
                boxes,
                None,
                valid_mask,
                0,
                0,
                self._global_rot_range,
                group_ids=group_ids,
                num_try=100,
            )
        sp_boxes_new = boxes[gt_boxes.shape[0]:]
        sp_boxes_bv = box_np_ops.center_to_corner_box2d(
            sp_boxes_new[:, 0:2], sp_boxes_new[:, 3:5], sp_boxes_new[:, -1])
        total_bv = np.concatenate([gt_boxes_bv, sp_boxes_bv], axis=0)
        # coll_mat = collision_test_allbox(total_bv)
        coll_mat = prep.box_collision_test(total_bv, total_bv)
        diag = np.arange(total_bv.shape[0])
        coll_mat[diag, diag] = False
        valid_samples = []
        idx = num_gt
        for num in group_num:
            if coll_mat[idx:idx + num].any():
                coll_mat[idx:idx + num] = False
                coll_mat[:, idx:idx + num] = False
            else:
                for i in range(num):
                    if self._enable_global_rot:
                        sampled[idx - num_gt +
                                i]["box3d_lidar"][:2] = boxes[idx + i, :2]
                        sampled[idx - num_gt +
                                i]["box3d_lidar"][-1] = boxes[idx + i, -1]
                        sampled[idx - num_gt + i]["rot_transform"] = (
                            boxes[idx + i, -1] -
                            sp_boxes[idx + i - num_gt, -1])

                    valid_samples.append(sampled[idx - num_gt + i])
            idx += num
        return valid_samples
Ejemplo n.º 4
0
    def sample_class_v2(self, name, num, gt_boxes):

        # sample num gt_boxes from gt_database
        sampled = self._sampler_dict[name].sample(num)
        sampled = copy.deepcopy(sampled)
        num_sampled = len(sampled)

        # get all boxes: gt_boxes + sp_boxes
        num_gt = gt_boxes.shape[0]
        gt_boxes_bv = box_np_ops.center_to_corner_box2d(
            gt_boxes[:, 0:2], gt_boxes[:, 3:5], gt_boxes[:, -1])
        sp_boxes = np.stack([i["box3d_lidar"] for i in sampled],
                            axis=0)  # todo: need modification here
        boxes = np.concatenate([gt_boxes, sp_boxes], axis=0).copy()

        # unused: get mask
        valid_mask = np.zeros([gt_boxes.shape[0]], dtype=np.bool_)
        valid_mask = np.concatenate(
            [valid_mask,
             np.ones([sp_boxes.shape[0]], dtype=np.bool_)], axis=0)
        if self._enable_global_rot:  # False
            prep.noise_per_object_v3_(boxes,
                                      None,
                                      valid_mask,
                                      0,
                                      0,
                                      self._global_rot_range,
                                      num_try=100)

        # get all boxes_bev: gt_boxes_bev + sampled_boxes_bev
        sp_boxes_new = boxes[gt_boxes.shape[0]:]
        sp_boxes_bv = box_np_ops.center_to_corner_box2d(
            sp_boxes_new[:, 0:2], sp_boxes_new[:, 3:5], sp_boxes_new[:, -1])
        total_bv = np.concatenate([gt_boxes_bv, sp_boxes_bv], axis=0)

        # collision test on bev (stricter than 3d)
        coll_mat = prep.box_collision_test(total_bv,
                                           total_bv)  # todo: too slow here
        diag = np.arange(total_bv.shape[0])
        coll_mat[diag, diag] = False

        # get valid samples
        valid_samples = []
        for i in range(
                num_gt, num_gt + num_sampled
        ):  # todo: without multiple try times, sometimes, the overall box num may not meet the requirement
            if coll_mat[i].any():
                # i-th sampled box is not considered into gt-boxes.
                coll_mat[i] = False
                coll_mat[:, i] = False
            else:
                if self._enable_global_rot:  # False
                    sampled[i - num_gt]["box3d_lidar"][:2] = boxes[
                        i, :2]  # boxes has got noise
                    sampled[i - num_gt]["box3d_lidar"][-1] = boxes[i, -1]
                    sampled[i - num_gt]["rot_transform"] = (
                        boxes[i, -1] - sp_boxes[i - num_gt, -1])
                # i-th sampled box is considered into gt-boxes.
                valid_samples.append(sampled[i - num_gt])

        return valid_samples