pcd_demo.py 2.02 KB
Newer Older
dingchang's avatar
dingchang committed
1
# Copyright (c) OpenMMLab. All rights reserved.
wuyuefeng's avatar
Demo  
wuyuefeng committed
2
3
from argparse import ArgumentParser

ZCMax's avatar
ZCMax committed
4
import numpy as np
wuyuefeng's avatar
Demo  
wuyuefeng committed
5

ZCMax's avatar
ZCMax committed
6
7
8
from mmdet3d.apis import inference_detector, init_model
from mmdet3d.registry import VISUALIZERS
from mmdet3d.utils import register_all_modules
wuyuefeng's avatar
Demo  
wuyuefeng committed
9

ZCMax's avatar
ZCMax committed
10
11

def parse_args():
wuyuefeng's avatar
Demo  
wuyuefeng committed
12
13
14
15
16
17
18
    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(
19
        '--score-thr', type=float, default=0.0, help='bbox score threshold')
wuyuefeng's avatar
Demo  
wuyuefeng committed
20
21
    parser.add_argument(
        '--out-dir', type=str, default='demo', help='dir to save results')
22
    parser.add_argument(
Zongbao Feng's avatar
Zongbao Feng committed
23
24
25
        '--show',
        action='store_true',
        help='show online visualization results')
26
27
28
    parser.add_argument(
        '--snapshot',
        action='store_true',
Zongbao Feng's avatar
Zongbao Feng committed
29
        help='whether to save online visualization results')
wuyuefeng's avatar
Demo  
wuyuefeng committed
30
    args = parser.parse_args()
ZCMax's avatar
ZCMax committed
31
32
33
34
35
36
    return args


def main(args):
    # register all modules in mmdet into the registries
    register_all_modules()
wuyuefeng's avatar
Demo  
wuyuefeng committed
37

ZCMax's avatar
ZCMax committed
38
    # TODO: Support inference of point cloud numpy file.
wuyuefeng's avatar
Demo  
wuyuefeng committed
39
    # build the model from a config file and a checkpoint file
40
    model = init_model(args.config, args.checkpoint, device=args.device)
ZCMax's avatar
ZCMax committed
41
42
43
44
45
46
47
48
49

    # init visualizer
    visualizer = VISUALIZERS.build(model.cfg.visualizer)
    visualizer.dataset_meta = {
        'CLASSES': model.CLASSES,
        'PALETTE': model.palette
    }

    # test a single point cloud sample
wuyuefeng's avatar
Demo  
wuyuefeng committed
50
    result, data = inference_detector(model, args.pcd)
ZCMax's avatar
ZCMax committed
51
52
53

    points = np.fromfile(args.pcd, dtype=np.float32)
    data_input = dict(points=points)
wuyuefeng's avatar
Demo  
wuyuefeng committed
54
    # show the results
ZCMax's avatar
ZCMax committed
55
56
57
58
59
60
61
62
63
    visualizer.add_datasample(
        'result',
        data_input,
        pred_sample=result,
        show=True,
        wait_time=0,
        out_file=args.out_file,
        pred_score_thr=args.score_thr,
        vis_task='det')
wuyuefeng's avatar
Demo  
wuyuefeng committed
64
65
66


if __name__ == '__main__':
ZCMax's avatar
ZCMax committed
67
68
    args = parse_args()
    main(args)