コード例 #1
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')
    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_detector(model, args.pcd)
    # show the results
    show_result_meshlab(data,
                        result,
                        args.out_dir,
                        args.score_thr,
                        show=args.show,
                        snapshot=args.snapshot)
コード例 #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
コード例 #3
0
def test_inference_detector():
    if not torch.cuda.is_available():
        pytest.skip('test requires GPU and torch+cuda')

    pcd = 'tests/data/kitti/training/velodyne_reduced/000000.bin'
    detector_cfg = 'configs/pointpillars/hv_pointpillars_secfpn_' \
                   '6x8_160e_kitti-3d-3class.py'
    detector = init_model(detector_cfg, device='cuda:0')
    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
コード例 #4
0
ファイル: inference.py プロジェクト: Yaonian72/Autodrive
 def run(self, data_bin, threshold=0.3):
     result, data = inference_detector(self.model, data_bin)
     obj_ind = result[0]['scores_3d'] >= threshold
     pred_3d = result[0]['boxes_3d'].corners[obj_ind, ...]
     pred_2d = []
     for obj in pred_3d:
         obj_2d = self.calib.project_velo_to_image(obj)
         pred_2d.append([
             np.min(obj_2d, axis=0)[0],
             np.min(obj_2d, axis=0)[1],
             np.max(obj_2d, axis=0)[0],
             np.max(obj_2d, axis=0)[1]
         ])
     return pred_2d, [
         xx.squeeze() for xx in np.split(pred_3d, pred_3d.shape[0], axis=0)
     ]
コード例 #5
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)
コード例 #6
0
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)
    print("Selected pcd_file:", pcd_file)

    result, data = inference_detector(model, pcd_file)
    print("Number of detected bboxes:", len(result['labels_3d']))

    # Convert to MeshLab
    os.makedirs(args.outdir, exist_ok=True)
    show_result_meshlab(data, result, args.outdir)
    print("Visualization result is saved in \'{}\'. "
          "Please use MeshLab to visualize it.".format(
              os.path.join(args.outdir,
                           os.path.basename(pcd_file).split('.')[0])))
コード例 #7
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)
コード例 #8
0
ファイル: mypcd_demo.py プロジェクト: lkk688/mymmdetection3d
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)
コード例 #9
0
        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
print(type(pred_bboxes))#numpy.ndarray
# boxes_3d
# scores_3d
コード例 #10
0
if __name__ == '__main__':

    mmdet3d_dir = '../mmdetection3d/'
    config_file = os.path.join(mmdet3d_dir,
                               "configs/3dssd/3dssd_kitti-3d-car.py")
    ckpt_file = os.path.join(mmdet3d_dir,
                             "checkpoints/3dssd_kitti-3d-car/latest.pth")
    # build the model from a config file and a checkpoint file
    from mmdet3d.apis import init_detector, inference_detector, show_result_meshlab

    from tqdm import tqdm
    model = init_detector(config_file, ckpt_file, device='cuda:0')
    preds = []
    for i in tqdm(range(len(dataset))):
        result, data = inference_detector(model, dataset.get_lidar_filename(i))
        threshold = 0.5
        bboxes, scores = result[0]['boxes_3d'].corners, result[0]['scores_3d']
        pred = bboxes[scores > threshold]
        preds.append(pred)

    def anim(t):
        global fig_3d
        mlab.clf()
        t = int(t)
        img = dataset.get_image(t)
        pcd = dataset.get_lidar(t)
        calib = dataset.get_calibration(t)
        _, gt, _, _ = dataset.get_object(t)
        pred = preds[t]
        img_height, img_width, _ = img.shape