Bin-ze / BEVFormer_segmentation_detection

Implemented BEVFormer support for BEV segmentation
Apache License 2.0
98 stars 9 forks source link

关于BEV图中的box框颜色请教,是否可以根据不同的类别显示不一样的颜色的box框 #22

Closed MQC1111 closed 7 months ago

MQC1111 commented 7 months ago

您好,我想关于BEV图请教一下您:

1、关于在最终生成BEV图中如何给不一样的类别附上不一样的颜色box呢,例如,在BEV图上,给行人用蓝色box表示,给car用红色的box表示,给bus用绿色的box表示呢?是在下面的visual_det_seg.py代码中这个位置进行修改吗?应该如何修改呢?

def visualize_sample(nusc: NuScenes, sample_token: str, gt_boxes: EvalBoxes, pred_boxes: EvalBoxes, conf_th: float = 0.30,) -> None: """ Visualizes a sample from BEV with annotations and detection results. :param nusc: NuScenes object. :param sample_token: The nuScenes sample token. :param gt_boxes: Ground truth boxes grouped by sample. :param pred_boxes: Prediction grouped by sample. :param nsweeps: Number of sweeps used for lidar visualization. :param conf_th: The confidence threshold used to filter negatives. :param eval_range: Range in meters beyond which boxes are ignored. :param verbose: Whether to print to stdout. :param savepath: If given, saves the the rendering here instead of displaying. """

# seg map
seg_map = padding_seg_to_det(os.path.join(pred_seg_path, sample_token + '.png'))
seg_map = np.ascontiguousarray(seg_map, dtype=np.uint8)

# Retrieve sensor & pose records.
sample_rec = nusc.get('sample', sample_token)
sd_record = nusc.get('sample_data', sample_rec['data']['LIDAR_TOP'])
cs_record = nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token'])
pose_record = nusc.get('ego_pose', sd_record['ego_pose_token'])

# Get boxes.
boxes_gt_global = gt_boxes[sample_token]
boxes_est_global = pred_boxes[sample_token]

# Map GT boxes to lidar.
boxes_gt = boxes_to_sensor(boxes_gt_global, pose_record, cs_record)

# Map EST boxes to lidar.
boxes_est = boxes_to_sensor(boxes_est_global, pose_record, cs_record)
#c = get_color(box.name)
# Add scores to EST boxes.
for box_est, box_est_global in zip(boxes_est, boxes_est_global):
    box_est.score = box_est_global.detection_score

    # Show GT boxes.

    for box in boxes_gt:
        #c = get_color(box.name)
        view = np.array([[seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, 0, seg_map.shape[0] / 2],
                         [0, -seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, seg_map.shape[0] / 2],
                         [0, 0, 1, 0], [0, 0, 0, 1]])
        box.render_cv2(seg_map, view=view, colors=((0, 0, 255), (0, 0, 255), (0, 0, 255)), linewidth=2)

# Show EST boxes.
for box in boxes_est:
    # Show only predictions with a high score.
    assert not np.isnan(box.score), 'Error: Box score cannot be NaN!'
    if box.score >= conf_th:
        view = np.array([[seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, 0, seg_map.shape[0] / 2],
                         [0, -seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, seg_map.shape[0] / 2],
                         [0, 0, 1, 0], [0, 0, 0, 1]])
        box.render_cv2(seg_map, view=view, normalize=False, colors=((255, 0, 0), (255, 0, 0), (255, 0, 0)), linewidth=1)

return seg_map

3、为什么最终得到的BEV图不是连续帧呢?使用MINI数据集才有几十张BEV的图

非常的感谢您们给予的回复,万分感谢您的指导!

Bin-ze commented 7 months ago

您好,我想关于BEV图请教一下您:

1、关于在最终生成BEV图中如何给不一样的类别附上不一样的颜色box呢,例如,在BEV图上,给行人用蓝色box表示,给car用红色的box表示,给bus用绿色的box表示呢?是在下面的visual_det_seg.py代码中这个位置进行修改吗?应该如何修改呢?

def visualize_sample(nusc: NuScenes, sample_token: str, gt_boxes: EvalBoxes, pred_boxes: EvalBoxes, conf_th: float = 0.30,) -> None: """ Visualizes a sample from BEV with annotations and detection results. :param nusc: NuScenes object. :param sample_token: The nuScenes sample token. :param gt_boxes: Ground truth boxes grouped by sample. :param pred_boxes: Prediction grouped by sample. :param nsweeps: Number of sweeps used for lidar visualization. :param conf_th: The confidence threshold used to filter negatives. :param eval_range: Range in meters beyond which boxes are ignored. :param verbose: Whether to print to stdout. :param savepath: If given, saves the the rendering here instead of displaying. """

# seg map
seg_map = padding_seg_to_det(os.path.join(pred_seg_path, sample_token + '.png'))
seg_map = np.ascontiguousarray(seg_map, dtype=np.uint8)

# Retrieve sensor & pose records.
sample_rec = nusc.get('sample', sample_token)
sd_record = nusc.get('sample_data', sample_rec['data']['LIDAR_TOP'])
cs_record = nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token'])
pose_record = nusc.get('ego_pose', sd_record['ego_pose_token'])

# Get boxes.
boxes_gt_global = gt_boxes[sample_token]
boxes_est_global = pred_boxes[sample_token]

# Map GT boxes to lidar.
boxes_gt = boxes_to_sensor(boxes_gt_global, pose_record, cs_record)

# Map EST boxes to lidar.
boxes_est = boxes_to_sensor(boxes_est_global, pose_record, cs_record)
#c = get_color(box.name)
# Add scores to EST boxes.
for box_est, box_est_global in zip(boxes_est, boxes_est_global):
    box_est.score = box_est_global.detection_score

    # Show GT boxes.

    for box in boxes_gt:
        #c = get_color(box.name)
        view = np.array([[seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, 0, seg_map.shape[0] / 2],
                         [0, -seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, seg_map.shape[0] / 2],
                         [0, 0, 1, 0], [0, 0, 0, 1]])
        box.render_cv2(seg_map, view=view, colors=((0, 0, 255), (0, 0, 255), (0, 0, 255)), linewidth=2)

# Show EST boxes.
for box in boxes_est:
    # Show only predictions with a high score.
    assert not np.isnan(box.score), 'Error: Box score cannot be NaN!'
    if box.score >= conf_th:
        view = np.array([[seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, 0, seg_map.shape[0] / 2],
                         [0, -seg_map.shape[0] // (det_grid_conf['xbound'][1] * 2), 0, seg_map.shape[0] / 2],
                         [0, 0, 1, 0], [0, 0, 0, 1]])
        box.render_cv2(seg_map, view=view, normalize=False, colors=((255, 0, 0), (255, 0, 0), (255, 0, 0)), linewidth=1)

return seg_map

3、为什么最终得到的BEV图不是连续帧呢?使用MINI数据集才有几十张BEV的图

非常的感谢您们给予的回复,万分感谢您的指导!

分隔图颜色在test.py中修改https://github.com/Bin-ze/BEVFormer_segmentation_detection/blob/master/projects/mmdet3d_plugin/apis/test.py#L22

可能与读取方式有关,我使用完整的nuscene数据集生成的帧是连续的,就像主页展示的那样

Bin-ze commented 7 months ago

修改在这里: box.render_cv2(seg_map, view=view, colors=((0, 0, 255), (0, 0, 255), (0, 0, 255)), linewidth=2) 这里默认gt和pred分别为红色和蓝色,你只需要简单的修改一下代码,根据类别来展示不同的颜色即可

Bin-ze commented 7 months ago

你可以自己实现一个 get_color函数

MQC1111 commented 7 months ago

你可以自己实现一个 get_color函数

我已经做到了,非常感谢您的提示,跪谢 哈哈

MQC1111 commented 7 months ago

打扰您了,能否在请教您一个问题呢,我使用的全部的nuScenes数据集,为什么最后得到的BEV分割图只有6019张图呢,全部的数据集不应该有很多张吗

Bin-ze commented 7 months ago

因为默认是用的test集合的数据

MQC1111 commented 7 months ago

因为默认是用的test集合的数据

可否请问您,如果想获得比test集合更多的图片应该修改哪个文件中哪个地方的代码才能实现呀,跪谢回复!