Ultra-Fast-Lane-Detection-v2 icon indicating copy to clipboard operation
Ultra-Fast-Lane-Detection-v2 copied to clipboard

if valid_col[0, :, i].sum() >= num_cls_col / 4,这里为什么是除以4,而不是除以2啊

Open guodaoyi opened this issue 1 year ago • 1 comments

大佬麻烦问下,def pred2coords(pred, row_anchor, col_anchor, local_width=1, original_image_width=1640, original_image_height=590):

batch_size, num_grid_row, num_cls_row, num_lane_row = pred['loc_row'].shape

batch_size, num_grid_col, num_cls_col, num_lane_col = pred['loc_col'].shape
max_indices_row = pred['loc_row'].argmax(1).cpu()
# n , num_cls, num_lanes
valid_row = pred['exist_row'].argmax(1).cpu()
# n, num_cls, num_lanes

max_indices_col = pred['loc_col'].argmax(1).cpu()
# n , num_cls, num_lanes
valid_col = pred['exist_col'].argmax(1).cpu()
# n, num_cls, num_lanes

pred['loc_row'] = pred['loc_row'].cpu()
pred['loc_col'] = pred['loc_col'].cpu()

coords = []

row_lane_idx = [1, 2]
col_lane_idx = [0, 3]

for i in row_lane_idx:
    tmp = []
    if valid_row[0, :, i].sum() > num_cls_row / 2:
        for k in range(valid_row.shape[1]):
            if valid_row[0, k, i]:
                all_ind = torch.tensor(list(range(max(0, max_indices_row[0, k, i] - local_width),
                                                  min(num_grid_row - 1,
                                                      max_indices_row[0, k, i] + local_width) + 1)))

                out_tmp = (pred['loc_row'][0, all_ind, k, i].softmax(0) * all_ind.float()).sum() + 0.5
                out_tmp = out_tmp / (num_grid_row - 1) * original_image_width
                tmp.append((int(out_tmp), int(row_anchor[k] * original_image_height)))
        coords.append(tmp)
for i in col_lane_idx:
    tmp = []
    if valid_col[0, :, i].sum() > num_cls_col / 4:
        for k in range(valid_col.shape[1]):
            if valid_col[0, k, i]:
                all_ind = torch.tensor(list(range(max(0, max_indices_col[0, k, i] - local_width),
                                                  min(num_grid_col - 1,
                                                      max_indices_col[0, k, i] + local_width) + 1)))

                out_tmp = (pred['loc_col'][0, all_ind, k, i].softmax(0) * all_ind.float()).sum() + 0.5

                out_tmp = out_tmp / (num_grid_col - 1) * original_image_height
                tmp.append((int(col_anchor[k] * original_image_width), int(out_tmp)))
        coords.append(tmp)

return coords

guodaoyi avatar May 16 '23 11:05 guodaoyi

@guodaoyi 这个是一个超参,你可以自己调整。至于为什么row是2,col是4,是因为长度小于图像高度一半的,宽度1/4的车道线会被认为是过短的,会被滤除

cfzd avatar May 17 '23 10:05 cfzd