-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
136 lines (129 loc) · 5.62 KB
/
reader.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import glob
import numpy as np
def get_data_mask(dirs):
dataset = []
for d in dirs:
batch = []
masks = glob.glob(d + 'mask-item-*.jpg')
for mask in masks:
dist_file = mask.split('.jpg')[0] + '.dist'
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
content = content[:-2]
label = content[-1]
distances = np.array([float(dis) for dis in content])
#print(np.mean(distances), np.median(distances), np.min(distances))
batch.append([mask,float(str(np.min(distances)))])
dataset.append(batch)
return dataset
labels = {'car': [1,0,0,0,0,0,0,0], 'person':[0,1,0,0,0,0,0,0], 'bicycle':[0,0,1,0,0,0,0,0],'traffic light': [0,0,0,1,0,0,0,0], 'bus': [0,0,0,0,1,0,0,0], 'motorcycle':[0,0,0,0,0,1,0,0],'truck':[0,0,0,0,0,0,1,0], 'skateboard': [0,0,0,0,0,0,0,1]}
def get_data_mask_graph(dirs):
dataset = []
for d in dirs:
batch = []
masks = glob.glob(d + 'mask-item-*.jpg')
for mask in masks:
dist_file = mask.split('.jpg')[0] + '.dist'
box_contnent = None
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
label = content[-2]
content = content[:-2]
if label not in list(labels.keys()):
continue
distances = np.array([float(dis) for dis in content])
batch.append([mask,labels[label],float(str(np.min(distances)))])
dataset.append(batch)
return dataset
def get_data_bbox(dirs):
dataset = []
for d in dirs:
batch = []
bbox = glob.glob(d + 'mask-item-*.bbox')
for box in bbox:
dist_file = box.split('.bbox')[0] + '.dist'
box_contnent = None
with open(box, 'r') as b:
box_content = b.read().split('\n')[0].split(',')
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
label = content[-2]
content = content[:-2]
if label not in list(labels.keys()):
continue
distances = np.array([float(dis) for dis in content])
batch.append([[float(bc) for bc in box_content] + labels[label],float(str(np.min(distances)))])
dataset.append(batch)
return dataset
def get_data_bbox_graph(dirs):
dataset = []
for d in dirs:
batch = []
bbox = glob.glob(d + 'mask-item-*.bbox')
for box in bbox:
dist_file = box.split('.bbox')[0] + '.dist'
box_contnent = None
with open(box, 'r') as b:
box_content = b.read().split('\n')[0].split(',')
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
label = content[-2]
content = content[:-2]
if label not in list(labels.keys()):
continue
distances = np.array([float(dis) for dis in content])
batch.append([[float(bc) for bc in box_content],labels[label],float(str(np.min(distances)))])
dataset.append(batch)
return dataset
def get_data_dis(dirs):
dataset = []
for d in dirs:
bbox = glob.glob(d + 'mask-item-*.bbox')
for box in bbox:
dist_file = box.split('.bbox')[0] + '.dist'
box_contnent = None
with open(box, 'r') as b:
box_content = b.read().split('\n')[0].split(',')
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
label = content[-2]
content = content[:-2]
if label not in list(labels.keys()):
continue
distances = np.array([float(dis) for dis in content])
dataset.append([[float(bc) for bc in box_content] + labels[label],float(str(np.min(distances)))])
return dataset
def get_depth_data(dirs):
dataset = []
interpol = []
for d in dirs:
bbox = glob.glob(d + 'mask-item-*.bbox')
for box in bbox:
dist_file = box.split('.bbox')[0] + '.dist'
box_contnent = None
with open(box, 'r') as b:
box_content = b.read().split('\n')[0].split(',')
with open(dist_file,encoding='utf8',errors='ignore') as f:
content = f.read().split('\n')
if len(content) <= 2:
continue
label = content[-2]
content = content[:-2]
if label not in list(labels.keys()):
continue
distances = np.array([float(dis) for dis in content])
dataset.append([[float(bc) for bc in box_content] + labels[label],float(str(np.min(distances)))])
main_image = d + d.split('/')[-2] + '.jpg'
interpolation = np.load(d+ 'interpolation.npy')
interpol.append([main_image,interpolation])
return dataset, interpol