当前位置:首页 > 编程笔记 > 正文
已解决

FCOS难点记录

来自网友在路上 179879提问 提问时间:2023-11-09 18:58:40阅读次数: 79

最佳答案 问答题库798位专家为你答疑解惑

在这里插入图片描述
FCOS 中有计算 特征图(Feature map中的每个特征点到gt_box的左、上、右、下的距离)

		x = coords[:, 0] # h*w,2   即 第一列y = coords[:, 1] l_off = x[None, :, None] - gt_boxes[..., 0][:, None, :]  # [1,h*w,1]-[batch_size,1,m]-->[batch_size,h*w,m]t_off = y[None, :, None] - gt_boxes[..., 1][:, None, :]r_off = gt_boxes[..., 2][:, None, :] - x[None, :, None]b_off = gt_boxes[..., 3][:, None, :] - y[None, :, None]ltrb_off = torch.stack([l_off, t_off, r_off, b_off], dim=-1)  # [batch_size,h*w,m,4]areas = (ltrb_off[..., 0] + ltrb_off[..., 2]) * (ltrb_off[..., 1] + ltrb_off[..., 3])  # [batch_size,h*w,m]off_min = torch.min(ltrb_off, dim=-1)[0]  # [batch_size,h*w,m]off_max = torch.max(ltrb_off, dim=-1)[0]  # [batch_size,h*w,m]

根据上边的画的图可以看出,假设对应的 feature map 大小为 2x2,stride=4,原始图片为8x8。将特征图中的每个特征点映射回去,可以得到相应的 4个(h*w个)坐标。对应图中的 红色a,绿色b,黄色c和蓝色d的点。

print(x,"\n",y,x.shape)
'''
tensor([2., 6., 2., 6.]) 
tensor([2., 2., 6., 6.]) torch.Size([4])
'''print(x[None,:,None]) # [1,4,1]
'''
tensor([[[2.],[6.],[2.],[6.]]]) 
'''print(gt_boxes) # [1,2,4]  batch=1, 两个框,每个框左上角和右下角坐标
'''
tensor([[[5, 4, 7, 6],[1, 1, 4, 6]]])
'''print(gt_boxes[...,0],gt_boxes[...,0][:,None,:])
''' 
tensor([[5, 1]]) tensor([[[5, 1]]])
'''
l_off = [2,2]-[5,1]=[-3,1]  以此类推print(l_off,"\n", l_off.shape)'''
**第一列代表,所有的点abcd横坐标与第一个框的左边偏移量。第二列代表到第二个框的偏移量**
tensor([[[-3.,  1.],[ 1.,  5.],[-3.,  1.],[ 1.,  5.]]]) torch.Size([1, 4, 2])'''print(ltrb_off)
'''
第一列代表,所有的投影点abcd,到两个框的左边偏移量。第一行第二行分别代表两个框。
tensor([[[[-3., -2.,  5.,  4.],[ 1.,  1.,  2.,  4.]],[[ 1., -2.,  1.,  4.],[ 5.,  1., -2.,  4.]],[[-3.,  2.,  5.,  0.],[ 1.,  5.,  2.,  0.]],[[ 1.,  2.,  1.,  0.],[ 5.,  5., -2.,  0.]]]]) torch.Size([1, 4, 2, 4]) #[batch_size,h*w,m,4]
'''print(ltrb_off[...,0])
'''tensor([[[-3.,  1.],[ 1.,  5.],[-3.,  1.],[ 1.,  5.]]]) torch.Size([1, 4, 2])
'''print(areas)
'''
areas: tensor([[[ 4., 15.],[ 4., 15.],[ 4., 15.],[ 4., 15.]]])
'''torch.return_types.min(
values=tensor([[[-3.,  1.],[-2., -2.],[-3.,  0.],[ 0., -2.]]]),
indices=tensor([[[0, 0],[1, 2],[0, 3],[3, 2]]])) torch.return_types.max(
values=tensor([[[5., 4.],[4., 5.],[5., 5.],[2., 5.]]]),
indices=tensor([[[2, 3],[3, 0],[2, 1],[1, 0]]]))
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"FCOS难点记录":http://eshow365.cn/6-36444-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!