From 884519a5e8df4d0fabdb7b5e8b490a1f621ba452 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Mon, 10 Jan 2022 14:47:25 +0800 Subject: [PATCH 1/5] add plane info in pkl file --- setup.cfg | 2 +- tools/data_converter/kitti_converter.py | 24 +++++++++++++++++------- tools/data_converter/kitti_data_utils.py | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index f998f9c7c9..c1a2151bd2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,7 @@ line_length = 79 multi_line_output = 0 known_standard_library = setuptools known_first_party = mmdet,mmseg,mmdet3d -known_third_party = cv2,imageio,indoor3d_util,load_scannet_data,lyft_dataset_sdk,m2r,matplotlib,mmcv,nuimages,numba,numpy,nuscenes,pandas,plyfile,pycocotools,pyquaternion,pytest,pytorch_sphinx_theme,recommonmark,requests,scannet_utils,scipy,seaborn,shapely,skimage,tensorflow,terminaltables,torch,trimesh,ts,waymo_open_dataset +known_third_party = cv2,imageio,indoor3d_util,load_scannet_data,lyft_dataset_sdk,m2r,matplotlib,mmcv,nuimages,numba,numpy,nuscenes,pandas,plyfile,pycocotools,pyquaternion,pytest,pytorch_sphinx_theme,recommonmark,requests,scannet_utils,scipy,seaborn,shapely,skimage,sphinx,tensorflow,terminaltables,torch,trimesh,ts,waymo_open_dataset no_lines_before = STDLIB,LOCALFOLDER default_section = THIRDPARTY diff --git a/tools/data_converter/kitti_converter.py b/tools/data_converter/kitti_converter.py index b7bff1d471..fb385b381b 100644 --- a/tools/data_converter/kitti_converter.py +++ b/tools/data_converter/kitti_converter.py @@ -94,9 +94,12 @@ def create_kitti_info_file(data_path, Args: data_path (str): Path of the data root. - pkl_prefix (str): Prefix of the info file to be generated. - save_path (str): Path to save the info file. - relative_path (bool): Whether to use relative path. + pkl_prefix (str, optional): Prefix of the info file to be generated. + Default: 'kitti'. + save_path (str, optional): Path to save the info file. + Default: None. + relative_path (bool, optional): Whether to use relative path. + Default: True. """ imageset_folder = Path(data_path) / 'ImageSets' train_img_ids = _read_imageset_file(str(imageset_folder / 'train.txt')) @@ -113,6 +116,7 @@ def create_kitti_info_file(data_path, training=True, velodyne=True, calib=True, + plane=True, image_ids=train_img_ids, relative_path=relative_path) _calculate_num_points_in_gt(data_path, kitti_infos_train, relative_path) @@ -124,6 +128,7 @@ def create_kitti_info_file(data_path, training=True, velodyne=True, calib=True, + plane=True, image_ids=val_img_ids, relative_path=relative_path) _calculate_num_points_in_gt(data_path, kitti_infos_val, relative_path) @@ -140,6 +145,7 @@ def create_kitti_info_file(data_path, label_info=False, velodyne=True, calib=True, + plane=False, image_ids=test_img_ids, relative_path=relative_path) filename = save_path / f'{pkl_prefix}_infos_test.pkl' @@ -158,10 +164,14 @@ def create_waymo_info_file(data_path, Args: data_path (str): Path of the data root. - pkl_prefix (str): Prefix of the info file to be generated. - save_path (str): Path to save the info file. - relative_path (bool): Whether to use relative path. - max_sweeps (int): Max sweeps before the detection frame to be used. + pkl_prefix (str, optional): Prefix of the info file to be generated. + Default: 'waymo'. + save_path (str, optional): Path to save the info file. + Default: None. + relative_path (bool, optional): Whether to use relative path. + Default: True. + max_sweeps (int, optional): Max sweeps before the detection frame + to be used. Default: 5. """ imageset_folder = Path(data_path) / 'ImageSets' train_img_ids = _read_imageset_file(str(imageset_folder / 'train.txt')) diff --git a/tools/data_converter/kitti_data_utils.py b/tools/data_converter/kitti_data_utils.py index 01538e065b..3d89fbe7fb 100644 --- a/tools/data_converter/kitti_data_utils.py +++ b/tools/data_converter/kitti_data_utils.py @@ -59,6 +59,17 @@ def get_label_path(idx, relative_path, exist_check, use_prefix_id) +def get_plane_path(idx, + prefix, + training=True, + relative_path=True, + exist_check=True, + info_type='planes', + use_prefix_id=False): + return get_kitti_info_path(idx, prefix, info_type, '.txt', training, + relative_path, exist_check, use_prefix_id) + + def get_velodyne_path(idx, prefix, training=True, @@ -143,6 +154,7 @@ def get_kitti_image_info(path, label_info=True, velodyne=False, calib=False, + plane=False, image_ids=7481, extend_matrix=True, num_worker=8, @@ -251,6 +263,17 @@ def map_func(idx): calib_info['Tr_imu_to_velo'] = Tr_imu_to_velo info['calib'] = calib_info + if plane: + plane_path = get_plane_path(idx, path, training, relative_path) + if relative_path: + plane_path = str(root_path / plane_path) + with open(plane_path, 'r') as f: + lines = f.readlines() + assert lines[0] == '# Matrix\n' + assert lines[1] == 'WIDTH 4\n' + assert lines[2] == 'HEIGHT 1\n' + info['plane'] = np.array([float(i) for i in lines[3].split()]) + if annotations is not None: info['annos'] = annotations add_difficulty_to_annos(info) From 4563e12eb80b379151810e7f4a0162913f2c549c Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Mon, 10 Jan 2022 15:07:26 +0800 Subject: [PATCH 2/5] add_plane_info --- docs/en/datasets/kitti_det.md | 3 ++- docs/zh_cn/datasets/kitti_det.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/en/datasets/kitti_det.md b/docs/en/datasets/kitti_det.md index 2562da92f2..bb3f46f126 100644 --- a/docs/en/datasets/kitti_det.md +++ b/docs/en/datasets/kitti_det.md @@ -6,7 +6,7 @@ This page provides specific tutorials about the usage of MMDetection3D for KITTI ## Prepare dataset -You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. +You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. Besides, the road planes could be downloaded from [HERE](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing), which are optional for data augmentation in the training for better performance. Like the general way to prepare dataset, it is recommended to symlink the dataset root to `$MMDETECTION3D/data`. @@ -29,6 +29,7 @@ mmdetection3d │ │ │ ├── image_2 │ │ │ ├── label_2 │ │ │ ├── velodyne +│ │ │ ├── planes (optional) ``` ### Create KITTI dataset diff --git a/docs/zh_cn/datasets/kitti_det.md b/docs/zh_cn/datasets/kitti_det.md index d901518df2..048c95eaa6 100644 --- a/docs/zh_cn/datasets/kitti_det.md +++ b/docs/zh_cn/datasets/kitti_det.md @@ -6,7 +6,7 @@ ## 数据准备 -您可以在[这里](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d)下载 KITTI 3D 检测数据并解压缩所有 zip 文件。 +您可以在[这里](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d)下载 KITTI 3D 检测数据并解压缩所有 zip 文件。此外,您可以在[这里](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing)下载道路平面信息,其在训练过程中作为一个可选项,用来提高模型的性能. 像准备数据集的一般方法一样,建议将数据集根目录链接到 `$MMDETECTION3D/data`。 @@ -29,6 +29,7 @@ mmdetection3d │ │ │ ├── image_2 │ │ │ ├── label_2 │ │ │ ├── velodyne +│ │ │ ├── planes (optional) ``` ### 创建 KITTI 数据集 From 8704a171b5fb9a77eb0c9a6f3283e17338364843 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 19 Jan 2022 15:11:57 +0800 Subject: [PATCH 3/5] fix comments --- docs/en/datasets/kitti_det.md | 2 +- tools/data_converter/kitti_converter.py | 6 +++--- tools/data_converter/kitti_data_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/datasets/kitti_det.md b/docs/en/datasets/kitti_det.md index bb3f46f126..cbbec4f7e4 100644 --- a/docs/en/datasets/kitti_det.md +++ b/docs/en/datasets/kitti_det.md @@ -6,7 +6,7 @@ This page provides specific tutorials about the usage of MMDetection3D for KITTI ## Prepare dataset -You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. Besides, the road planes could be downloaded from [HERE](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing), which are optional for data augmentation in the training for better performance. +You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. Besides, the road planes could be downloaded from [HERE](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing), which are optional for data augmentation during training for better performance. Like the general way to prepare dataset, it is recommended to symlink the dataset root to `$MMDETECTION3D/data`. diff --git a/tools/data_converter/kitti_converter.py b/tools/data_converter/kitti_converter.py index fb385b381b..436ef68528 100644 --- a/tools/data_converter/kitti_converter.py +++ b/tools/data_converter/kitti_converter.py @@ -116,7 +116,7 @@ def create_kitti_info_file(data_path, training=True, velodyne=True, calib=True, - plane=True, + with_plane=True, image_ids=train_img_ids, relative_path=relative_path) _calculate_num_points_in_gt(data_path, kitti_infos_train, relative_path) @@ -128,7 +128,7 @@ def create_kitti_info_file(data_path, training=True, velodyne=True, calib=True, - plane=True, + with_plane=True, image_ids=val_img_ids, relative_path=relative_path) _calculate_num_points_in_gt(data_path, kitti_infos_val, relative_path) @@ -145,7 +145,7 @@ def create_kitti_info_file(data_path, label_info=False, velodyne=True, calib=True, - plane=False, + with_plane=False, image_ids=test_img_ids, relative_path=relative_path) filename = save_path / f'{pkl_prefix}_infos_test.pkl' diff --git a/tools/data_converter/kitti_data_utils.py b/tools/data_converter/kitti_data_utils.py index 3d89fbe7fb..48058d110a 100644 --- a/tools/data_converter/kitti_data_utils.py +++ b/tools/data_converter/kitti_data_utils.py @@ -154,7 +154,7 @@ def get_kitti_image_info(path, label_info=True, velodyne=False, calib=False, - plane=False, + with_plane=False, image_ids=7481, extend_matrix=True, num_worker=8, @@ -263,7 +263,7 @@ def map_func(idx): calib_info['Tr_imu_to_velo'] = Tr_imu_to_velo info['calib'] = calib_info - if plane: + if with_plane: plane_path = get_plane_path(idx, path, training, relative_path) if relative_path: plane_path = str(root_path / plane_path) From d2a49e204d2564cd785284e3b5520ade8298250d Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 26 Jan 2022 16:33:56 +0800 Subject: [PATCH 4/5] change to mmcv api --- tools/data_converter/kitti_data_utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/data_converter/kitti_data_utils.py b/tools/data_converter/kitti_data_utils.py index 48058d110a..a9acc54374 100644 --- a/tools/data_converter/kitti_data_utils.py +++ b/tools/data_converter/kitti_data_utils.py @@ -1,4 +1,5 @@ # Copyright (c) OpenMMLab. All rights reserved. +import mmcv import numpy as np from collections import OrderedDict from concurrent import futures as futures @@ -267,11 +268,7 @@ def map_func(idx): plane_path = get_plane_path(idx, path, training, relative_path) if relative_path: plane_path = str(root_path / plane_path) - with open(plane_path, 'r') as f: - lines = f.readlines() - assert lines[0] == '# Matrix\n' - assert lines[1] == 'WIDTH 4\n' - assert lines[2] == 'HEIGHT 1\n' + lines = mmcv.list_from_file(plane_path) info['plane'] = np.array([float(i) for i in lines[3].split()]) if annotations is not None: From 6ad9c5d1eb3d2c63f0d9df2392223a726b181bfa Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Thu, 27 Jan 2022 12:48:53 +0800 Subject: [PATCH 5/5] change road plane link --- docs/en/datasets/kitti_det.md | 2 +- docs/zh_cn/datasets/kitti_det.md | 2 +- setup.cfg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/datasets/kitti_det.md b/docs/en/datasets/kitti_det.md index cbbec4f7e4..3398402443 100644 --- a/docs/en/datasets/kitti_det.md +++ b/docs/en/datasets/kitti_det.md @@ -6,7 +6,7 @@ This page provides specific tutorials about the usage of MMDetection3D for KITTI ## Prepare dataset -You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. Besides, the road planes could be downloaded from [HERE](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing), which are optional for data augmentation during training for better performance. +You can download KITTI 3D detection data [HERE](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip all zip files. Besides, the road planes could be downloaded from [HERE](https://download.openmmlab.com/mmdetection3d/data/train_planes.zip), which are optional for data augmentation during training for better performance. The road planes are generated by [AVOD](https://github.com/kujason/avod), you can see more details [HERE](https://github.com/kujason/avod/issues/19). Like the general way to prepare dataset, it is recommended to symlink the dataset root to `$MMDETECTION3D/data`. diff --git a/docs/zh_cn/datasets/kitti_det.md b/docs/zh_cn/datasets/kitti_det.md index 048c95eaa6..85253bf8e9 100644 --- a/docs/zh_cn/datasets/kitti_det.md +++ b/docs/zh_cn/datasets/kitti_det.md @@ -6,7 +6,7 @@ ## 数据准备 -您可以在[这里](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d)下载 KITTI 3D 检测数据并解压缩所有 zip 文件。此外,您可以在[这里](https://drive.google.com/file/d/1d5mq0RXRnvHPVeKx6Q612z0YRO1t2wAp/view?usp=sharing)下载道路平面信息,其在训练过程中作为一个可选项,用来提高模型的性能. +您可以在[这里](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d)下载 KITTI 3D 检测数据并解压缩所有 zip 文件。此外,您可以在[这里](https://download.openmmlab.com/mmdetection3d/data/train_planes.zip)下载道路平面信息,其在训练过程中作为一个可选项,用来提高模型的性能。道路平面信息由 [AVOD](https://github.com/kujason/avod) 生成,你可以在[这里](https://github.com/kujason/avod/issues/19)查看更多细节。 像准备数据集的一般方法一样,建议将数据集根目录链接到 `$MMDETECTION3D/data`。 diff --git a/setup.cfg b/setup.cfg index c1a2151bd2..e7bb89b9b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,4 +13,4 @@ no_lines_before = STDLIB,LOCALFOLDER default_section = THIRDPARTY [codespell] -ignore-words-list = ans,refridgerator,crate,hist,formating,dout,wan,nd,fo +ignore-words-list = ans,refridgerator,crate,hist,formating,dout,wan,nd,fo,avod,AVOD