semantickitti_dataset.py 3.89 KB
Newer Older
dingchang's avatar
dingchang committed
1
# Copyright (c) OpenMMLab. All rights reserved.
ZCMax's avatar
ZCMax committed
2
from typing import Callable, List, Optional, Union
3

4
5
import numpy as np

6
from mmdet3d.registry import DATASETS
ZCMax's avatar
ZCMax committed
7
from .seg3d_dataset import Seg3DDataset
8
9
10


@DATASETS.register_module()
11
12
class SemanticKittiDataset(Seg3DDataset):
    r"""SemanticKitti Dataset.
13
14
15
16
17
18

    This class serves as the API for experiments on the SemanticKITTI Dataset
    Please refer to <http://www.semantic-kitti.org/dataset.html>`_
    for data downloading

    Args:
19
20
21
22
23
        data_root (str, optional): Path of dataset root. Defaults to None.
        ann_file (str): Path of annotation file. Defaults to ''.
        metainfo (dict, optional): Meta information for dataset, such as class
            information. Defaults to None.
        data_prefix (dict): Prefix for training data. Defaults to
24
            dict(pts='',
25
26
27
28
                 img='',
                 pts_instance_mask='',
                 pts_semantic_mask='').
        pipeline (List[dict]): Pipeline used for data processing.
29
30
31
32
33
34
35
36
            Defaults to [].
        modality (dict): Modality to specify the sensor data used as input,
            it usually has following keys:

                - use_camera: bool
                - use_lidar: bool
            Defaults to dict(use_lidar=True, use_camera=False).
        ignore_index (int, optional): The label index to be ignored, e.g.
37
            unannotated points. If None is given, set to len(self.classes) to
38
            be consistent with PointSegClassMapping function in pipeline.
39
            Defaults to None.
40
        scene_idxs (np.ndarray or str, optional): Precomputed index to load
41
            data. For scenes with many points, we may sample it several times.
42
            Defaults to None.
43
        test_mode (bool): Whether the dataset is in test mode.
44
45
            Defaults to False.
    """
ZCMax's avatar
ZCMax committed
46
    METAINFO = {
47
48
49
50
51
52
53
54
55
56
        'classes': ('car', 'bicycle', 'motorcycle', 'truck', 'bus', 'person',
                    'bicyclist', 'motorcyclist', 'road', 'parking', 'sidewalk',
                    'other-ground', 'building', 'fence', 'vegetation',
                    'trunck', 'terrian', 'pole', 'traffic-sign'),
        'palette': [[100, 150, 245], [100, 230, 245], [30, 60, 150],
                    [80, 30, 180], [100, 80, 250], [155, 30, 30],
                    [255, 40, 200], [150, 30, 90], [255, 0, 255],
                    [255, 150, 255], [75, 0, 75], [175, 0, 75], [255, 200, 0],
                    [255, 120, 50], [0, 175, 0], [135, 60, 0], [150, 240, 80],
                    [255, 240, 150], [255, 0, 0]],
57
        'seg_valid_class_ids':
58
        tuple(range(19)),
59
        'seg_all_class_ids':
60
        tuple(range(19)),
ZCMax's avatar
ZCMax committed
61
    }
62
63

    def __init__(self,
ZCMax's avatar
ZCMax committed
64
65
66
67
                 data_root: Optional[str] = None,
                 ann_file: str = '',
                 metainfo: Optional[dict] = None,
                 data_prefix: dict = dict(
68
                     pts='',
69
70
71
                     img='',
                     pts_instance_mask='',
                     pts_semantic_mask=''),
ZCMax's avatar
ZCMax committed
72
73
                 pipeline: List[Union[dict, Callable]] = [],
                 modality: dict = dict(use_lidar=True, use_camera=False),
74
75
76
                 ignore_index: Optional[int] = None,
                 scene_idxs: Optional[Union[str, np.ndarray]] = None,
                 test_mode: bool = False,
ZCMax's avatar
ZCMax committed
77
78
                 **kwargs) -> None:

79
80
81
        super().__init__(
            data_root=data_root,
            ann_file=ann_file,
ZCMax's avatar
ZCMax committed
82
83
            metainfo=metainfo,
            data_prefix=data_prefix,
84
85
            pipeline=pipeline,
            modality=modality,
ZCMax's avatar
ZCMax committed
86
87
88
89
            ignore_index=ignore_index,
            scene_idxs=scene_idxs,
            test_mode=test_mode,
            **kwargs)
90
91

    def get_seg_label_mapping(self, metainfo):
92
        seg_label_mapping = np.zeros(metainfo['max_label'] + 1, dtype=np.int64)
93
94
95
        for idx in metainfo['seg_label_mapping']:
            seg_label_mapping[idx] = metainfo['seg_label_mapping'][idx]
        return seg_label_mapping