giantmonkeyTC
2344
34d1f8b

LiDAR-Based 3D Semantic Segmentation

LiDAR-based 3D semantic segmentation is one of the most basic tasks supported in MMDetection3D. It expects the given model to take any number of points with features collected by LiDAR as input, and predict the semantic labels for each input point. Next, taking PointNet++ (SSG) on the ScanNet dataset as an example, we will show how to prepare data, train and test a model on a standard 3D semantic segmentation benchmark, and how to visualize and validate the results.

Data Preparation

To begin with, we need to download the raw data from ScanNet's official website.

Due to different ways of organizing the raw data in different datasets, we typically need to collect the useful data information with a .pkl or .json file.

So after getting all the raw data ready, we can follow the instructions presented in ScanNet README doc to generate data infos.

Afterwards, the related folder structure should be as follows:

mmdetection3d
β”œβ”€β”€ mmdet3d
β”œβ”€β”€ tools
β”œβ”€β”€ configs
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ scannet
β”‚   β”‚   β”œβ”€β”€ scannet_utils.py
β”‚   β”‚   β”œβ”€β”€ batch_load_scannet_data.py
β”‚   β”‚   β”œβ”€β”€ load_scannet_data.py
β”‚   β”‚   β”œβ”€β”€ scannet_utils.py
β”‚   β”‚   β”œβ”€β”€ README.md
β”‚   β”‚   β”œβ”€β”€ scans
β”‚   β”‚   β”œβ”€β”€ scans_test
β”‚   β”‚   β”œβ”€β”€ scannet_instance_data
β”‚   β”‚   β”œβ”€β”€ points
β”‚   β”‚   β”œβ”€β”€ instance_mask
β”‚   β”‚   β”œβ”€β”€ semantic_mask
β”‚   β”‚   β”œβ”€β”€ seg_info
β”‚   β”‚   β”‚   β”œβ”€β”€ train_label_weight.npy
β”‚   β”‚   β”‚   β”œβ”€β”€ train_resampled_scene_idxs.npy
β”‚   β”‚   β”‚   β”œβ”€β”€ val_label_weight.npy
β”‚   β”‚   β”‚   β”œβ”€β”€ val_resampled_scene_idxs.npy
β”‚   β”‚   β”œβ”€β”€ scannet_infos_train.pkl
β”‚   β”‚   β”œβ”€β”€ scannet_infos_val.pkl
β”‚   β”‚   β”œβ”€β”€ scannet_infos_test.pkl

Training

Then let us train a model with provided configs for PointNet++ (SSG). You can basically follow this tutorial for sample scripts when training with different GPU settings. Suppose we use 2 GPUs on a single machine with distributed training:

./tools/dist_train.sh configs/pointnet2/pointnet2_ssg_2xb16-cosine-200e_scannet-seg.py 2

Note that 2xb16 in the config name refers to the training is completed with 2 GPUs and 16 samples on each GPU. If your customized setting is different from this, sometimes you need to adjust the learning rate accordingly. A basic rule can be referred to here.

Quantitative Evaluation

During training, the model checkpoints will be evaluated regularly according to the setting of train_cfg = dict(val_interval=xxx) in the config. We support official evaluation protocols for different datasets. For ScanNet, the model will be evaluated with mean Intersection over Union (mIoU) over all 20 categories. The evaluation results will be printed in the command like:

+---------+--------+--------+---------+--------+--------+--------+--------+--------+--------+-----------+---------+---------+--------+---------+--------------+----------------+--------+--------+---------+----------------+--------+--------+---------+
| classes | wall   | floor  | cabinet | bed    | chair  | sofa   | table  | door   | window | bookshelf | picture | counter | desk   | curtain | refrigerator | showercurtrain | toilet | sink   | bathtub | otherfurniture | miou   | acc    | acc_cls |
+---------+--------+--------+---------+--------+--------+--------+--------+--------+--------+-----------+---------+---------+--------+---------+--------------+----------------+--------+--------+---------+----------------+--------+--------+---------+
| results | 0.7257 | 0.9373 | 0.4625  | 0.6613 | 0.7707 | 0.5562 | 0.5864 | 0.4010 | 0.4558 | 0.7011    | 0.2500  | 0.4645  | 0.4540 | 0.5399  | 0.2802       | 0.3488         | 0.7359 | 0.4971 | 0.6922  | 0.3681         | 0.5444 | 0.8118 | 0.6695  |
+---------+--------+--------+---------+--------+--------+--------+--------+--------+--------+-----------+---------+---------+--------+---------+--------------+----------------+--------+--------+---------+----------------+--------+--------+---------+

In addition, you can also evaluate a specific model checkpoint after training is finished. Simply run scripts like the following:

./tools/dist_test.sh configs/pointnet2/pointnet2_ssg_16x2_cosine_200e_scannet-seg.py work_dirs/pointnet2_ssg/latest.pth 8

Testing and Making a Submission

If you would like to only conduct inference or test the model performance on the online benchmark, you should change ann_file='scannet_infos_val.pkl' to ann_file='scannet_infos_test.pkl' in the ScanNet dataset's config. Remember to specify the submission_prefix in the test_evaluator, e.g., adding test_evaluator = dict(type='SegMetric', submission_prefix=work_dirs/pointnet2_ssg/test_submission) or just add --cfg-options test_evaluator.submission_prefix=work_dirs/pointnet2_ssg/test_submission in the end of command. After generating the results, you can basically compress the folder and upload to the ScanNet evaluation server.

Qualitative Validation

MMDetection3D also provides versatile tools for visualization such that you can use tools/misc/visualize_results.py with results pkl file for offline visualization of add --show in the end of test command to do the online visualization. Besides, we also provide scripts tools/misc/browse_dataset.py to visualize the dataset without inference. Please refer more details in the doc for visualization.