fabiotosi92 / monoResMatch-Tensorflow

Tensorflow implementation of monocular Residual Matching (monoResMatch) network.
116 stars 20 forks source link

Disparity scaling error after resizing in evaluation_utils.py and evaluate_kitti,py? #7

Closed MShahzebKhan closed 4 years ago

MShahzebKhan commented 4 years ago

@fabiotosi92 I think there is a disparity scalling error in the convert_disps_to_depths_kitti function. After resizing the pred_disp, it should be scaled by dividing it with the pred_disp width before resizing and multiplying with the pred_disp current width. Whereas, in current case it is divided and multiplied by the same width size.

Similarly, the pred_disp variable in evluate_kitty.py in the eigen condition of if statement is not scaled at all after resizing.

`def convert_disps_to_depths_kitti(gt_disparities, pred_disparities, width): gt_depths = [] pred_depths = [] pred_disparities_resized = []

for i in range(len(gt_disparities)):
    gt_disp = gt_disparities[i]
    height, width = gt_disp.shape

    pred_disp = pred_disparities[i]
    pred_disp = cv2.resize(pred_disp, (width, height), interpolation=cv2.INTER_LINEAR)
    **pred_disp = pred_disp * pred_disp.shape[1] / width**
    pred_disparities_resized.append(pred_disp) 

    mask = gt_disp > 0

    gt_depth = width_to_focal[width] * 0.54 / (gt_disp + (1.0 - mask))
    pred_depth = width_to_focal[width] * 0.54 / pred_disp

    gt_depths.append(gt_depth)
    pred_depths.append(pred_depth)
return gt_depths, pred_depths, pred_disparities_resized `

` for t_id in range(num_samples): pred_disparities.append(np.load(os.path.join(args.disp_folder, str(t_id) + '.npy')))

    test_files = read_text_lines(args.gt_path + 'eigen_test_files.txt')
    gt_files, gt_calib, im_sizes, im_files, cams = read_file_data(test_files, args.gt_path)

    num_test = len(im_files)
    gt_depths = []
    pred_depths = []
    for t_id in range(num_samples):
        camera_id = cams[t_id]  # 2 is left, 3 is right
        depth = generate_depth_map(gt_calib[t_id], gt_files[t_id], im_sizes[t_id], camera_id, False, True)
        gt_depths.append(depth.astype(np.float32))

        **disp_pred = cv2.resize(pred_disparities[t_id], (im_sizes[t_id][1], im_sizes[t_id][0]), interpolation=cv2.INTER_LINEAR)**

        # need to convert from disparity to depth
        focal_length, baseline = get_focal_length_baseline(gt_calib[t_id], camera_id)
        depth_pred = (baseline * focal_length) / disp_pred
        depth_pred[np.isinf(depth_pred)] = 0

        pred_depths.append(depth_pred)`
fabiotosi92 commented 4 years ago

Hi! Thank you to highlight this issue, the "convert_disps_to_depths_kitti" function is wrong. However, we never use it for the Eigen testing split evaluation (it's a typo from an wrong older version using the KITTI training split). The disparity values are properly scaled in the main.py file (line 236):

disp = cv2.resize(disp[0], (width, height), interpolation=cv2.INTER_LINEAR) * (width/args.width)

and this is the reason why in the eigen condition of the evaluate_kitti.py is not scaled.