-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathname_list_dataset.py
157 lines (118 loc) · 4.46 KB
/
name_list_dataset.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
import random
from collections import OrderedDict
import kitti_sample
class ElementList(object):
def __init__(self, parent, method, lst):
super().__init__()
self.parent = parent
self.method = method
self.lst = lst
def __getitem__(self, item):
return getattr(self.parent, self.method)(self.lst, item)
def __len__(self):
return len(self.lst[1])
def list_dir(path, ext):
return list(sorted([
os.path.splitext(f)[0]
for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f)) and os.path.splitext(f)[1] == ext
]))
class NameListDataset(object):
"""Class to load Kitti tracking dataset"""
def __init__(
self,
data_path = 'data/tracking/training/',
):
"""
"""
self._is_pil_image = True
self.data_path = data_path
self.image_path = os.path.join(self.data_path, 'image_2')
self.velo_path = os.path.join(self.data_path, 'velodyne')
self.calib_path = os.path.join(self.data_path, 'calib')
self.label_path = os.path.join(self.data_path, 'label_2')
self.imu_path = os.path.join(self.data_path, 'oxts')
self.dataset_list = list_dir(self.imu_path, '.txt')
oxts = [
kitti_sample.load_oxts_packets_and_poses(os.path.join(self.imu_path, name+'.txt'))
for name in self.dataset_list
]
frame_name_lists = []
for seq_name in self.dataset_list:
dir = os.path.join(self.velo_path, seq_name)
frame_name_list = list_dir(dir, '.bin')
frame_name_lists.append(frame_name_list)
self.sequences = []
for name, frame_name_list, oxts in zip(self.dataset_list, frame_name_lists, oxts):
self.sequences.append((name, frame_name_list, oxts))
pass
@staticmethod
def getLabelmap():
return ['Car', 'Van', 'Truck', 'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram', 'Misc']
def list_all_sequences(self):
"""Scan over all samples in the dataset"""
print('Start generation of a file list')
names = []
for root, _, fnames in sorted(os.walk(self.velo_path)):
for fname in sorted(fnames):
path = os.path.join(root, fname)
if os.path.isdir(path):
nameonly = os.path.splitext(fname)[0]
names.append(nameonly)
print('End generation of a file list')
return names
def __getitem__(self, sequence_index):
"""
Args:
sequence_index (int): Index of a sequence
Returns:
"""
return ElementList(self, '_get_frame', self.sequences[sequence_index])
def _get_frame(self, frame_list, frame_index):
"""
Args:
frame_list: ?
frame_index (int): Index of a frame
Returns:
"""
sequence_name, frame_name_list, oxts = frame_list
frame_name = frame_name_list[frame_index]
_, velo, calib, _ = self._getitem(
sequence_name,
frame_name,
load_image=False, load_velodyne=True, load_calib=True, load_label=False)
imu = oxts[int(frame_name)]
return sequence_name, velo, calib, imu
def _getitem(
self, sequence_name, frame_name,
load_image=True, load_velodyne=False, load_calib=True, load_label=True):
image = None
if load_image:
path = os.path.join(self.image_path, sequence_name, frame_name+'.png')
if self._is_pil_image:
image = kitti_sample.get_image_pil(path)
else:
image = kitti_sample.get_image(path)
velo = None
if load_velodyne:
path = os.path.join(self.velo_path, sequence_name, frame_name+'.bin')
velo = kitti_sample.get_velo_scan(path)
calib = None
if load_calib:
path = os.path.join(self.calib_path, sequence_name+'.txt')
calib = kitti_sample.get_calib(path)
label = None
if load_label:
path = os.path.join(self.label_path, sequence_name+'.txt')
# TODO filter only boxes for frame_name
label = kitti_sample.get_label(path)
return image, velo, calib, label
def __len__(self):
"""
Args:
none
Returns:
int: number of images in the dataset
"""
return len(self.dataset_list)