Beispiel #1
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)
        if num_gt > 0:
            gt_boxes_bv = box_np_ops.center_to_corner_box2d(
                gt_boxes[:, 0:2], gt_boxes[:, 3:5], gt_boxes[:, 6])

        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)
        if num_gt > 0:
            boxes = np.concatenate([gt_boxes, sp_boxes], axis=0).copy()
        else:
            boxes = sp_boxes
        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[:, 6])

        if num_gt > 0:
            total_bv = np.concatenate([gt_boxes_bv, sp_boxes_bv], axis=0)
        else:
            total_bv = sp_boxes_bv
        # 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"][6] = boxes[i, 6]
                    sampled[i - num_gt]["rot_transform"] = (
                        boxes[i, 6] - sp_boxes[i - num_gt, 6])
                valid_samples.append(sampled[i - num_gt])
        return valid_samples
Beispiel #2
0
    def sample_class_v2(self, name, num, gt_boxes):
        sampled = self._sampler_dict[name].sample(
            num)  # 调用类别对应的BatchSampler内的sample方法,返回用来采样对象的信息
        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[:, 6])  # 生成原始真值鸟瞰图

        sp_boxes = np.stack([i["box3d_lidar"] for i in sampled],
                            axis=0)  # 读取采样真值框,横向排列

        valid_mask = np.zeros([gt_boxes.shape[0]], dtype=np.bool_)  # 原始真值框标为0
        valid_mask = np.concatenate(
            [valid_mask,
             np.ones([sp_boxes.shape[0]], dtype=np.bool_)],
            axis=0)  # 将原始真值框标志0与采样真值框标志1拼起来
        boxes = np.concatenate([gt_boxes, sp_boxes],
                               axis=0).copy()  # 拼接原始真值框与采样真值框
        if self._enable_global_rot:  # False
            # 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[:, 6])  # 新采样框的鸟瞰图

        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:  # False
                    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
Beispiel #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[:, 6])

        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[:, 6])
        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