mmdetection3d学习笔记(一)——初识

感觉用mmdetection3d这个框架学习3D检测还不错,尝试研究一下结构和代码,在此记录一下。mmdetection3d的官方代码:GitHub - open-mmlab/mmdetection3d: OpenMMLab's next-generation platform for general 3D object detection.

配置环境

首先配置一下环境,因为之前电脑上已经安装了anaconda,因此直接创建虚拟环境然后激活

conda create -n mmdet3d python==3.8.3
activate mmdet3d

安装torch和cuda,这里torch版本使用的1.8.0,cuda使用11.1

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f 

 从github上把mmdetection3d代码下载下来,地址GitHub - open-mmlab/mmdetection3d: OpenMMLab's next-generation platform for general 3D object detection.或者直接使用git命令,当前版本==1.2.0

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

 进入mmdetection3d文件夹中,使用他们自己开发的mim工具进行编译,会安装相应的依赖,包括mmcv, mmdet, mmengine等

pip install -v -e . 这个命令中-e . 直接执行当前文件夹下的setup.py文件,内含执行命令,将安装依赖(requirements) 和将 命名空间软件(mmdet) 重新安装到包管理器中。-v 指输出更详细的信息

cd mmdetection3d
pip install openmim
mim install -v -e . 

整个代码库结构如下图

 数据预处理

  1. 以KITTI数据集为例,从KITTI官网上下载KITTI数据集,放置成mmdetection3d需要的格式;
  2. train_planes.zip下载道路平面信息放到training文件夹下,其在训练过程中作为一个可选项,用于提升模型性能;(训练时默认带这个,没有会报错)
  3. 参考下方代码,下载文件到ImageSets,使用数据处理脚本create_data.py处理数据。

转换后的数据主要变化:

  • mmdetection3d的转角定义和KITTI自定义不太一样(KITTI转角以相机坐标系为基准,而mmdetection3d以激光雷达坐标系为基准),因此需要做一下转换;
  • 生成一系列的pkl数据便于训练时使用。该文件包含数据集的各种信息,包括数据集路径、calib 信息和标注信息等等,从而做到各个数据集内部格式尽可能的统一。;
  • 将点云数据裁剪成仅包含前方视野的点云;
  • gt-database是将包含在训练数据集的每个 3D 边界框中的点云数据分别提取出来,得到的各个物体的点云文件,常用来在数据增强时使用(copy-paste)。
# 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


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

 前几行代码主要下载4个文件到ImageSets文件夹里,wget好像是Linux命令,windows下我直接打开链接手动另存了,最终效果见下图

demo推理

尝试使用预训练模型进行推理。 

新建一个checkpoints文件夹,从官网上下载一个权重文件

或者使用源码直接下载一个权重文件,这里使用kitti-3d-class权重文件

mim download mmdet3d --config pointpillars_hv_secfpn_8xb6-160e_kitti-3d-class --dest checkpoints

然后使用命令行进行推理验证(这里是用的jupyter lab来执行命名,方便查看效果)

遇到的问题:open3d安装包识别不了,降低了一下版本可以了

!python demo/pcd_demo.py \
    demo/data/kitti/000008.bin \
    configs/pointpillars/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py \
    checkpoints/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class_20220301_150306-37dc2420.pth \
    --show

启动训练

使用KITTI数据集进行训练,单卡使用tools/trains.py,多卡使用tools/dist_train.sh

python tools/train.py configs/pointpillars/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py

#使用configs下的配置文件
#可选参数例如[--resume-from 从断点处继续训练,--load-from 加载预训练权重finetune]

先暂时到这儿,接下来进入具体模块和代码。。。 

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值