mmdetection3D---(1)

mmdetection3d说明文档记录:

https://mmdetection3d.readthedocs.io/en/latest/getting_started.html

一、config文件

1、config文件结构

config文件可能会有继承base下的父类,所以可能只看configs下的文件是不太全,可以使用如下脚本打印完整的config文件.

python tools/misc/print_config.py /PATH/TO/CONFIG

在config目录下的网络的config文件会继承同文件夹下**_base_目录下的父类**,所有的config文件都在同一个目录下。官方建议是只使用一个基础父类,最大的继承层级不超过3层。config文件一般都有四个基本的模块组成:
dataset:数据集相关配置
model:模型结构配置
schedule:训练优化策略
default_runtime:训练迭代设置

2.config文件的命名

{model}_[model setting]_{backbone}_{neck}_[norm setting]_[misc]_[batch_per_gpu x gpu]_{schedule}_{dataset}
#############################################################################################################
[model setting]: specific setting for some model.

{backbone}: backbone type like regnet-400mf, regnet-1.6gf.

{neck}: neck type like fpn, secfpn.

[norm_setting]: bn (Batch Normalization) is used unless specified, other norm layer type could be gn (Group Normalization), sbn (Synchronized Batch Normalization). gn-head/gn-neck indicates GN is applied in head/neck only, while gn-all means GN is applied in the entire model, e.g. backbone, neck, head.

[misc]: miscellaneous setting/plugins of model, e.g. strong-aug means using stronger augmentation strategies for training.

[batch_per_gpu x gpu]: samples per GPU and GPUs, 4x8 is used by default.

{schedule}: training schedule, options are 1x, 2x, 20e, etc. 1x and 2x means 12 epochs and 24 epochs respectively. 20e is adopted in cascade models, which denotes 20 epochs. For 1x/2x, initial learning rate decays by a factor of 10 at the 8/16th and 11/22th epochs. For 20e, initial learning rate decays by a factor of 10 at the 16th and 19th epochs.

3.不同于mmdetection,train_cfg和test_cfg 在mmdetection3d中被放到了模型定义中。

# recommended
model = dict(
   type=...,
   ...
   train_cfg=dict(...),
   test_cfg=dict(...)
)

安装open3d
https://stackoverflow.com/questions/49911550/how-to-upgrade-disutils-package-pyyaml

4.针对_base_中的基础配置的修改替换

使用_delete_=True关键字

例如:_base_中定义网络的neck如下:

model = dict(
    type='MVXFasterRCNN',
    pts_voxel_layer=dict(...),
    pts_voxel_encoder=dict(...),
    pts_middle_encoder=dict(...),
    pts_backbone=dict(...),
    pts_neck=dict(
        type='FPN',
        norm_cfg=dict(type='naiveSyncBN2d', eps=1e-3, momentum=0.01),
        act_cfg=dict(type='ReLU'),
        in_channels=[64, 128, 256],
        out_channels=256,
        start_level=0,
        num_outs=3),
    pts_bbox_head=dict(...))

想替换成其他类型的neck,在子类config文件中继承_base_之后,做如下定义修改:

_base_ = '../_base_/models/hv_pointpillars_fpn_nus.py'
model = dict(
    pts_neck=dict(
        _delete_=True,
        type='SECONDFPN',
        norm_cfg=dict(type='naiveSyncBN2d', eps=1e-3, momentum=0.01),
        in_channels=[64, 128, 256],
        upsample_strides=[1, 2, 4],
        out_channels=[128, 128, 128]),
    pts_bbox_head=dict(...))

5.中间变量train_pipeline和test_pipeline

train_pioeline和test_pipeline是对数据进行处理的中间变量,在进行设置之后,需要将其传输到data中。

_base_ = './nus-3d.py'
train_pipeline = [
    dict(
        type='LoadPointsFromFile',
        load_dim=5,
        use_dim=5,
        file_client_args=file_client_args)
        ..........
]
test_pipeline = [
    dict(
        type='LoadPointsFromFile',
        load_dim=5,
        use_dim=5,
        file_client_args=file_client_args),
    ...................
]
data = dict(
    train=dict(pipeline=train_pipeline),
    val=dict(pipeline=test_pipeline),
    test=dict(pipeline=test_pipeline))

二、自定义相关

1.自定义数据集

2、自定义数据处理pipeline

数据处理中涉及dataset,dataloader,另外,为了存储不同大小的数据(例如图片,bbox),使用一个容器类datacontainer作为数据存储容器。
pipeline定义了数据处理的每一个步骤,每一个步骤都是以一个字典作为输入,然后输出一个字典供下一阶段使用。dataset和pipiline是分离的两部分,dataset主要是用来定义处理数据注释标签信息,pipeline定义将数据处理成字典形式的所有步骤。
下方是pipeline的处理模块流程,绿色代表add新内容,橙色代表更新的内容。
mmdetection3D---(1)_第1张图片总体的数据处理流程分成四个阶段:
数据加载
预处理
数据格式化
数据增强
可以自定义pipeline的处理步骤,然后用在pipeline中。

3.自定义模型

1.model的模块在mmdetection3d中被分成6个类型:
encoder:

 e.g., HardVFE and PointPillarsScatter.
 主要是在voxel-based方法中用来对特征进行编码的,包括voxel layer,voxel encoder和middle encoder三个小部分。

backbone:

e.g., ResNet, SECOND.
通常就是用于提取特征的卷积网络

neck:

e.g., FPN, SECONDFPN
一个自底向上的线路,一个自顶向下的线路,横向连接.融合低层次高分辨率信息和高层次深语义信息。

FPN出自detection任务;U-Net出自segmentation任务。 FPN的“放大”部分是直接插值放大的,没有deconvolution的filters学习参数;U-Net“放大”部分就是Decoder,需要deconvolution的filters学习参数的。FPN及其大多数改进都是把原Feature Map和FPN的Feature Map做加法;U-Net及其大多数改进都是把原Feature Map和Decoder的Feature Map做Concatiantion,再做1x1卷积。FPN对每一个融合的层都做detection;U-Net 只在最后一层做segmentation的pixel预测。 作者:饭饭 链接:https://www.zhihu.com/question/351279839/answer/1002339902

head:

 e.g., bbox prediction and mask prediction.

roi extractor:

e.g., H3DRoIHead and PartAggregationROIHead.
提取roi区域的特征图

loss:

e.g., FocalLoss, L1Loss, and GHMLoss.


2.各个模块都可以自定义,定义的步骤主要包括三个步骤
以定义名为second的backbone为例:
(1)创建自定义backbone类文件
mmdet3d/models/backbones/second.py

import torch.nn as nn

from ..builder import BACKBONES


@BACKBONES.register_module()
class SECOND(nn.Module):

    def __init__(self, arg1, arg2):
        pass

    def forward(self, x):  # should return a tuple
        pass

    def init_weights(self, pretrained=None):
        pass

(2)在init文件中导入
mmdet3d/models/backbones/init.py

from .second import SECOND

(3)在config中使用

model = dict(
    ...
    backbone=dict(
        type='SECOND',
        arg1=xxx,
        arg2=xxx),
    ...

详细链接

4.自定义训练时间策略、优化策略

参考

这里有一个有意思的pytorch模块:
hooks-------钩子
当你训练一个网络,想要提取中间层的参数、或者特征图的时候,使用hook就能派上用场了。
详细介绍

三、工具相关

1.绘制图像曲线:
损失曲线、评价mAP曲线
2.计算时间
3.可视化工具
可视化结果,可视化数据集
字典dic()
4.模型复杂度统计

字典创建:冒号隔开key:value,逗号隔开几对元素

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

print ("dict['Name']: ", dict['Name'])
print ("dict['Age']: ", dict['Age'] )

#以上实例输出结果:

#dict['Name']:  Zara
#dict['Age']:  7

报错输出:

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print ("dict['Alice']: ", dict['Alice'] )

# 以上实例输出结果:

#KeyError: 'Alice'
super().__init__()的作用也就显而易见了,就是执行父类的构造函数,使得我们能够调用父类的属性。

Try to use open3d==0.11

你可能感兴趣的:(深度学习框架应用,mmdetection3d)