-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathpose_evaluation_utils.py
61 lines (52 loc) · 2.54 KB
/
pose_evaluation_utils.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
# Mostly based on the code written by Clement Godard:
# https://github.com/mrharicot/monodepth/blob/master/utils/evaluation_utils.py
import numpy as np
# import pandas as pd
from path import Path
from scipy.misc import imread
from tqdm import tqdm
from .sintel_io import cam_read
class test_framework_Sintel(object):
def __init__(self, root, sequence_set, seq_length=3, step=1):
self.root = root
self.img_files, self.poses, self.sample_indices = read_scene_data(self.root, sequence_set, seq_length, step)
def generator(self):
for img_list, pose_list, sample_list in zip(self.img_files, self.poses, self.sample_indices):
for snippet_indices in sample_list:
imgs = [imread(img_list[i]).astype(np.float32) for i in snippet_indices]
poses = [cam_read(pose_list[i], pose_only=True).astype(np.float32) for i in snippet_indices]
poses = np.stack(poses)
first_pose = poses[0]
poses[:,:,-1] -= first_pose[:,-1]
compensated_poses = np.linalg.inv(first_pose[:,:3]) @ poses
yield {'imgs': imgs,
'path': img_list[0],
'poses': compensated_poses
}
def __iter__(self):
return self.generator()
def __len__(self):
return sum(len(imgs) for imgs in self.img_files)
def read_scene_data(data_root, sequence_set, seq_length=3, step=1):
data_root = Path(data_root)
im_sequences = []
poses_sequences = []
indices_sequences = []
demi_length = (seq_length - 1) // 2
shift_range = np.array([step*i for i in range(-demi_length, demi_length + 1)]).reshape(1, -1)
sequences = set()
for seq in sequence_set:
corresponding_dirs = set((data_root/'clean').dirs(seq))
sequences = sequences | corresponding_dirs
print('getting test metadata for theses sequences : {}'.format(sequences))
for sequence in tqdm(sequences):
poses = sorted(Path(sequence.replace('/clean/', '/camdata_left/')).files('*.cam'))
# np.genfromtxt(data_root/'poses'/'{}.txt'.format(sequence.name)).astype(np.float64).reshape(-1, 3, 4)
imgs = sorted(sequence.files('*.png'))
# construct 5-snippet sequences
tgt_indices = np.arange(demi_length, len(imgs) - demi_length).reshape(-1, 1)
snippet_indices = shift_range + tgt_indices
im_sequences.append(imgs)
poses_sequences.append(poses)
indices_sequences.append(snippet_indices)
return im_sequences, poses_sequences, indices_sequences