【MMDetection3D】基于单目(Monocular)的3D目标检测入门实战

这篇具有很好参考价值的文章主要介绍了【MMDetection3D】基于单目(Monocular)的3D目标检测入门实战。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

本文简要介绍单目(仅一个摄像头)3D目标检测算法,并使用MMDetection3D算法库,对KITTI(SMOKE算法)、nuScenes-Mini(FCOS3D、PGD算法)进行训练、测试以及可视化操作。
 

单目3D检测

概述

单目3D检测,顾名思义,就是只使用一个摄像头采集图像数据,并将图像作为输入送入模型进,为每一个感兴趣的目标预测 3D 框及类别标签。但可以想到,图像不能提供足够的三维信息(缺失深度信息),因此人们在前些年热衷于研究LIDAR-based的算法(如: PointNet、VoxelNet、PointPillars等等),大大提高3D物体检测的精度。

但是LIDAR-based的缺点在于成本较高,且易受天气环境的影响,而Camera-based算法能够提高检测系统的鲁棒性,尤其是当其他更昂贵的模块失效时。因此,如何基于单/多摄像头数据实现可靠/精确的3D检测显得尤为重要。为了解决Camera-based中物体定位问题,人们做了很多努力,例如从图像中推断深度、利用几何约束和形状先验等。然而,这个问题远未解决。由于3D定位能力差,Camera-based算法检测方法的性能仍然比LIDAR-based方法差得多。
 

检测算法

下面这张图出自这篇论文:3D Object Detection for Autonomous Driving: A Review and New Outlooks,论文非常详细地列出了在2015年至2022年上半年之间,基于单目的3D目标检测研究工作,并且细分了Image-only Monocular 3D Object DetectorDepth-assisted Monocular 3D Object DetectorPrior-guided Monocular 3D Object DetectorStereo-based 3D Object DetectorMulti-camera 3D Object Detector五个小方向,个人认为还是比较全面和客观的

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
具体的论文可参照:Learning-Deep-Learning

另外还可以关注nuScenes官网中Detection模块的榜单,选择Camera模式,就可以看到实时更新的SOTA算法啦~

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
 

nuScenes-Mini数据集

官网:https://www.nuscenes.org/
所属公司:Motional(前身为 nuTonomy)
更多信息:https://www.nuscenes.org/nuscenes

简介

nuScenes 数据集(发音为 /nuːsiːnz/)是由 Motional(前身为 nuTonomy)团队开发的带有 3d 对象注释的大规模自动驾驶数据集,它的特点:

  • Full sensor suite (1x LIDAR, 5x RADAR, 6x camera, IMU, GPS)
  • 1000 scenes of 20s each
  • 1,400,000 camera images
  • 390,000 lidar sweeps
  • Two diverse cities: Boston and Singapor
  • Left versus right hand traffic
  • Detailed map information
  • 1.4M 3D bounding boxes manually annotated for 23 object classes
  • Attributes such as visibility, activity and pose
  • New: 1.1B lidar points manually annotated for 32 classes
  • New: Explore nuScenes on Strada
  • Free to use for non-commercial use

下载

完整的nuScenes数据集要500+G(要了命了),为了方便操作,节约时间,便于入门学习(理由可真多hhh),后续实战我们选择nuScenes-Mini数据集,官方是这么说的:

Full dataset (v1.0)
In March 2019 we released the full nuScenes dataset with 1000 scenes. Due to the huge size of the dataset, we provide the mini, trainval and test splits separately. Mini (10 scenes) is a subset of trainval used to explore the data without having to download the entire dataset. Trainval (700+150 scenes) is packaged into 10 different archives that each contain 85 scenes. Test (150 scenes) is used for challenges and does not come with object annotations. Alternatively, it is also possible to download only selected modalities (camera, lidar, radar) or only keyframes. The meta data is provided separately and includes the annotations, ego vehicle poses, calibration, maps and log information.

下载方法一:手动下载并解压(不推荐)

首先在官网注册账号,然后进入nuScenes-Downloads页面,滑到最下面,就可以看到Full dataset (v1.0)以及Mini数据集的下载地址啦~

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
下载方法二:命令行无脑下载(推荐)

nuScenes官网上有详细的使用教程:Tutorial,为了后续实战方便,这里选择下载到mmdetection3d/data/nuscenes-mini/目录下:

# Make the directory to store the nuScenes dataset in.
!mkdir -p data/nuscenes-mini
cd data/nuscenes-mini
# Download the nuScenes mini split.
!wget https://www.nuscenes.org/data/v1.0-mini.tgz  
# Uncompress the nuScenes mini split.
!tar -xf v1.0-mini.tgz -C data/nuscenes-mini
# Install nuScenes.
!pip install nuscenes-devkit &> /dev/null  

安装完成后,数据集结构如下:

mmdetection3d
├── mmdet3d
├── tools
├── configs
├── data
│   ├── nuscenes-mini
│   │   ├── maps
│   │   ├── samples
│   │   ├── sweep
|   |   ├── v1.0-mini 

 

MMDetection3D

版本:Release V1.1.0rc0
安装配置、环境搭建:【MMDetection3D】环境搭建,使用PointPillers训练&测试&可视化KITTI数据集

下面,我们在MMDet3D库中进行如下实验:

单目算法 KITTI nuScenes-Mini
PGD
SMOKE
FCOS3D

即:使用PGD算法和SMOKE算法对KITTI进行训练、测试和可视化,使用PGD和FCOS3D算法对nuScenes-Mini进行训练、测试和可视化。

 

数据集准备

KITTI

3D 目标检测 KITTI 数据集

nuScenes-Mini

3D 目标检测 NUSCENES 数据集

 

配置文件

1、首先,要修改数据集路径

以nuScenes-Mini数据集为例,在/mmdetection3d/configs/_base_/datasets/文件夹中新建nus-mini-mono3d.py文件,即用于单目检测的nuScenes-Mini数据配置文件,将同文件夹下的nus-mono3d.py文件中的内容复制到新建文件中,并修改data_root参数:

dataset_type = 'NuScenesMonoDataset'
# 修改为你的数据集路径
data_root = 'your_dataset_root'
class_names = [
    'car', 'truck', 'trailer', 'bus', 'construction_vehicle', 'bicycle',
    'motorcycle', 'pedestrian', 'traffic_cone', 'barrier'
]
# Input modality for nuScenes dataset, this is consistent with the submission
# format which requires the information in input_modality.
input_modality = dict(
    use_lidar=False,
    use_camera=True,
    use_radar=False,
    use_map=False,
    use_external=False)
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFileMono3D'),
    dict(
        type='LoadAnnotations3D',
        with_bbox=True,
        with_label=True,
        with_attr_label=True,
        with_bbox_3d=True,
        with_label_3d=True,
        with_bbox_depth=True),
    dict(type='Resize', img_scale=(1600, 900), keep_ratio=True),
    dict(type='RandomFlip3D', flip_ratio_bev_horizontal=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle3D', class_names=class_names),
    dict(
        type='Collect3D',
        keys=[
            'img', 'gt_bboxes', 'gt_labels', 'attr_labels', 'gt_bboxes_3d',
            'gt_labels_3d', 'centers2d', 'depths'
        ]),
]
test_pipeline = [
    dict(type='LoadImageFromFileMono3D'),
    dict(
        type='MultiScaleFlipAug',
        scale_factor=1.0,
        flip=False,
        transforms=[
            dict(type='RandomFlip3D'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(
                type='DefaultFormatBundle3D',
                class_names=class_names,
                with_label=False),
            dict(type='Collect3D', keys=['img']),
        ])
]
# construct a pipeline for data and gt loading in show function
# please keep its loading function consistent with test_pipeline (e.g. client)
eval_pipeline = [
    dict(type='LoadImageFromFileMono3D'),
    dict(
        type='DefaultFormatBundle3D',
        class_names=class_names,
        with_label=False),
    dict(type='Collect3D', keys=['img'])
]

data = dict(
    samples_per_gpu=2,
    workers_per_gpu=2,
    train=dict(
        type=dataset_type,
        data_root=data_root,
        ann_file=data_root + 'nuscenes_infos_train_mono3d.coco.json',
        img_prefix=data_root,
        classes=class_names,
        pipeline=train_pipeline,
        modality=input_modality,
        test_mode=False,
        box_type_3d='Camera'),
    val=dict(
        type=dataset_type,
        data_root=data_root,
        ann_file=data_root + 'nuscenes_infos_val_mono3d.coco.json',
        img_prefix=data_root,
        classes=class_names,
        pipeline=test_pipeline,
        modality=input_modality,
        test_mode=True,
        box_type_3d='Camera'),
    test=dict(
        type=dataset_type,
        data_root=data_root,
        ann_file=data_root + 'nuscenes_infos_val_mono3d.coco.json',
        img_prefix=data_root,
        classes=class_names,
        pipeline=test_pipeline,
        modality=input_modality,
        test_mode=True,
        box_type_3d='Camera'))
evaluation = dict(interval=2)

2、修改模型配置文件(以PGD为例)

打开/mmdetection3d/configs/pgd/文件夹下,新建/pgd_r101_caffe_fpn_gn-head_2x16_1x_nus-mini-mono3d.py文件,并将同文件夹下的/pgd_r101_caffe_fpn_gn-head_2x16_1x_nus-mono3d.py文件内容复制到新建文件中,并修改'../_base_/datasets/nus-mini-mono3d.py'参数:

_base_ = [
    '../_base_/datasets/nus-mini-mono3d.py', '../_base_/models/pgd.py',
    '../_base_/schedules/mmdet_schedule_1x.py', '../_base_/default_runtime.py'
]
# model settings
model = dict(
    backbone=dict(
        dcn=dict(type='DCNv2', deform_groups=1, fallback_on_stride=False),
        stage_with_dcn=(False, False, True, True)),
    bbox_head=dict(
        pred_bbox2d=True,
        group_reg_dims=(2, 1, 3, 1, 2,
                        4),  # offset, depth, size, rot, velo, bbox2d
        reg_branch=(
            (256, ),  # offset
            (256, ),  # depth
            (256, ),  # size
            (256, ),  # rot
            (),  # velo
            (256, )  # bbox2d
        ),
        loss_depth=dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0),
        bbox_coder=dict(
            type='PGDBBoxCoder',
            base_depths=((31.99, 21.12), (37.15, 24.63), (39.69, 23.97),
                         (40.91, 26.34), (34.16, 20.11), (22.35, 13.70),
                         (24.28, 16.05), (27.26, 15.50), (20.61, 13.68),
                         (22.74, 15.01)),
            base_dims=((4.62, 1.73, 1.96), (6.93, 2.83, 2.51),
                       (12.56, 3.89, 2.94), (11.22, 3.50, 2.95),
                       (6.68, 3.21, 2.85), (6.68, 3.21, 2.85),
                       (2.11, 1.46, 0.78), (0.73, 1.77, 0.67),
                       (0.41, 1.08, 0.41), (0.50, 0.99, 2.52)),
            code_size=9)),
    # set weight 1.0 for base 7 dims (offset, depth, size, rot)
    # 0.05 for 2-dim velocity and 0.2 for 4-dim 2D distance targets
    train_cfg=dict(code_weight=[
        1.0, 1.0, 0.2, 1.0, 1.0, 1.0, 1.0, 0.05, 0.05, 0.2, 0.2, 0.2, 0.2
    ]),
    test_cfg=dict(nms_pre=1000, nms_thr=0.8, score_thr=0.01, max_per_img=200))

class_names = [
    'car', 'truck', 'trailer', 'bus', 'construction_vehicle', 'bicycle',
    'motorcycle', 'pedestrian', 'traffic_cone', 'barrier'
]
img_norm_cfg = dict(
    mean=[103.530, 116.280, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False)
train_pipeline = [
    dict(type='LoadImageFromFileMono3D'),
    dict(
        type='LoadAnnotations3D',
        with_bbox=True,
        with_label=True,
        with_attr_label=True,
        with_bbox_3d=True,
        with_label_3d=True,
        with_bbox_depth=True),
    dict(type='Resize', img_scale=(1600, 900), keep_ratio=True),
    dict(type='RandomFlip3D', flip_ratio_bev_horizontal=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle3D', class_names=class_names),
    dict(
        type='Collect3D',
        keys=[
            'img', 'gt_bboxes', 'gt_labels', 'attr_labels', 'gt_bboxes_3d',
            'gt_labels_3d', 'centers2d', 'depths'
        ]),
]
test_pipeline = [
    dict(type='LoadImageFromFileMono3D'),
    dict(
        type='MultiScaleFlipAug',
        scale_factor=1.0,
        flip=False,
        transforms=[
            dict(type='RandomFlip3D'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(
                type='DefaultFormatBundle3D',
                class_names=class_names,
                with_label=False),
            dict(type='Collect3D', keys=['img']),
        ])
]
data = dict(
    samples_per_gpu=2,
    workers_per_gpu=2,
    train=dict(pipeline=train_pipeline),
    val=dict(pipeline=test_pipeline),
    test=dict(pipeline=test_pipeline))
# optimizer
optimizer = dict(
    lr=0.004, paramwise_cfg=dict(bias_lr_mult=2., bias_decay_mult=0.))
optimizer_config = dict(
    _delete_=True, grad_clip=dict(max_norm=35, norm_type=2))
# learning policy
lr_config = dict(
    policy='step',
    warmup='linear',
    warmup_iters=500,
    warmup_ratio=1.0 / 3,
    step=[8, 11])
total_epochs = 12
evaluation = dict(interval=4)
runner = dict(max_epochs=total_epochs)

3、修改训练Epoch数、保存权重间隔等等(可选)

  • 在每个模型的配置文件中,如果是EpochBasedRunnerrunner,可以直接修改max_epochs参数改变训练的epoch数
  • /mmdetection3d/configs/_base_/default_runtime.py文件中,修改第一行代码的interval参数,即可改变保存权重间隔

 

多卡训练

这里以使用PGD模型训练nuScenes-Mini数据集为例,在Terminal中执行如下命令,训练文件默认保存至/mmdetection3d/work_dirs/pgd/pgd_r101_caffe_fpn_gn-head_2x16_1x_nus-mini-mono3d文件夹中:

CUDA_VISIBLE_DEVICES=0,1,2,3 tools/dist_train.sh configs/pgd/pgd_r101_caffe_fpn_gn-head_2x16_1x_nus-mini-mono3d.py 4

 

测试及可视化

如果是在VScode中进行测试和可视化,需要先设置$DISPLAY参数:

首先在MobaXterm中输入:echo $DISPLAY,查看当前窗口DISPLAY环境变量的值

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ echo $DISPLAY
localhost:10.0

之后,在VScode的终端输设置DISPLAY环境变量的值为10.0,并查看:

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ export DISPLAY=:10.0
(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ echo $DISPLAY
:10.0

这里以PGD模型为例,在Terminal中执行如下命令,测试文件默认保存至/mmdetection3d/outputs/pgd_nus_mini文件夹中:

python tools/test.py configs/pgd/pgd_r101_caffe_fpn_gn-head_2x16_2x_nus-mini-mono3d_finetune.py work_dirs/pgd_r101_caffe_fpn_gn-head_2x16_2x_nus-mini-mono3d_finetune/latest.pth --show --show-dir ./outputs/pgd/pgd_nus_mini

可视化结果如下:

KITTI

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能PGD
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能SMOKE

nuScenes-Mini

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能 FCOS3D
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能 PGD

可以看到检测出的多余框非常多,应该是NMS阈值和score阈值设置问题,下面我们修改阈值,以PGD-nuScenes为例,修改configs/pgd/pgd_r101_caffe_fpn_gn-head_2x16_2x_nus-mini-mono3d_finetune.py文件中的测试参数:

    test_cfg=dict(nms_pre=1000, nms_thr=0.2, score_thr=0.1, max_per_img=200))

分别将NMS参数和score参数设置为:nms_thr=0.2, score_thr=0.1

再次进行测试并可视化:

mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
mmdetection3d,3D目标检测,计算机视觉,3D目标检测,人工智能
可以看到效果明显好多了

 

参考资料

3D Object Detection for Autonomous Driving: A Review and New Outlooks

nuScenes 数据集

MMDetection3D说明文档:基于视觉的 3D 检测

Questions about FCOS3D and PGD model 3D box文章来源地址https://www.toymoban.com/news/detail-779295.html

到了这里,关于【MMDetection3D】基于单目(Monocular)的3D目标检测入门实战的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • mmdetection3d nuScenes (持续更新)

    本文为博主原创文章,未经博主允许不得转载。 本文为专栏《python三维点云从基础到深度学习》系列文章,地址为“https://blog.csdn.net/suiyingy/article/details/124017716”。         Mmdetection3d集成了大量3D深度学习算法,其中很大一部分可以在智能驾驶nuScenes数据集上运行。在算法

    2023年04月15日
    浏览(30)
  • win10 mmdetection3d环境搭建

    官网:mmdetection3d/README_zh-CN.md at master · open-mmlab/mmdetection3d · GitHub 安装过程参照:win10 mmdetection3d 训练KITTI_树和猫的博客-CSDN博客_pointnet训练kitti 官网安装过程 3D目标检测框架综述-知乎中描述了当前3D目标检测的数据和模型状况,为了能将数据和评价标准等统一,介绍了4个比

    2023年04月18日
    浏览(27)
  • 【MMDetection3D】MVXNet踩坑笔记

    原文 代码 MVXNet(CVPR2019) 最近许多关于3D target detection的工作都集中在设计能够使用点云数据的神经网络架构上。虽然这些方法表现出令人鼓舞的性能,但它们通常基于单一模态,无法利用其他模态(如摄像头和激光雷达)的信息。尽管一些方法融合了来自不同模式的数据,这些方

    2024年01月18日
    浏览(33)
  • 新版mmdetection3d将3D bbox绘制到图像

    使用 python mmdet3d/utils/collect_env.py 收集环境信息 以前写过mmdetection3d中的可视化,但mmdetection3d更新后代码已经不适用了,正好我把我的工作全转移到新版mmdetection3d上来了,因此重新写了一下推理结果可视化。整体思路还是构建模型、构建数据、推理、绘制,下面分步讲解 我用

    2024年04月15日
    浏览(30)
  • mmdetection3d系列--(1)安装步骤(无坑版)

      最近在看一些基于点云3d目标检测的文章,需要复现甚至修改一些算法,就找到了mmlab开源的mmdetection3d目标检测框架,方便后续学习。     在安装的时候遇到一点坑,比如环境问题,安装完能跑demo但是不能跑训练测试问题等。在解决问题后还是完成了安装。在这里记录一

    2024年02月02日
    浏览(30)
  • MMDetection3D库中的一些模块介绍

    本文目前仅包含2个体素编码器、2个中间编码器、1个主干网络、1个颈部网络和1个检测头。如果有机会,会继续补充更多模型。 若发现内容有误,欢迎指出。   MMDetection3D的点云数据一般会经历如下步骤/模块:   下面分别介绍每个部分的一些典型模型。   在介绍体素

    2023年04月17日
    浏览(34)
  • MMdetection3D学习系列(一)——环境配置安装

    MMdetion3D是是mmlab在3d目标检测方面提供的相关检测模型,可以实现点云、图像或者多模态数据上的3D目标检测以及点云语义分割。 GitHub地址:https://github.com/open-mmlab/mmdetection3d/ 目前mmdetection3d 支持21种不同的算法,100多个预训练模型,7个数据集: mmdetection3D安装比较简单,之前

    2024年02月01日
    浏览(35)
  • 3D目标检测框架 MMDetection3D环境搭建 docker篇

    本文介绍如何搭建3D目标检测框架,使用docker快速搭建MMDetection3D的开发环境,实现视觉3D目标检测、点云3D目标检测、多模态3D目标检测等等。 需要大家提前安装好docker,并且docker版本= 19.03。 1、下载MMDetection3D源码 https://github.com/open-mmlab/mmdetection3d  git clone https://github.com/ope

    2024年02月08日
    浏览(32)
  • mmdetection3d可视化多模态模型推理结果

    参考文献: 带你玩转 3D 检测和分割 (三):有趣的可视化 - 知乎 (zhihu.com) Welcome to MMDetection3D’s documentation! — MMDetection3D 1.0.0rc4 文档 让我们看一下ChatGPT的回答[手动狗头]: mmdetection3D是基于PyTorch框架的3D目标检测工具包,它是mmdetection的3D扩展版本。它提供了一个灵活且高效的

    2024年02月16日
    浏览(31)
  • 零基础熟悉mmdetection3d数据提取、模型搭建过程

    本图文从介绍配置文件开始,逐步构建一个新的配置文件,并依次构建相关模型,最终使用一条点云数据简单走了一下处理流程 关于mmdetection3d的安装,参考官方文档安装 — MMDetection3D 1.0.0rc4 文档 1.1 mmdetection3d配置文件的组成 官方文档:教程 1: 学习配置文件 — MMDetection3D 1.

    2024年02月05日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包