深度学习中角度估计

1.3D Bounding Box Estimation Using Deep Learning and Geometry(CVPR 2017)

We show that a novel MultiBin discretecontinuous formulation of the orientation regression significantly outperforms a more traditional L2 loss
(1)L2 loss在很多回归问题中并不好用,它预测结果倾向平均值: L2 loss is not a good fit for many complex multi-modal regression problems,The L2 loss encourages the network to minimize to average loss across all modes, which results in an estimate that may
be poor for any single mode. This has been observed in the context of the image colorization problem, where the L2 norm produces unrealistic average colors for items like clothing [27].
(2)所以,有些值不能直接用L2 loss回归: Faster R-CNN [18] and SSD [11] do not regress the bounding boxes directly: instead they divide the space of the bounding boxes into several discrete modes called anchor boxes and then estimate the continuous offsets that need to be applied to each anchor box。预测相对于anchor的log偏差。
对于深度预测,我们也可以类别ssd中,预测落在每个类别的概率和相对于中心深度的偏移占该类别长度的百分比
(3)我们预测角度的做法:MultiBin
将角度离散化为n个有重叠的部分,即n类;对每一类,预测当前角度落在该类别的概率c和相对于类别中心的残差角的正弦余弦值。
使用单独一个分支,预测概率;使用另一个分支,预测两个值,然后两个值做L2 Norm(因为sin^2+ cos^2=1)
bins的个数:
如果只使用一个bins,相当于直接做L2 loss;
在KITTI数据上,自动驾驶中方向车辆的范围是很小的,所以bins=2时效果最好
Pascal3D+中,bins=8时的效果最好
这样做的好处:类比目标检测中使用anchor框,分类预测为每个anchor框的置信度,回归每个框相对于anchor的偏移;如果直接回归角度,回归的范围大,不好回归,所以分类+回归,先划分到一个类别,然后在该类别中回归;bins之间有overlap的好处,相当于增加了每个类别的样本量.

在这里插入图片描述
(4)对于目标大小预测,由于每个类别的目标大小分布是单峰和低方差的(比如汽车类,自行车类,他们的大小的方差可能都只是几厘米),所以可以直接使用L2 loss预测相对于对应类别均值的偏差。
在这里插入图片描述
代码路劲:https://github.com/fuenwang/3D-BoundingBox

将gt的角度转为标签:
#首先根据划分的bins,构造每个bins的中心的角度
        centerAngle = np.zeros(bins)
        interval = 2 * np.pi / bins #计算各个bins之间的间隔为interval
        for i in range(1, bins):
            centerAngle[i] = i * interval
        self.centerAngle = centerAngle
#然后,遍历每个bins,依次计算gt角度和bins中心的角度的偏差
for i in range(self.bins):
 	diff = abs(centerAngle[i] - LocalAngle)
 	#因为我们计算角度的绝对误差,不会超过180度;我们根据gt角度和bins中心角度的偏差值来设置confidence_multi,如果角度偏差在intervalAngle / 2 + self.overlap内,则对应bins的confluence设为1
	if diff > np.pi:
		diff = 2 * np.pi - diff
	if diff <= intervalAngle / 2 + self.overlap:
         confidence_multi[i] = 1
    if diff < intervalAngle / 2:
         confidence[i] = 1
angleDiff[one, :] = data['LocalAngle'] - self.centerAngle

计算损失时:损失包括分类损失和回归损失(只对gt中confluence中为1的类别计算回归损失)
分类损失:交叉熵损失
回归损失:
def OrientationLoss(orient, angleDiff, confGT):#分布代表预测的角度偏差的cos和sin,实际的角度偏差值,实际的confulence
    [batch, _, bins] = orient.size()
    cos_diff = torch.cos(angleDiff)
    sin_diff = torch.sin(angleDiff)
    cos_ori = orient[:, :, 0]
    sin_ori = orient[:, :, 1]
    mask1 = (confGT != 0)
    mask2 = (confGT == 0)
    count = torch.sum(mask1, dim=1)
    tmp = cos_diff * cos_ori + sin_diff * sin_ori
    tmp[mask2] = 0
    total = torch.sum(tmp, dim = 1)
    count = count.type(torch.FloatTensor).cuda()
    total = total / count
    return -torch.sum(total) / batch

角度预测的网络:
首先,用self.features特征提取网络.获得特征的shape为[B,512,7,7]
x = self.features(x)
x = x.view(-1, 512 * 7 * 7)
orientation = self.orientation(x) #self.orientation用全连接层,将通道数从512*7*7变为256,再变为bins*2
对预测结果做L2 norm:
orientation = orientation.view(-1, self.bins, 2)
orientation = F.normalize(orientation, dim=2)
对每个bins做类别预测
confidence = self.confidence(x)#self.orientation用全连接层,将通道数从512*7*7变为256,再变为bins

根据cos的曲线,
在这里插入图片描述
此处的损失为-cos(A-B),当控制A-B的值为[-pi,pi]时(即将label控制为[-pi,pi]),A-B为0时,误差最小;|A-B|增大时,误差也逐渐增大,为了防止损失为-1,可以加上1,变为1-cos(A-B)

2.估计建筑物的方向角 Learning Geocentric Object Pose in Oblique Monocular Images

估计sin,cos,使用MSE loss,如何实现的没有看明白
在这里插入图片描述
网络过程:首先通过编码器,获得特征,然后预测整张图的角度;
然后解码器获得和原图一样大的特征,估计建筑物高度(建筑物高度是建筑的内在属性,不随旋转,角度等变化,学习建筑物的高度需要去学习更多的更有意义的更正确的上下文的特征);然后将建筑物的高度与特征图做concat后,去估计在建筑物offset的长度,然后长度*角度得到flow.
角度的MSE loss:
(cosA-cosB)2+(sinA-sinB)2=1-(cosAcosB+sinAsinB)=-cos(A-B)+1,与上面一致
注意:直接预测cosB和sinB,需要使用F.nomalize对结果做归一化处理,这样才能保证为cosB2+sinB
2=1

网络估计角度的过程:

先用全局池化,然后接两个卷积层,先输出通道为2048,然后输出通道为2
    y = GlobalAveragePooling2D(name='pool1')(x)
    y = Dense(2048, name='fc1')(y)
    y = Dropout(0.5)(y)
    xydir = Dense(2, name='xydir', activation='linear')(y)

目标检测中的角度估计

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值