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

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

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

ZCMax's avatar
ZCMax committed
10
11

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


def main(args):
    # register all modules in mmdet into the registries
    register_all_modules()
35
36
37

    # build the model from a config file and a checkpoint file
    model = init_model(args.config, args.checkpoint, device=args.device)
ZCMax's avatar
ZCMax committed
38
39
40
41
42
43
44
45
46

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

    # test a single point cloud sample
47
    result, data = inference_segmentor(model, args.pcd)
ZCMax's avatar
ZCMax committed
48
49
50

    points = np.fromfile(args.pcd, dtype=np.float32)
    data_input = dict(points=points)
51
    # show the results
ZCMax's avatar
ZCMax committed
52
53
54
55
56
57
58
59
60
    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='seg')
61
62
63


if __name__ == '__main__':
ZCMax's avatar
ZCMax committed
64
65
    args = parse_args()
    main(args)