初步使用mmdetection3d进行点云目标检测

   MMDetection3D 是一个基于 PyTorch 的3D目标检测开源工具箱,涵盖了3D目标检测、单目3D目标检测、多模态3D目标检测、3D语义分割等三维深度学习任务。
MMDetection3D包含的目标检测算法

MMDetection3D中的3D目标检测模型

环境搭建

创建Anaconda虚拟环境

conda create -n mmdet3d python=3.7

进入虚拟环境

安装对应版本的cuda、pytorch、torchvision

安装mmcv-full、MMDection、MMSegmentation

pip install mmcv-full
pip install mmdet
pip install MMSegmentation

克隆MMDection3D代码仓库

git clone https://github.com/open-mmlab/mmdetection3d.git

跳转至代码目录后 安装依赖包

pip install -e .

手动安装无法自动找到的依赖和冲突的依赖

项目结构

在这里插入图片描述
重要文件:

  • configs: 各种模型、数据集的配置参数文件
  • tests: 各个模块组件的单元测试代码
  • data:存放数据集的目录,包括原始数据及预处理后的数据文件
  • mmdet3d: 核心代码
      apis: 一般是 train.py , test.py 等,在最外层的脚本里调用到这里面的文件
      core: 核心代码,常被其他模块调用。
      datasets: 各数据集的定义
      models: 模型相关代码
      utils: 辅助工具
  • tools: 常用脚本
      analysis_tools: 分析工具,包括可视化,计算flops等
      data_converter: 各数据集的预处理转换脚本
      create_data.py: 数据预处理入口
      train.py: 训练脚本
      test.py: 测试脚本

demo测试

单模态

使用预训练好的VoteNet模型进行3D单模态目标检测

python demo/pcd_demo.py demo/data/sunrgbd/000017.bin configs/votenet/votenet_8xb16_gbd-3d.py checkpoints/votenet_16x8_sunrgbd-3d-10class_20210820_162823-bf11f014.pth

测试图片:
在这里插入图片描述
测试结果:
在这里插入图片描述
在这里插入图片描述

多模态

使用预训练好的ImVoteNet模型进行3D多模态目标检测

python demo/multi_modality_demo.py demo/data/sunrgbd/000017.bin demo/data/sunrgbd/000017.jpg demo/data/sunrgbd/sunrgbd_000017_infos.pkl configs/imvotenet/imvotenet_stage2_8xb16_sunrgbd-3d.py checkpoints/imvotenet_stage2_16x8_sunrgbd-3d-10class_20210819_192851-1bcd1b97.pth

在这里插入图片描述

在这里插入图片描述

数据集准备

数据集下载

使用 KITTI 3D 目标检测数据集进行实验
数据集可以直接在官网下载
在这里插入图片描述
图片、激光点云、标注真值、标定参数通过图片序号一一对应
在这里插入图片描述
将下载好的数据集按照如下目录结构导入

mmdetection3d
├── mmdet3d
├── tools
├── configs
├── data
│   ├── kitti
│   │   ├── testing
│   │   │   ├── calib
│   │   │   ├── image_2
│   │   │   ├── velodyne
│   │   ├── training
│   │   │   ├── calib
│   │   │   ├── image_2
│   │   │   ├── label_2
│   │   │   ├── velodyne
│   │   │   ├── planes (optional)

加载点云数据

创建 KITTI 点云数据,首先需要加载原始的点云数据并生成相关的包含目标标签和标注框的数据标注文件,同时还需要为 KITTI 数据集生成每个单独的训练目标的点云数据,并将其存储在 data/kitti/kitti_gt_database 的 .bin 格式的文件中,此外,需要为训练数据或者验证数据生成 .pkl 格式的包含数据信息的文件

按照如下命令创建最终的KITTI数据集:

# 进入mmdetection3d主目录
cd mmdetection3d
# 创建文件夹
mkdir ./data/kitti/ && mkdir ./data/kitti/ImageSets
# Download data split
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/test.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/test.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/train.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/train.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/val.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/val.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/trainval.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/trainval.txt
# 使用create_data.py进行数据预处理
python tools/create_data.py kitti --root-path ./data/kitti --out-dir ./data/kitti --extra-tag kitti --with-plane

请添加图片描述

最终数据目录结构如下所示

kitti
├── ImageSets
│   ├── test.txt
│   ├── train.txt
│   ├── trainval.txt
│   ├── val.txt
├── testing
│   ├── calib
│   ├── image_2
│   ├── velodyne
│   ├── velodyne_reduced
├── training
│   ├── calib
│   ├── image_2
│   ├── label_2
│   ├── velodyne
│   ├── velodyne_reduced
│   ├── planes (optional)
├── kitti_gt_database
│   ├── xxxxx.bin
├── kitti_infos_train.pkl
├── kitti_infos_val.pkl
├── kitti_dbinfos_train.pkl
├── kitti_infos_test.pkl
├── kitti_infos_trainval.pkl

训练

数据集和环境都配置好后,就可以开始训练,使用命令python tools/train.py -h可以查看有哪些训练参数:
在这里插入图片描述
关键参数:

  • configs:必选,训练模型的参数配置文件
  • work-dir:可选,训练日志及权重文件保存文件夹,默认会新建work-dirs文件夹,并保存在以configs文件名命名的文件夹中
  • gpu-id:可选,使用的GPU个数

修改训练参数

/mmdetection3d/configs/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py文件中,可以修改epoch轮数,学习率等参数
在这里插入图片描述

开始训练

使用以下命令开始训练:
python tools/train.py configs/pointpillars/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py
在这里插入图片描述
在这里插入图片描述
训练结果会保存在/mmdetection3d/work-dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class文件夹中,包括日志文件(.log)、权重文件(.pth)以及模型配置文件(.py)等
请添加图片描述

可能遇到的问题

  • torch.cuda.OutOfMemoryError: CUDA out of memory
    减小batch的大小

  • RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
    可能是pytorch cuda cudnn之间版本匹配问题
    引入如下语句,不使用cudnn加速 看问题是否排除

import torch
torch.backends.cudnn.enabled = False

  还有可能是内存不足等问题

  • OSError: [WinError 1455]
    页面文件太小,无法完成操作,增加页面大小
    在这里插入图片描述

测试

使用命令python tools/test.py -h可以查看有哪些测试参数
在这里插入图片描述
关键参数:

  • config:必选,模型配置文件
  • checkpoint:必选,训练生成的权重文件
  • show:可选,是否对测试结果进行可视化

开始测试

python tools/test.py configs/pointpillars/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py work_dirs/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class/epoch_3.pth
在这里插入图片描述

测试结果

在这里插入图片描述

参考资料

【MMDetection3D】环境搭建,使用PointPillers训练&测试&可视化KITTI数据集

KITTI 3D目标检测数据集解析(完整版)

MMdetection3d环境搭建、使用MMdetection3d做3D目标检测训练自己的数据集、测试、可视化,以及常见的错误

MMdetection3d 安装与 Demo

MMdetection3d 训练与测试

  • 29
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值