-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevaluation.py
More file actions
49 lines (37 loc) · 1.41 KB
/
evaluation.py
File metadata and controls
49 lines (37 loc) · 1.41 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
import torch
import numpy as np
import cv2
from utils import parser
from models.TriGeoNet.TriGeoNet import TriGeoNet
if __name__ == "__main__":
model_config = parser()
left_image_path = r'xxxxx'
right_image_path = r'xxxxx'
model_config.ckpt = r'xxxxx'
def read_image(path):
img = cv2.imread(path, cv2.IMREAD_UNCHANGED).astype('float32')
if len(img.shape) == 3:
img = np.moveaxis(img, -1, 0) / 127.5 - 1.0
model_config.maxdisp = 96
model_config.mindisp = -96
model_config.channels = 3
else:
img = np.expand_dims(img, axis=0)
img = (img - np.mean(img)) / np.std(img)
model_config.maxdisp = 64
model_config.mindisp = -128
model_config.channels = 1
return img
left = read_image(left_image_path)
right = read_image(right_image_path)
model = TriGeoNet(model_config)
model.load_state_dict(torch.load(model_config.ckpt, map_location='cpu')['state_dict'])
model = model.cuda()
left = torch.from_numpy(left).unsqueeze(0).cuda()
right = torch.from_numpy(right).unsqueeze(0).cuda()
model.eval()
with torch.no_grad():
with torch.cuda.amp.autocast(enabled=True):
disp4, disp3, disp2, disp1 = model(left, right)
disp_result = np.squeeze(disp1.detach().cpu().numpy())
cv2.imwrite('disp_result.tif', disp_result)