模型初始化
模型初始化是在centerfusion/src/main.py下42行左右,debug进入到creatmodel函数中
def create_model(arch, head, head_conv, opt=None):
'''
arch:用来指定要加载的backbone 代码用的是dla_34表示加载dla34这个主干模型
head: 检测网络头的相关参数:
相关具体说明可以看:https://blog.youkuaiyun.com/gui_hai/article/details/129120671
{'hm': 10, 表示预测的类别一共有10类所以通道数为10
'reg': 2, 表示hw计算出来的bbox中心点小数偏置,xy需要预测2个数据
'wh': 2, 预测的bbox的宽高
'dep': 1, 预测bbox的深度
'rot': 8, 旋转角度 8的含义待定(没有完全搞懂这)
'dim': 3, 预测3Dbbox的长宽高
'amodel_offset': 2, 保存根据实际中心点bbox中心点小数偏置
'dep_sec': 1,
'rot_sec': 8,
'nuscenes_att': 8, bbox的状态信息 比如:移动,静止等,作者在convert_Nunscenes.py中定义8类
'velocity': 3} 表示xyz方向的速度
'''
num_layers = int(arch[arch.find('_') + 1:]) if '_' in arch else 0
arch = arch[:arch.find('_')] if '_' in arch else arch
model_class = _network_factory[arch] #加载接下来要出事化的backbone类
model = model_class(num_layers, heads=head, head_convs=head_conv, opt=opt)#创建模型
return model
首先讲述的模型的初始化部分,所以涉及到的模型类只放了模型的__init__函数
定义model的时候,首先会进入到DLASeg类中,这个类继承了BaseModel类,所以在运行super函数的时候会调用BaseModel类,首先介绍一下BaseMode类,之后对DLASeg类进行介绍。
class BaseModel(nn.Module):
'''
这个类是在构建目标检测中的分类头
将head中需要分类和回归的数据定义一个头分支来进行预测
比如head中的hm这一属性会生成如下的模型:
Sequential(
(0): Conv2d(64, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): ReLU(inplace=True)
(2): Conv2d(256, 10, kernel_size=(1, 1), stride=(1, 1)))
'''
def __init__(self, heads, head_convs, num_stacks, last_channel, opt=None):
super(BaseModel, self).__init__()
self.opt = opt
if opt is not None and opt.head_kernel != 3:
print('Using head kernel:', opt.head_kernel)
head_kernel = opt.head_kernel
else:
head_kernel = 3
self.num_stacks = num_stacks
self.heads = heads
self.secondary_heads = opt.secondary_heads
last_channels = {
head: last_channel for head in heads}
for head in self.secondary_heads:
'''
论文中提到的第二个分类头
第二个分类头会将生成的雷达特征和图像特征concat在一起,
所以在定义卷积输入通道个数的时候应该是图像的通道数和雷达通道数之和
'''
last_channels[head] = last_channel+len(opt.pc_feat_lvl)
#下边这部分就是在生成每部分的卷积头
for head in self.heads:
classes = self.heads[head]
head_conv = head_convs[head]
if len(head_conv) > 0:
out = nn.Conv2d(head_conv[-1], classes,
kernel_size=1, stride=1, padding=0, bias=True
深度学习模型初始化:以DLASeg为例

该文详细介绍了模型初始化过程,特别是DLASeg类的构建,它基于BaseModel并利用DLA34作为backbone。BaseModel中定义了分类头的构建,而DLASeg类负责搭建backbone网络。模型的forward函数在ModelWithLoss类中执行,处理图像和雷达特征,进行两阶段预测。
最低0.47元/天 解锁文章
536

被折叠的 条评论
为什么被折叠?



