在物体检测中,经过backbone之后等等卷积操作,在最后的feature map将要根据feature map的每一个点(yolov3好像叫cell,FCOS叫location)做出预测,预测的框的偏移值(FCOS是l,r,t,b)都需要根据feature map的坐标映射到原图的坐标。
1、首先需要根据feature map的大小生成,网格的坐标,下面是FCOS的代码。
def compute_location_per_level(self, height, width, stride, device):
shift_x = torch.arange(
0, width * stride, step=stride, dtype=torch.float32, device=device
)
shift_y = torch.arange(
0, height * stride, step=stride, dtype=torch.float32, device=device
)
shift_y, shift_x = torch.meshgrid(shift_y, shift_x)
shift_x = shift_x.reshape(-1)
shift_y = shift_y.reshape(-1)
location = torch.stack((shift_x, shift_y), 1) + stride // 2
return location
输出的location就是每一个cell都有一个坐标值,如height, width大小的map,有height*width个cell,
用numpy写:
import n