Exemple #1
0
def main():
    parser = ArgumentParser()
    parser.add_argument('pcd', help='Point cloud file')
    parser.add_argument('image', help='image file')
    parser.add_argument('ann', help='ann file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--score-thr', type=float, default=0.0, help='bbox score threshold')
    parser.add_argument(
        '--out-dir', type=str, default='demo', help='dir to save results')
    parser.add_argument(
        '--show', action='store_true', help='show online visuliaztion results')
    parser.add_argument(
        '--snapshot',
        action='store_true',
        help='whether to save online visuliaztion results')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result, data = inference_multi_modality_detector(model, args.pcd,
                                                     args.image, args.ann)
    # show the results
    show_result_meshlab(
        data,
        result,
        args.out_dir,
        args.score_thr,
        show=args.show,
        snapshot=args.snapshot)
Exemple #2
0
def test_inference_detector():
    pcd = 'tests/data/kitti/training/velodyne_reduced/000000.bin'
    detector_cfg = 'configs/pointpillars/hv_pointpillars_secfpn_' \
                   '6x8_160e_kitti-3d-3class.py'
    detector = init_detector(detector_cfg, device='cpu')
    results = inference_detector(detector, pcd)
    bboxes_3d = results[0][0]['boxes_3d']
    scores_3d = results[0][0]['scores_3d']
    labels_3d = results[0][0]['labels_3d']
    assert bboxes_3d.tensor.shape[0] >= 0
    assert bboxes_3d.tensor.shape[1] == 7
    assert scores_3d.shape[0] >= 0
    assert labels_3d.shape[0] >= 0
Exemple #3
0
def main():
    parser = ArgumentParser()
    parser.add_argument('pcd', help='Point cloud file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--score-thr', type=float, default=0.0, help='bbox score threshold')
    parser.add_argument(
        '--out-dir', type=str, default='demo', help='dir to save results')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result, data = inference_detector(model, args.pcd)
Exemple #4
0
                    nargs='+',
                    default=0,
                    help="Sample index in the dataset")

parser.add_argument("--outdir",
                    type=str,
                    default='cache/',
                    help="Path to the output directory")

args = parser.parse_args()

# Build dataset and model
cfg = mmcv.Config.fromfile(args.cfg)
dataset = build_dataset(cfg.data.val)

model = init_detector(args.cfg, args.ckpt, device='cuda')


# Execution function
def execution(idx):
    global dataset, model, cfg, args
    print()

    # Select and infer a sample
    sample = dataset.__getitem__(idx)
    if isinstance(sample['img_metas'], list):
        filename = sample['img_metas'][0].data['pts_filename']
    else:
        filename = sample['img_metas'].data['pts_filename']

    pcd_file = os.path.join(dataset.root_split, dataset.pts_prefix, filename)
Exemple #5
0
from mmdet3d.apis import init_detector, inference_detector, show_result_meshlab

#%%

config_file = '../configs/3dssd/3dssd_kitti-3d-car.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
checkpoint_file = '../checkpoints/3dssd_kitti-3d-car/latest.pth'

#%%

# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

#%%

# test a single sample
pcd = 'kitti_000008.bin'
result, data = inference_detector(model, pcd)

print(model)
Exemple #6
0
def main():
    parser = ArgumentParser()
    parser.add_argument(
        '--pcd',
        type=str,
        default='./demo/kitti_000008.bin',
        help='Point cloud file'
    )  #/data/cmpe249-fa21/4c_train5678/training/velodyne/008118.bin
    parser.add_argument(
        '--config',
        type=str,
        default=
        './configs/second/myhv_second_secfpn_sbn_2x16_2x_waymoD5-3d-4class.py',
        help='Config file')
    parser.add_argument(
        '--checkpoint',
        type=str,
        default=
        '../modelzoo_mmdetection3d/hv_second_secfpn_6x8_80e_kitti-3d-3class_20200620_230238-9208083a.pth',
        help='Checkpoint file')
    parser.add_argument('--device',
                        default='cuda:0',
                        help='Device used for inference')
    parser.add_argument('--score-thr',
                        type=float,
                        default=0.6,
                        help='bbox score threshold')
    parser.add_argument('--out-dir',
                        type=str,
                        default='demo',
                        help='dir to save results')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result, data = inference_detector(model, args.pcd)
    print(result)  # three keys: 'boxes_3d', 'scores_3d', 'labels_3d'

    points = data['points'][0][0].cpu().numpy()  # points number *4
    pts_filename = data['img_metas'][0][0]['pts_filename']
    print("pts_filename:", pts_filename)
    file_name = osp.split(pts_filename)[-1].split('.')[0]  #006767
    print(data['img_metas'])
    print(data['img_metas'][0][0]['box_mode_3d'])  #Box3DMode.LIDAR

    print("results len:", len(result[0]))  # len=1,
    for res in result[0].keys():
        print(res)
    #boxes_3d, scores_3d, labels_3d
    pred_bboxes = result[0]['boxes_3d'].tensor.numpy()
    print(
        pred_bboxes
    )  # [11,7], Each row is (x, y, z, x_size, y_size, z_size, yaw) in Box3DMode.LIDAR
    print(type(pred_bboxes))  #numpy.ndarray

    print("box_mode_3d:",
          data['img_metas'][0][0]['box_mode_3d'])  #Box3DMode.LIDAR

    # show the results (points save to xxx_points.obj file, pred3d box save to xxx_pred.ply, these two files can opend by meshlab)
    show_result_meshlab(data, result, args.out_dir)
Exemple #7
0
    def __init__(self, checkpoint, config, calib_file, from_video=True):

        self.model = init_detector(config, checkpoint)
        self.calib = Calibration(calib_file, from_video=from_video)
        sample_num = corners3d.shape[0]
        corners3d_hom = np.concatenate((corners3d, np.ones((sample_num, 8, 1))), axis=2)  # (N, 8, 4)

        img_pts = np.matmul(corners3d_hom, P2.T)  # (N, 8, 3), The transposed array.

        x, y = img_pts[:, :, 0] / img_pts[:, :, 2], img_pts[:, :, 1] / img_pts[:, :, 2]
        x1, y1 = np.min(x, axis=1), np.min(y, axis=1)
        x2, y2 = np.max(x, axis=1), np.max(y, axis=1)

        boxes = np.concatenate((x1.reshape(-1, 1), y1.reshape(-1, 1), x2.reshape(-1, 1), y2.reshape(-1, 1)), axis=1)
        boxes_corner = np.concatenate((x.reshape(-1, 8, 1), y.reshape(-1, 8, 1)), axis=2)

        return boxes, boxes_corner

# build the model from a config file and a checkpoint file
model = init_detector(base_folder+config_file, base_folder+checkpoint_file, device='cuda:0')

# test a single image and show the results
result, data = inference_detector(model, point_cloud)

points = data['points'][0][0].cpu().numpy()# points number *4
pts_filename = data['img_metas'][0][0]['pts_filename']
file_name = osp.split(pts_filename)[-1].split('.')[0] #006767
print(data['img_metas'])
print(data['img_metas'][0][0]['box_mode_3d']) #Box3DMode.LIDAR

print(len(result))
for res in result[0].keys():
    print(res)
pred_bboxes = result[0]['boxes_3d'].tensor.numpy()
print(pred_bboxes)# [11,7], Each row is (x, y, z, x_size, y_size, z_size, yaw) in Box3DMode.LIDAR