- 获取特征图
ipm_pred_segment, emb, offset_y, z = prediction[0] # BEV
ipm_gt_seg = torch.clone(ipm_pred_segment)
- sigmoid激活,将数组归一化到0~1之间,选0.5作为阈值,区分前景(车道线)和背景
ipm_gt_seg = torch.sigmoid(ipm_gt_seg)
ipm_gt_seg = (ipm_gt_seg > 0.5)
- tesnor格式转numpy array格式
array1 = ipm_gt_seg.squeeze(0).cpu().detach().numpy()
- array转opencv mat格式
# de-normalize,将图像数据扩展到[0,255]
maxValue = array1.max()
array1 = array1 * 255 / maxValue
# float32-->uint8
mat = np.uint8(array1)
mat = mat.transpose(1, 2, 0)
cv2.imshow("ipm", mat)
cv2.waitKey(1)