-
Notifications
You must be signed in to change notification settings - Fork 557
/
eval_depth.py
77 lines (68 loc) · 3.43 KB
/
eval_depth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from __future__ import division
import sys
import cv2
import os
import numpy as np
import argparse
from depth_evaluation_utils import *
parser = argparse.ArgumentParser()
parser.add_argument("--kitti_dir", type=str, help='Path to the KITTI dataset directory')
parser.add_argument("--pred_file", type=str, help="Path to the prediction file")
parser.add_argument("--test_file_list", type=str, default='./data/kitti/test_files_eigen.txt',
help="Path to the list of test files")
parser.add_argument('--min_depth', type=float, default=1e-3, help="Threshold for minimum depth")
parser.add_argument('--max_depth', type=float, default=80, help="Threshold for maximum depth")
args = parser.parse_args()
def main():
pred_depths = np.load(args.pred_file)
test_files = read_text_lines(args.test_file_list)
gt_files, gt_calib, im_sizes, im_files, cams = \
read_file_data(test_files, args.kitti_dir)
num_test = len(im_files)
gt_depths = []
pred_depths_resized = []
for t_id in range(num_test):
camera_id = cams[t_id] # 2 is left, 3 is right
pred_depths_resized.append(
cv2.resize(pred_depths[t_id],
(im_sizes[t_id][1], im_sizes[t_id][0]),
interpolation=cv2.INTER_LINEAR))
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))
pred_depths = pred_depths_resized
rms = np.zeros(num_test, np.float32)
log_rms = np.zeros(num_test, np.float32)
abs_rel = np.zeros(num_test, np.float32)
sq_rel = np.zeros(num_test, np.float32)
d1_all = np.zeros(num_test, np.float32)
a1 = np.zeros(num_test, np.float32)
a2 = np.zeros(num_test, np.float32)
a3 = np.zeros(num_test, np.float32)
for i in range(num_test):
gt_depth = gt_depths[i]
pred_depth = np.copy(pred_depths[i])
mask = np.logical_and(gt_depth > args.min_depth,
gt_depth < args.max_depth)
# crop used by Garg ECCV16 to reprocude Eigen NIPS14 results
# if used on gt_size 370x1224 produces a crop of [-218, -3, 44, 1180]
gt_height, gt_width = gt_depth.shape
crop = np.array([0.40810811 * gt_height, 0.99189189 * gt_height,
0.03594771 * gt_width, 0.96405229 * gt_width]).astype(np.int32)
crop_mask = np.zeros(mask.shape)
crop_mask[crop[0]:crop[1],crop[2]:crop[3]] = 1
mask = np.logical_and(mask, crop_mask)
# Scale matching
scalor = np.median(gt_depth[mask])/np.median(pred_depth[mask])
pred_depth[mask] *= scalor
pred_depth[pred_depth < args.min_depth] = args.min_depth
pred_depth[pred_depth > args.max_depth] = args.max_depth
abs_rel[i], sq_rel[i], rms[i], log_rms[i], a1[i], a2[i], a3[i] = \
compute_errors(gt_depth[mask], pred_depth[mask])
print("{:>10}, {:>10}, {:>10}, {:>10}, {:>10}, {:>10}, {:>10}, {:>10}".format('abs_rel', 'sq_rel', 'rms', 'log_rms', 'd1_all', 'a1', 'a2', 'a3'))
print("{:10.4f}, {:10.4f}, {:10.4f}, {:10.4f}, {:10.4f}, {:10.4f}, {:10.4f}, {:10.4f}".format(abs_rel.mean(), sq_rel.mean(), rms.mean(), log_rms.mean(), d1_all.mean(), a1.mean(), a2.mean(), a3.mean()))
main()