MMDetection3D 自定义数据集使用指南

MMDetection3D 自定义数据集使用指南

前言

在3D目标检测任务中,使用自定义数据集进行模型训练和评估是一个常见需求。本文将详细介绍如何在MMDetection3D框架中使用自定义数据集,包括数据准备、配置修改以及训练评估的全流程。

数据准备

点云数据格式

MMDetection3D目前仅支持.bin格式的点云数据。如果你的数据是其他格式,需要进行转换:

  1. PCD转BIN

    • 使用pypcd工具进行转换
    • 转换脚本示例:
      import numpy as np
      from pypcd import pypcd
      
      pcd_data = pypcd.PointCloud.from_path('input.pcd')
      points = np.zeros([pcd_data.width, 4], dtype=np.float32)
      points[:, 0] = pcd_data.pc_data['x'].copy()
      points[:, 1] = pcd_data.pc_data['y'].copy()
      points[:, 2] = pcd_data.pc_data['z'].copy()
      points[:, 3] = pcd_data.pc_data['intensity'].copy().astype(np.float32)
      with open('output.bin', 'wb') as f:
          f.write(points.tobytes())
      
  2. LAS转BIN

    • 通常需要先转换为PCD格式,再转为BIN格式

标注文件格式

标注文件应为.txt格式,每行表示一个3D边界框,格式如下:

x y z dx dy dz yaw 类别名称

其中:

  • (x,y,z):边界框中心坐标
  • (dx,dy,dz):边界框尺寸(长宽高)
  • yaw:绕Z轴的旋转角度(弧度)
  • 类别名称:目标类别标签

标定文件格式

标定文件应包含相机内参矩阵和激光雷达到各相机的变换矩阵:

P0  # 相机0内参矩阵
P1  # 相机1内参矩阵
...
lidar2cam0  # 激光雷达到相机0的变换矩阵
lidar2cam1  # 激光雷达到相机1的变换矩阵
...

数据组织结构

根据任务类型不同,数据组织结构也有所差异:

1. 基于激光雷达的3D检测

data/custom/
├── ImageSets/
│   ├── train.txt
│   ├── val.txt
├── points/
│   ├── 000000.bin
│   ├── 000001.bin
├── labels/
│   ├── 000000.txt
│   ├── 000001.txt

2. 基于视觉的3D检测

data/custom/
├── ImageSets/
│   ├── train.txt
│   ├── val.txt
├── calibs/
│   ├── 000000.txt
│   ├── 000001.txt
├── images/
│   ├── images_0/
│   │   ├── 000000.png
│   ├── images_1/
├── labels/
│   ├── 000000.txt

3. 多模态3D检测

data/custom/
├── ImageSets/
├── calibs/
├── points/
├── images/
│   ├── images_0/
│   ├── images_1/
├── labels/

4. 基于激光雷达的3D语义分割

data/custom/
├── ImageSets/
├── points/
├── semantic_mask/
│   ├── 000000.bin

数据转换工具

准备好原始数据后,使用以下命令生成训练/验证信息文件:

python tools/create_data.py custom --root-path ./data/custom --out-dir ./data/custom --extra-tag custom

自定义数据集类

mmdet3d/datasets/my_dataset.py中创建自定义数据集类:

@DATASETS.register_module()
class MyDataset(Det3DDataset):
    METAINFO = {
        'classes': ('Pedestrian', 'Cyclist', 'Car')  # 替换为你的类别
    }

    def parse_ann_info(self, info):
        """处理标注信息"""
        ann_info = super().parse_ann_info(info)
        if ann_info is None:
            ann_info = dict()
            ann_info['gt_bboxes_3d'] = np.zeros((0, 7), dtype=np.float32)
            ann_info['gt_labels_3d'] = np.zeros(0, dtype=np.int64)
        
        ann_info = self._remove_dontcare(ann_info)
        gt_bboxes_3d = LiDARInstance3DBoxes(ann_info['gt_bboxes_3d'])
        ann_info['gt_bboxes_3d'] = gt_bboxes_3d
        return ann_info

配置文件修改

1. 数据集配置

configs/_base_/datasets/custom.py中配置:

dataset_type = 'MyDataset'
data_root = 'data/custom/'
class_names = ['Pedestrian', 'Cyclist', 'Car']
point_cloud_range = [0, -40, -3, 70.4, 40, 1]  # 根据数据集调整
input_modality = dict(use_lidar=True, use_camera=False)
metainfo = dict(classes=class_names)

# 配置训练和测试pipeline
train_pipeline = [...]
test_pipeline = [...]

2. 模型配置

对于基于体素的检测器(如PointPillars),需要调整以下参数:

  • voxel_size:体素大小
  • point_cloud_range:点云范围
  • anchor_rangeanchor_size:根据数据集中目标的统计信息设置

3. 整体配置

将各部分配置组合:

_base_ = [
    '../_base_/models/pointpillars_hv_secfpn_custom.py',
    '../_base_/datasets/custom.py',
    '../_base_/schedules/cyclic-40e.py', 
    '../_base_/default_runtime.py'
]

数据可视化

在训练前,建议使用可视化工具检查数据:

python tools/misc/browse_dataset.py configs/pointpillars/pointpillars_hv_secfpn_8xb6_custom.py

评估配置

MMDetection3D目前仅支持KITTI风格的评估:

val_evaluator = dict(
    type='KittiMetric',
    ann_file=data_root + 'custom_infos_val.pkl',
    metric='bbox')

总结

本文详细介绍了在MMDetection3D中使用自定义数据集的完整流程,包括数据格式要求、组织结构、转换工具使用、数据集类实现以及配置文件修改等关键步骤。通过遵循这些指南,用户可以轻松地将自己的3D数据集应用于MMDetection3D框架中的各种3D检测和分割任务。

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惠淼铖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值