test_semantickitti_dataset.py 4.29 KB
Newer Older
ZCMax's avatar
ZCMax committed
1
2
3
4
5
# Copyright (c) OpenMMLab. All rights reserved.
import unittest

import numpy as np

6
from mmdet3d.datasets import SemanticKittiDataset
ZCMax's avatar
ZCMax committed
7
8
9
10
11
12
from mmdet3d.utils import register_all_modules


def _generate_semantickitti_dataset_config():
    data_root = './tests/data/semantickitti/'
    ann_file = 'semantickitti_infos.pkl'
13
14
15
16
    classes = ('car', 'bicycle', 'motorcycle', 'truck', 'bus', 'person',
               'bicyclist', 'motorcyclist', 'road', 'parking', 'sidewalk',
               'other-ground', 'building', 'fence', 'vegetation', 'trunck',
               'terrian', 'pole', 'traffic-sign')
17
18

    seg_label_mapping = {
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
        0: 19,  # "unlabeled"
        1: 19,  # "outlier" mapped to "unlabeled" --------------mapped
        10: 0,  # "car"
        11: 1,  # "bicycle"
        13: 4,  # "bus" mapped to "other-vehicle" --------------mapped
        15: 2,  # "motorcycle"
        16: 4,  # "on-rails" mapped to "other-vehicle" ---------mapped
        18: 3,  # "truck"
        20: 4,  # "other-vehicle"
        30: 5,  # "person"
        31: 6,  # "bicyclist"
        32: 7,  # "motorcyclist"
        40: 8,  # "road"
        44: 9,  # "parking"
        48: 10,  # "sidewalk"
        49: 11,  # "other-ground"
        50: 12,  # "building"
        51: 13,  # "fence"
        52: 19,  # "other-structure" mapped to "unlabeled" ------mapped
        60: 8,  # "lane-marking" to "road" ---------------------mapped
        70: 14,  # "vegetation"
        71: 15,  # "trunk"
        72: 16,  # "terrain"
        80: 17,  # "pole"
        81: 18,  # "traffic-sign"
        99: 19,  # "other-object" to "unlabeled" ----------------mapped
        252: 0,  # "moving-car" to "car" ------------------------mapped
        253: 6,  # "moving-bicyclist" to "bicyclist" ------------mapped
        254: 5,  # "moving-person" to "person" ------------------mapped
        255: 7,  # "moving-motorcyclist" to "motorcyclist" ------mapped
        256: 4,  # "moving-on-rails" mapped to "other-vehic------mapped
        257: 4,  # "moving-bus" mapped to "other-vehicle" -------mapped
        258: 3,  # "moving-truck" to "truck" --------------------mapped
        259: 4  # "moving-other"-vehicle to "other-vehicle"-----mapped
53
54
    }
    max_label = 259
ZCMax's avatar
ZCMax committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    modality = dict(use_lidar=True, use_camera=False)
    pipeline = [
        dict(
            type='LoadPointsFromFile',
            coord_type='LIDAR',
            shift_height=True,
            load_dim=4,
            use_dim=[0, 1, 2]),
        dict(
            type='LoadAnnotations3D',
            with_bbox_3d=False,
            with_label_3d=False,
            with_mask_3d=False,
            with_seg_3d=True,
69
            seg_3d_dtype='np.int32'),
70
        dict(type='PointSegClassMapping'),
ZCMax's avatar
ZCMax committed
71
72
73
74
75
76
        dict(type='Pack3DDetInputs', keys=['points', 'pts_semantic_mask'])
    ]

    data_prefix = dict(
        pts='sequences/00/velodyne', pts_semantic_mask='sequences/00/labels')

77
78
    return (data_root, ann_file, classes, data_prefix, pipeline, modality,
            seg_label_mapping, max_label)
ZCMax's avatar
ZCMax committed
79
80


81
class TestSemanticKittiDataset(unittest.TestCase):
ZCMax's avatar
ZCMax committed
82
83

    def test_semantickitti(self):
84
85
        (data_root, ann_file, classes, data_prefix, pipeline, modality,
         seg_label_mapping,
86
         max_label) = _generate_semantickitti_dataset_config()
ZCMax's avatar
ZCMax committed
87
88

        register_all_modules()
89
        np.random.seed(0)
90
        semantickitti_dataset = SemanticKittiDataset(
ZCMax's avatar
ZCMax committed
91
92
            data_root,
            ann_file,
93
94
95
96
            metainfo=dict(
                classes=classes,
                seg_label_mapping=seg_label_mapping,
                max_label=max_label),
ZCMax's avatar
ZCMax committed
97
98
99
100
101
102
103
            data_prefix=data_prefix,
            pipeline=pipeline,
            modality=modality)

        input_dict = semantickitti_dataset.prepare_data(0)

        points = input_dict['inputs']['points']
104
        data_sample = input_dict['data_samples']
ZCMax's avatar
ZCMax committed
105
106
        pts_semantic_mask = data_sample.gt_pts_seg.pts_semantic_mask
        self.assertEqual(points.shape[0], pts_semantic_mask.shape[0])
107
108

        expected_pts_semantic_mask = np.array([
109
110
111
            12, 12, 12, 14, 14, 12, 19, 12, 14, 12, 12, 14, 15, 19, 14, 12, 12,
            12, 12, 19, 12, 12, 12, 12, 12, 14, 12, 15, 12, 14, 14, 17, 12, 14,
            14, 14, 15, 14, 12, 12, 14, 12, 17, 14, 12, 14, 12, 14, 14, 12
112
113
114
115
        ])

        self.assertTrue(
            (pts_semantic_mask.numpy() == expected_pts_semantic_mask).all())