-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
77 lines (70 loc) · 2.19 KB
/
Copy patheval.py
File metadata and controls
77 lines (70 loc) · 2.19 KB
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
import sys
import os
import torch
import numpy as np
from collections import OrderedDict
from Trainer import Trainer
from utils import dispToDepth
def usage():
print("python eval.py /path/to/config.yaml /path/to/unzipped/weights/")
args = sys.argv
if len(args) != 3:
usage()
config_path = args[1]
weights_path = args[2]
t = Trainer(config_path)
device = t.device
modelName = t.modelName
# Encoder Model
encoder = t.models["encoder"]
encoderDict = torch.load(os.path.join(weights_path, "encoder.pth"), map_location=device)
try:
height = encoderDict.pop("height")
width = encoderDict.pop("width")
use_stereo = encoderDict.pop("use_stereo")
except:
pass
encoder.load_state_dict(encoderDict)
encoder.to(device)
encoder.eval()
# Depth Decoder Model
decoder = t.models["decoder"]
try:
decoder.load_state_dict(torch.load(os.path.join(weights_path, "decoder.pth"), map_location=device))
except:
odict = torch.load(os.path.join(weights_path, "depth.pth"), map_location=device)
odict_compat = OrderedDict([(key.replace("conv.conv", "conv"), value) for key, value in odict.items()])
del odict
decoder.load_state_dict(odict_compat)
decoder.to(device)
decoder.eval()
abs_rel = []
sq_rel = []
rms = []
log_rms = []
a1 = []
a2 = []
a3 = []
for batch_idx, inputs in enumerate(t.valLoader):
for key, value in inputs.items():
inputs[key] = value.to(device)
input_images = inputs[("color", 0, 0)]
features = encoder(input_images)
outputs = decoder(features)
_, depth = dispToDepth(outputs[("disp", 0)], 0.1, 100.0)
outputs[("depth", 0, 0)] = depth
losses = t.losses["Depth"](inputs, outputs)
abs_rel.append(losses["de/abs_rel"].item())
sq_rel.append(losses["de/sq_rel"].item())
rms.append(losses["de/rms"].item())
log_rms.append(losses["de/log_rms"].item())
a1.append(losses["da/a1"].item())
a2.append(losses["da/a2"].item())
a3.append(losses["da/a3"].item())
print("a1 : {}".format(np.mean(a1)))
print("a2 : {}".format(np.mean(a2)))
print("a3 : {}".format(np.mean(a3)))
print("abs_rel : {}".format(np.mean(abs_rel)))
print("sq_rel : {}".format(np.mean(sq_rel)))
print("rms : {}".format(np.mean(rms)))
print("log_rms : {}".format(np.mean(log_rms)))