CenterNet的Head部分会预测三个变量:
def forward_single(self, x: Tensor) -> Tuple[Tensor, ...]:
"""Forward feature of a single level.
Args:
x (Tensor): Feature of a single level.
Returns:
center_heatmap_pred (Tensor): center predict heatmaps, the
channels number is num_classes.
wh_pred (Tensor): wh predicts, the channels number is 2.
offset_pred (Tensor): offset predicts, the channels number is 2.
"""
center_heatmap_pred = self.heatmap_head(x).sigmoid()
wh_pred = self.wh_head(x)
offset_pred = self.offset_head(x)
return center_heatmap_pred, wh_pred, offset_pred
分别是中心点热力图center_heatmap_pred
,box宽高wh_pred
,与中心点偏移offset_pred
center_heatmap_pred
用来确定下图中的初始黄色点
wh_pred
用来预测下图中的红色宽高线段
offset_pred
用来预测下图中的(绿色)中心点偏移线段
直觉上也是先修正中心点,之后再根据box宽高确定box的位置,在代码中这样体现:
topk_xs = topk_xs + offset[..., 0]
topk_ys = topk_ys + offset[..., 1]
tl_x = (topk_xs - wh[..., 0] / 2) * (inp_w / width)
tl_y = (topk_ys - wh[..., 1] / 2) * (inp_h / height)
br_x = (topk_xs + wh[..., 0] / 2) * (inp_w / width)
br_y = (topk_ys + wh[..., 1] / 2) * (inp_h / height)
先重新修正变量topk_xs
,之后再计算box的边界
以上代码均摘自 mmdet
https://github.com/open-mmlab/mmdetection/blob/main/mmdet/models/dense_heads/centernet_head.py