-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathutil.py
72 lines (62 loc) · 2.26 KB
/
util.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
import re
import os
import sys
import glob
import logging
import datetime
import numpy as np
def readPFM(file):
file = open(file, 'rb')
color = None
width = None
height = None
scale = None
endian = None
header = file.readline().rstrip()
if header == 'PF':
color = True
elif header == 'Pf':
color = False
else:
raise Exception('Not a PFM file.')
dim_match = re.match(r'^(\d+)\s(\d+)\s$', file.readline())
if dim_match:
width, height = map(int, dim_match.groups())
else:
raise Exception('Malformed PFM header.')
scale = float(file.readline().rstrip())
if scale < 0: # little-endian
endian = '<'
scale = -scale
else:
endian = '>' # big-endian
data = np.fromfile(file, endian + 'f')
shape = (height, width, 3) if color else (height, width)
data = np.reshape(data, shape)
data = np.flipud(data)
return data, scale
def ft3d_filenames(path):
ft3d_path = path
ft3d_samples_filenames = {}
for prefix in ["TRAIN", "TEST"]:
ft3d_train_data_path = os.path.join(ft3d_path, 'frames_cleanpass/TRAIN')
ft3d_train_labels_path = os.path.join(ft3d_path, 'disparity/TRAIN')
left_images_filenames = sorted(glob.glob(ft3d_train_data_path + "/*/*/left/*"))
right_images_filenames = sorted(glob.glob(ft3d_train_data_path + "/*/*/right/*"))
disparity_filenames = sorted(glob.glob(ft3d_train_labels_path + "/*/*/left/*"))
ft3d_samples_filenames[prefix] = [(left_images_filenames[i],
right_images_filenames[i],
disparity_filenames[i]) for i in range(len(left_images_filenames))]
return ft3d_samples_filenames
def init_logger(log_path, name="dispnet"):
root = logging.getLogger()
root.setLevel(logging.NOTSET)
logfile = os.path.join(log_path, "%s-%s.log" % (name, datetime.datetime.today()))
fileHandler = logging.FileHandler(logfile)
fileHandler.setLevel(logging.INFO)
root.addHandler(fileHandler)
consoleHandler = logging.StreamHandler(sys.stdout)
consoleHandler.setLevel(logging.DEBUG)
consoleHandler.terminator = ""
root.addHandler(consoleHandler)
logging.debug("Logging to %s" % logfile)