-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation_folders.py
66 lines (55 loc) · 2.07 KB
/
validation_folders.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import configparser
from builtins import open
from builtins import str
# etc., as needed
#from future import standard_library
import torch.utils.data as data
import numpy as np
from imageio import imread
from path import Path
def crawl_folders(folders_list):
imgs = []
depth = []
for folder in folders_list:
current_imgs = sorted(folder.files('*.jpg'))
current_depth = []
for img in current_imgs:
d = img.dirname()/(img.name[:-4] + '.npy')
assert(d.isfile()), "depth file {} not found".format(str(d))
depth.append(d)
imgs.extend(current_imgs)
depth.extend(current_depth)
return imgs, depth
def load_as_float(path):
return imread(path).astype(np.float32)
class ValidationSet(data.Dataset):
"""A sequence data loader where the files are arranged in this way:
root/scene_1/0000000.jpg
root/scene_1/0000000.npy
root/scene_1/0000001.jpg
root/scene_1/0000001.npy
..
root/scene_2/0000000.jpg
root/scene_2/0000000.npy
.
transform functions must take in a list a images and a numpy array which can be None
"""
def __init__(self, root, transform=None):
self.root = Path(root)
scene_list_path = self.root/'val_left.txt'
self.scenes = [self.root/folder[:-1] for folder in open(scene_list_path)]
self.imgs, self.depth = crawl_folders(self.scenes)
self.transform = transform
def __getitem__(self, index):
img = load_as_float(self.imgs[index])
depth = np.load(self.depth[index]).astype(np.float32)
if self.transform is not None:
img, _ = self.transform([img], None)
img = img[0]
return img, depth ###---the depth file is the .npy file correspoding to the .jpg with the same name
def __len__(self):
return len(self.imgs)