-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
executable file
·192 lines (172 loc) · 5.61 KB
/
visualize.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
# This file is covered by the LICENSE file in the root of this project.
import argparse
import os
import yaml
from auxiliary.laserscanvis import LaserScanVis
from auxiliary.dataset import SemKITTI_sk
from torch.utils.data import DataLoader
from vispy.scene import SceneCanvas
from vispy.util.event import Event
import time
import csv
import datetime
def collate_fn_BEV(data):
points = data[0][0]
remissions = data[0][1]
labels = data[0][2]
viridis_colors = data[0][3]
sem_label_colors = data[0][4]
return points, remissions, labels, viridis_colors, sem_label_colors
if __name__ == '__main__':
parser = argparse.ArgumentParser("./visualize.py")
parser.add_argument(
'--dataset', '-d',
type=str,
required=True,
help='Dataset to visualize. No Default',
)
parser.add_argument(
'--config', '-c',
type=str,
required=False,
default="config/semantic-kitti.yaml",
help='Dataset config file. Defaults to %(default)s',
)
parser.add_argument(
'--sequence', '-s',
type=str,
default="00",
required=False,
help='Sequence to visualize. Defaults to %(default)s',
)
parser.add_argument(
'--ignore_semantics', '-i',
dest='ignore_semantics',
default=False,
action='store_true',
help='Ignore semantics. Visualizes uncolored pointclouds. '
'Defaults to %(default)s',
)
parser.add_argument(
'--log_path',
dest='log_path',
default=None,
required=False,
help='Path to log visualization time to .csv file. Requires log_data argument. '
'Defaults to %(default)s',
)
parser.add_argument(
'--log_data',
dest='log_data',
default=False,
action='store_true',
help='Records and stores runtime for scanning and plotting visualizaions. Defaults to False'
)
parser.add_argument(
'--print_data',
dest='print_data',
default=False,
action='store_true',
help='Enables printing of runtime data to terminal. Defaults to False.'
)
parser.add_argument(
'--enable_auto',
dest='enable_auto',
default=False,
required=False,
action='store_true',
help='Enables instantaneous visualization of files for collecting'
' large amounts of visualization time measurements',
)
parser.add_argument(
'--shuffle',
dest='shuffle',
default=False,
required=False,
action='store_true',
help='Shuffles scans before visualization. Defaults to False'
)
FLAGS, unparsed = parser.parse_known_args()
# print summary of what we will do
print("*" * 80)
print("INTERFACE:")
print("Dataset", FLAGS.dataset)
print("Config", FLAGS.config)
print("Sequence", FLAGS.sequence)
print("ignore_semantics", FLAGS.ignore_semantics)
print("log_path", FLAGS.log_path)
print("log_data", FLAGS.log_data)
print("print_data", FLAGS.print_data)
print("enable_auto", FLAGS.enable_auto)
print("shuffle", FLAGS.shuffle)
print("*" * 80)
# prevent updating log_path if log_data not used
if FLAGS.log_path and not FLAGS.log_data:
print("Must pass log_data argument to specify log_path")
quit()
# Require log_path argument if log_data is passed
if FLAGS.log_data and not FLAGS.log_path:
print("Must specify a log_path")
quit()
# open config file
try:
print("Opening config file %s" % FLAGS.config)
CFG = yaml.safe_load(open(FLAGS.config, 'r'))
except Exception as e:
print(e)
print("Error opening yaml file.")
quit()
# fix sequence name
FLAGS.sequence = '{0:02d}'.format(int(FLAGS.sequence))
# does sequence folder exist?
scan_paths = os.path.join(FLAGS.dataset, "sequences",
FLAGS.sequence, "velodyne")
if os.path.isdir(scan_paths):
print(f"Sequence folder {scan_paths} exists! Using sequence from {scan_paths}")
else:
print(f"Sequence folder {scan_paths} doesn't exist! Exiting...")
quit()
color_dict = CFG["color_map"]
mydataset = SemKITTI_sk(data_path = "dataset/sequences",
imageset="train",
label_mapping="config/semantic-kitti-00.yaml",
sem_color_dict=color_dict,
percentLabels=1)
dataloader = DataLoader(mydataset, batch_size=1, shuffle=FLAGS.shuffle, collate_fn=collate_fn_BEV, num_workers=0)
data = enumerate(dataloader)
def temp():
start = time.time()
_, (points, _, labels, _, _) = next(data)
end = time.time()
print("Loaded points in {0} seconds".format(end-start))
return points, labels, labels, end-start
# create a visualizer
# TODO update class variables
vis = LaserScanVis(color_dict,
semantics=(not FLAGS.ignore_semantics),
verbose_runtime=FLAGS.print_data,
pullData=temp,
percent_points=1)
#key_press=key_press,
#canvas = canvas)
# print instructions
print("To navigate:")
print("\tn: next (next scan)")
print("\tq: quit (exit program)")
# if log_data flag is false, do not specify filewriter
if not FLAGS.log_data:
# run visualizer
vis.run()
quit()
# if log_data flag is true, open csv file for writing
now = datetime.datetime.now()
with open(FLAGS.log_path + '/{0}.csv'.format('{0}'.format(now).replace(" ", "_").replace(":", "-")[:19]),
'w', newline='') as csvfile:
print("Saving runtime data to ", csvfile.name)
fieldNames = ['Points','LoadData', 'PlotRaw','PlotSem']
writer = csv.DictWriter(csvfile, fieldnames=fieldNames)
writer.writeheader()
vis.csvwriter = writer
# run the visualizer
vis.run()