openPCdet 实现自定义点云数据集训练

openPCdet自定义数据集训练

*
openPCdet 代码框架
实现自定义数据集导入的流程
自定义数据集类的编写

openPCdet 代码框架

openPCdet是由香港中文大学MMLab实验室开源的轻量话激光雷达点云目标检测框架,它定义了一种统一的3D坐标系以及采用了数据与模型分离的高层代码设计思想,使用起来非常方便,具体介绍可以看下面的链接:
点云3D检测开源库
项目github地址

实现自定义数据集导入的流程

  1. 基于模板类dataset实现自定义数据集类的编写(可以仿照kitti编写)
  2. 编写自定义数据集类的配置文件(yaml)编写
  3. 编写网络配置文件
    实现了以上步骤之后,就可以开始训练了,下面附上我训练过程中的图片,这里采用的是pointpillar网络
    openPCdet 实现自定义点云数据集训练

; 自定义数据集类的编写

首先需要继承模板类dataset,下面是其中的基本方法 类结构:

openPCdet 实现自定义点云数据集训练
其中比较重要的就是getlidar(),getlabel()方法的实现,这两个方法实现了获取点云数据以及获取点云标签。然后需要注意在get_info()中需根据不同的数据集标注文件中3D坐标系的定义构建不同的坐标转换方式转换到统一的3D坐标系中。

我这里使用的的是万集发布的路侧激光雷达数据集,代码如下:

    def get_lidar(self, idx):
        """Loads point cloud for a sample
               Args:
                   index (int): Index of the point cloud file to get.

               Returns:
                   np.array(N, 4): point cloud.

"""

        lidar_file = self.root_split_path / 'velodyne' / ('%s.bin' % idx)

        assert lidar_file.exists()
        return np.fromfile(str(lidar_file), dtype=np.float32).reshape(-1, 4)

    def get_label(self, idx):

        label_file = self.root_split_path / 'label' / ('%s.txt' % idx)

        assert label_file.exists()

        objects = []
        with open(label_file, 'r') as f:
            for i in f.readlines():
                object1 = i.strip('\n').split(',')

                objects.append(object1)
        return objects

根据万集数据集标注文件,重写get_info()函数如下:

    def get_infos(self, num_workers=4, has_label=True, count_inside_pts=True, sample_id_list=None):
        import concurrent.futures as futures

        def process_single_scene(sample_idx):

            info = {}

            pc_info = {'num_features': 4, 'lidar_idx': sample_idx}

            info['point_cloud'] = pc_info
            if has_label:

                obj_list = self.get_label(sample_idx)

                annotations = {}

                annotations['type'] = np.array([int(obj[1]) for obj in obj_list])

                num_gt = len(annotations['type'])
                names = np.empty(num_gt, dtype="U30")
                j = 0
                for i in annotations['type']:
                    name = self.id_to_type(i)

                    names[j] = name

                    j = j + 1
                annotations['name'] = names.reshape(num_gt)

                annotations['x'] = np.array([float(obj[2]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['y'] = np.array([float(obj[3]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['z'] = np.array([float(obj[4]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['l'] = np.array([float(obj[7]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['w'] = np.array([float(obj[8]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['h'] = np.array([float(obj[9]) for obj in obj_list]).reshape(num_gt, 1)
                annotations['rotation_y'] = np.array([float(obj[6]) for obj in obj_list]).reshape(num_gt, 1)

                x = annotations['x'] / 100
                y = annotations['y'] / 100
                z = annotations['z'] / 100
                l = annotations['l'] / 100
                w = annotations['w'] / 100
                h = annotations['h'] / 100

                rots = annotations['rotation_y'] * (np.pi / 180)

                gt_boxes_lidar = np.concatenate([x, y, z, l, w, h, rots], axis=1)

                annotations['gt_boxes_lidar'] = gt_boxes_lidar

                info['annos'] = annotations

            return info

        sample_id_list = sample_id_list if sample_id_list is not None else self.sample_id_list

        with futures.ThreadPoolExecutor(num_workers) as executor:

            infos = executor.map(process_single_scene, sample_id_list)

        return list(infos)

大概比较重要的就是上面的三个方法的实现,由于我是仿照kitti实现的,所以也学习了kitti制作了pkl格式文件实现了数据的预加载,即在训练之前需要create_info,调用如下语句即可:

python -m pcdet.datasets.Dair.Dair_dataset create_Dair_infos tools/cfgs/dataset_configs/Dair_dataset.yaml

实现了数据的准备就可以开始训练了

Original: https://blog.csdn.net/qq_45297395/article/details/123478922
Author: Eric Jim
Title: openPCdet 实现自定义点云数据集训练

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/727482/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球