This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_performance.py
1626 lines (1330 loc) · 59.9 KB
/
plot_performance.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
from pathlib import Path
from loader_utils import *
import matplotlib
import matplotlib.pyplot as plt
import argparse
from typing import List, Tuple, Dict, Any, Optional
import shutil
# Get path to methods from command line
parser = argparse.ArgumentParser()
parser.add_argument('results_folder', type=Path)
parser.add_argument(
'endpoint_error_path',
type=Path,
help=
"Path to the folder that contains the method endpoint error files generated by the `visualization/generate_flow_error_plot_data.py` script; probably /efs/argoverse2/"
)
parser.add_argument(
'checkpoint_epe_files',
type=Path,
help=
"Path to the folder that contains the method checkpoint EPE files generated by the `data_prep_scripts/checkpoint_inspection*` family of scripts; probably ./checkpoint_eval_launch_dir"
)
parser.add_argument('--dataset',
type=str,
default="argo",
choices=["argo", "waymo"])
args = parser.parse_args()
assert args.results_folder.exists(
), f"Results folder {args.results_folder} does not exist"
assert args.endpoint_error_path.exists(
), f"Endpoint error path {args.endpoint_error_path} does not exist"
assert args.checkpoint_epe_files.exists(
), f"Checkpoint EPE files {args.checkpoint_epe_files} does not exist"
save_folder = args.results_folder / f"plots_{args.dataset}"
save_folder.mkdir(exist_ok=True, parents=True)
def set_font(size):
matplotlib.rcParams.update({# Use mathtext, not LaTeX
'text.usetex': False,
# Use the Computer modern font
'font.family': 'serif',
'font.serif': ['cmr10'],
'font.size' : size,
'mathtext.fontset': 'cm',
# Use ASCII minus
'axes.unicode_minus': False,
})
def color_map(rev: bool = False):
# return 'gist_earth'
if rev:
return 'magma_r'
return 'magma'
def color(count, total_elements, intensity=1.3):
start = 0.2
stop = 0.7
colormap = matplotlib.cm.get_cmap(color_map())
cm_subsection = np.linspace(start, stop, total_elements)
#color = [matplotlib.cm.gist_earth(x) for x in cm_subsection][count]
color = [colormap(x) for x in cm_subsection][count]
# Scale the color by intensity while leaving the 4th channel (alpha) unchanged
return [min(x * intensity, 1) for x in color[:3]] + [color[3]]
def color2d(count_x, count_y, total_elements_x, total_elements_y):
# Select the actual color, then scale along the intensity axis
start = 1.7
stop = 1
intensity_scale = np.linspace(start, stop, total_elements_y)
intensity = intensity_scale[count_y]
return color(count_x, total_elements_x, intensity)
linewidth = 0.5
minor_tick_color = (0.9, 0.9, 0.9)
def grid(minor=True, axis='both'):
plt.grid(linewidth=linewidth / 2, axis=axis)
if minor:
plt.grid(which='minor',
color=minor_tick_color,
linestyle='--',
alpha=0.7,
clip_on=True,
linewidth=linewidth / 4,
zorder=0)
def savefig(name, pad: float = 0):
for ext in ['pdf', 'png']:
outfile = save_folder / f"{name}.{ext}"
print("Saving", outfile)
plt.savefig(outfile, bbox_inches='tight', pad_inches=pad)
plt.clf()
def savetable(name, content: List[List[Any]]):
outfile = save_folder / f"{name}.txt"
def fmt(e):
if type(e) == float or type(e) == np.float64 or type(
e) == np.float32 or type(e) == np.float16:
return f"{e:.3f}"
return str(e)
print("Saving", outfile)
with open(outfile, 'w') as f:
assert type(content) == list, "Table must be a list of rows"
for row in content:
assert type(row) == list, "Table rows must be lists"
f.write(" & ".join([fmt(e) for e in row]) + "\\\\\n")
def load_results(validation_folder: Path,
dataset: str = args.dataset,
full_distance: str = "ALL"):
print("Loading results from", validation_folder)
config_folder = validation_folder / "configs"
print()
assert config_folder.exists(
), f"Config folder {config_folder} does not exist"
result_lst = []
for architecture_folder in sorted(config_folder.glob("*/")):
if "bak" in architecture_folder.name:
continue
def name_result_file(result_file: Path):
return architecture_folder.name + "_" + ".".join(
result_file.stem.split(".")[:-1])
result_files = list((architecture_folder / dataset).glob("*.pkl"))
result_names = [ name_result_file(result_file) for result_file in result_files]
def name_child_result_file(result_file: Path):
return architecture_folder.name + "_" + result_file.parent.name + "_" + ".".join(
result_file.stem.split(".")[:-1]).replace("eval_config_", "")
# Add result files in child folders
child_result_files = list((architecture_folder / dataset).glob("*/*.pkl"))
child_result_names = [ name_child_result_file(result_file) for result_file in child_result_files]
# Concatenate the lists
result_files.extend(child_result_files)
result_names.extend(child_result_names)
for result_file, result_name in zip(result_files, result_names):
result_lst.append(
ResultInfo(result_name,
result_file,
full_distance=full_distance))
return sorted(result_lst, key=lambda x: x.pretty_name())
print("Loading results...")
results = load_results(args.results_folder)
results_close = load_results(args.results_folder, full_distance="CLOSE")
results_far = load_results(args.results_folder, full_distance="FAR")
print("Done loading results.")
print(results)
assert len(
results) > 0, f"No results found in {args.results_folder.absolute()}"
def plot_epe_components_vs_epoch_per_method(metric : str):
valid_metrics = ["threeway", "foreground_dynamic", "foreground_static", "background"]
assert metric in valid_metrics, f"Invalid metric {metric}, must be one of {valid_metrics}"
ours_2x_threeway = [0.109, 0.085, 0.077, 0.074, 0.072, 0.069, 0.068, 0.067, 0.068, 0.066]
ours_2x_foreground_dynamic = [0.293, 0.221, 0.19, 0.188, 0.184, 0.172, 0.167, 0.166, 0.168, 0.163]
ours_2x_foreground_static = [0.017, 0.017, 0.021, 0.018, 0.017, 0.018, 0.018, 0.017, 0.018, 0.018]
ours_2x_background = [0.017, 0.017, 0.021, 0.017, 0.017, 0.018, 0.018, 0.017, 0.017, 0.018]
ours_1x_threeway = [0.112, 0.1, 0.096, 0.093, 0.094, 0.092, 0.091, 0.091, 0.09, 0.089]
ours_1x_foreground_dynamic = [0.29, 0.258, 0.245, 0.24, 0.243, 0.235, 0.232, 0.229, 0.229, 0.224]
ours_1x_foreground_static = [0.024, 0.021, 0.022, 0.02, 0.019, 0.021, 0.021, 0.021, 0.02, 0.021]
ours_1x_background = [0.024, 0.021, 0.021, 0.02, 0.019, 0.02, 0.021, 0.021, 0.02, 0.021]
ymin = 0
# max of maxes of each metric
ymax = 0.02 + max(max(ours_1x_threeway), max(ours_2x_threeway), max(ours_1x_foreground_dynamic), max(ours_2x_foreground_dynamic), max(ours_1x_foreground_static), max(ours_2x_foreground_static), max(ours_1x_background), max(ours_2x_background))
epochs = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49]
# 2x are all dotted, 1x are all dashed
linewidth = 0.5
markersize_1x = 2
markersize_2x = 6
if metric == "threeway":
# plot the threeway EPE for both in black
plt.plot(epochs, ours_1x_threeway, label="1x", color='black', linestyle='-', marker='o', markersize=markersize_1x, linewidth=linewidth)
plt.plot(epochs, ours_2x_threeway, label="3x", color='black', linestyle='--', marker='o', markersize=markersize_2x, linewidth=linewidth)
if metric == "foreground_dynamic":
# plot the foreground dynamic EPE for both in red
plt.plot(epochs, ours_1x_foreground_dynamic, label="1x", color='red', linestyle='-', marker='o', markersize=markersize_1x, alpha=0.5, linewidth=linewidth)
plt.plot(epochs, ours_2x_foreground_dynamic, label="3x", color='red', linestyle='--', marker='o', markersize=markersize_2x, alpha=0.5, linewidth=linewidth)
if metric == "foreground_static":
# plot the foreground static EPE for both in green
plt.plot(epochs, ours_1x_foreground_static, label="1x", color='green', linestyle='-', marker='o', markersize=markersize_1x, alpha=0.5, linewidth=linewidth)
plt.plot(epochs, ours_2x_foreground_static, label="3x", color='green', linestyle='--', marker='o', markersize=markersize_2x, alpha=0.5, linewidth=linewidth)
if metric == "background":
# plot the background EPE for both in blue
plt.plot(epochs, ours_1x_background, label="1x", color='blue', linestyle='-', marker='o', markersize=markersize_1x, alpha=0.5, linewidth=linewidth)
plt.plot(epochs, ours_2x_background, label="3x", color='blue', linestyle='--', marker='o', markersize=markersize_2x, alpha=0.5, linewidth=linewidth)
plt.ylim(bottom=ymin, top=ymax)
plt.xlabel("Epoch")
plt.ylabel("EPE (m)")
plt.legend()
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
def plot_scaling(x_label: bool = True, log_scale: bool = False):
ours_xl_results = [
# (5.0, 0.054),
(3.0, 0.056),
(1.0, 0.072),
#(0.1, 0.134),
]
ours_results = [
(5.0, 0.058),
(3.0, 0.066),
# (2.0, 0.076),
(1.0, 0.087),
(0.5, 0.101),
(0.2, 0.116),
(0.1, 0.139),
(0.01, 0.216),
]
fastflow_xl_results = [
(1.0, 0.058),
#(0.1, 0.124),
]
fastflow_results = [
(1.0, 0.076),
(0.5, 0.091),
(0.2, 0.104),
(0.1, 0.125),
(0.01, 0.202),
]
plt.gca().axvspan(1, 10, alpha=0.08, facecolor='blue')
plt.plot(*zip(*ours_results),
label="Ours",
color='red',
marker='o',
linewidth=0.5,
markersize=2)
# Color the XL results dark red
# Dark red is (0.545, 0, 0)
plt.plot(*zip(*ours_xl_results),
label="Ours XL",
color='red',
marker='s',
linestyle='--',
linewidth=0.5,
markersize=4)
plt.plot(*zip(*fastflow_results),
label="FastFlow3D",
color='black',
marker='o',
linewidth=0.5,
markersize=2)
plt.plot(*zip(*fastflow_xl_results),
label="FastFlow3D XL",
color='black',
marker='s',
linestyle='--',
linewidth=0.5,
markersize=4)
if x_label:
plt.xlabel("Dataset Size as Percentage of AV2 Sensor Train Split")
plt.ylabel("Threeway EPE (m)")
# Set x ticks
if log_scale:
plt.xticks([0.01, 0.1, 0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0],
["1%", "10%", "20%", "50%", "100%", "200%", "300%", "", "500%"])
else:
plt.xticks([0.01, 0.1, 0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0],
["1%", "10%", "20%", "50%", "100%", "200%", "300%", "", "500%"])
# Horizontal line
# plt.axhline(y=0.087,
# color='black',
# linestyle='--',
# linewidth=linewidth / 2)
plt.legend(loc='lower left')
# Draw arrow pointing from top right to bottom left
plt.annotate('',
xy=(0.01, 0.19),
xytext=(0.01, 0.10),
color='gray',
arrowprops=dict(arrowstyle="<-", color='gray'))
if log_scale:
plt.yscale('log')
plt.xscale('log')
# plt.yticks([
# 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18,
# 0.19, 0.20
# ], [
# "0.08", "", "0.10", "", "0.12", "", "0.14", "", "0.16", "", "0.18",
# "", "0.20"
# ])
plt.yticks([0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22], [
"0.06", "0.08", "0.10", "0.12", "0.14", "0.16", "0.18", "0.20",
"0.22"
])
plt.xticks([0.01, 0.1, 0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0],
["1%", "10%", "20%", "50%", "100%", "200%", "300%", "", "500%"])
# Draw text along arrow
plt.text(0.0096,
0.14,
'Better',
color='gray',
ha='center',
rotation=90,
rotation_mode='anchor')
else:
# Draw text along arrow
plt.text(0,
0.15,
'Better',
color='gray',
ha='center',
rotation=90,
rotation_mode='anchor')
print(plt.xlim())
# set X axis limit to -0.1395, 3.1495
plt.xlim(left=-0.1395, right=5.8)
# plt.text(2,
# 0.19,
# 'AV2 LiDAR\nDataset Frames',
# color='blue',
# ha='center',
# rotation_mode='anchor')
plt.text(2.5,
0.19,
'Data without\nHuman Labels',
color='blue',
ha='center',
rotation_mode='anchor')
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
def plot_speed_vs_performance_tradeoff(perf_error_bar: bool = True,
runtime_error_bar: bool = True,
gradient_bg: bool = True):
runtimes = {
'ZeroFlow 1x': 29.33,
'ZeroFlow 3x': 29.33,
'ZeroFlow 5x': 29.33,
'FastFlow3D': 29.33,
'ZeroFlow XL 3x': 260.61,
'FastFlow3D XL': 260.61,
'NSFP': 26285.0,
'Chodosh': 26285.0 + 8996.4,
'Gojcic': 6087.87,
'Sim2Real': 99.3477,
'EgoFlow': 2116.34,
'PPWC': 79.4275,
'FlowStep3D': 687.536,
'ICP': 523.11,
}
runtimes_error_bar = {
'ZeroFlow 1x': 2.38,
'ZeroFlow 3x': 2.38,
'ZeroFlow 5x': 2.38,
'ZeroFlow XL 3x': 1.21,
'FastFlow3D': 2.38,
'FastFlow3D XL': 2.38,
'NSFP': 18139.3,
'Chodosh': 20247.7,
'Gojcic': 1690.56,
'Sim2Real': 13.88,
'EgoFlow': 292.32,
'PPWC': 2.20,
'FlowStep3D': 3.13,
'ICP': 169.34,
}
perf_error_bar_dims = {
'ZeroFlow 1x': (0.00, 0.002),
'FastFlow3D': (0.002, 0.003),
}
points_processed = {
'ZeroFlow 1x': 52871.6,
'ZeroFlow 3x': 52871.6,
'ZeroFlow 5x': 52871.6,
'ZeroFlow XL 3x': 52871.6,
'FastFlow3D': 52871.6,
'FastFlow3D XL': 52871.6,
'NSFP': 52871.6,
'Chodosh': 52871.6,
'Gojcic': 20000,
'Sim2Real': 8192,
'EgoFlow': 8192,
'PPWC': 8192,
'FlowStep3D': 8192,
'ICP': 52871.6,
}
performance = {
'ZeroFlow 1x': 0.087,
'ZeroFlow 3x': 0.066,
'ZeroFlow 5x': 0.060,
'ZeroFlow XL 3x': 0.056,
'FastFlow3D XL': 0.058,
'NSFP': 0.068,
'Chodosh': 0.061,
'FastFlow3D': 0.076,
'PPWC': 0.130,
'FlowStep3D': 0.161,
'Sim2Real': 0.157,
'EgoFlow': 0.205,
'Gojcic': 0.083,
'ICP': 0.204,
}
uses_labels = {
'ZeroFlow 1x': False,
'ZeroFlow 3x': False,
'ZeroFlow 5x': False,
'ZeroFlow XL 3x': False,
'NSFP': False,
'FastFlow3D': True,
'FastFlow3D XL': True,
'PPWC': False,
'FlowStep3D': False,
'Sim2Real': False,
'EgoFlow': False,
'Gojcic': True,
'Chodosh': False,
'ICP': False,
}
horiz_offset = 2.5
vert_offset = 6.0
label_offset = {
'ICP': (-horiz_offset, -vert_offset),
'Sim2Real': (-horiz_offset, -vert_offset),
'NSFP': (horiz_offset, vert_offset),
'Gojcic': (-horiz_offset, vert_offset),
'Chodosh': (horiz_offset, -vert_offset),
'FastFlow3D XL': (0, vert_offset),
'ZeroFlow XL 3x': (0, -vert_offset),
'ZeroFlow 3x': (0, vert_offset* 0.2),
'ZeroFlow 5x': (0, -vert_offset* 0.2),
}
keys = runtimes.keys()
runtimes = [runtimes[k] for k in keys]
performance = [performance[k] for k in keys]
shapes = ['x' if uses_labels[k] else 'o' for k in keys]
alphas = [1.0 if uses_labels[k] else 1.0 for k in keys]
gliph_colors = [
'red' if ("Ours" in k or "ZeroFlow" in k) else
('black' if uses_labels[k] else 'black') for k in keys
]
text_colors = ['red' if k == 'Ours' else 'black' for k in keys]
points = [points_processed[k] for k in keys]
worst_runtime = max(runtimes)
best_runtime = min(runtimes)
worst_perf = max(performance)
best_perf = min(performance)
print(worst_runtime, best_runtime, worst_perf, best_perf)
# breakpoint()
plt.gca().axvspan(0, 100, alpha=0.08, facecolor='blue')
def gradient_image(ax, direction=0.3, cmap_range=(0, 1), **kwargs):
"""
Draw a gradient image based on a colormap.
Parameters
----------
ax : Axes
The axes to draw on.
direction : float
The direction of the gradient. This is a number in
range 0 (=vertical) to 1 (=horizontal).
cmap_range : float, float
The fraction (cmin, cmax) of the colormap that should be
used for the gradient, where the complete colormap is (0, 1).
**kwargs
Other parameters are passed on to `.Axes.imshow()`.
In particular, *cmap*, *extent*, and *transform* may be useful.
"""
phi = direction * np.pi / 2
v = np.array([np.cos(phi), np.sin(phi)])
X = np.array([[v @ [1, 0], v @ [1, 1]], [v @ [0, 0], v @ [0, 1]]])
a, b = cmap_range
X = a + (b - a) / X.max() * X
im = ax.imshow(X,
interpolation='bicubic',
clim=(0, 1),
aspect='auto',
**kwargs)
return im
if gradient_bg:
gradient_image(plt.gca(),
direction=0.65,
extent=(0.0, 1, 0, 1),
transform=plt.gca().transAxes,
cmap=plt.get_cmap('Greys'),
alpha=0.35)
plt.ylim(bottom=best_perf - 0.014, top=worst_perf + 0.008)
plt.xlim(left=18, right=worst_runtime * 1.7)
plt.text(43,
worst_perf,
'Real Time at 10Hz',
color='blue',
ha='center',
rotation_mode='anchor')
for key, runtime, perf, shape, alpha, point_count, gliph_color, text_color in zip(
keys, runtimes, performance, shapes, alphas, points, gliph_colors,
text_colors):
fontweight = 'bold' if key == 'Ours' else 'normal'
dot_scale = 35
alignment = 'left' if runtime < 20000 else 'right'
x_offset_sign = 1 if alignment == 'left' else -1
plt.scatter(runtime,
perf,
marker=shape,
label=key,
color=gliph_color,
zorder=10,
s=dot_scale,
alpha=alpha,
edgecolors='none')
if perf_error_bar:
if key in perf_error_bar_dims:
plt.errorbar(runtime,
perf,
yerr=np.array([perf_error_bar_dims[key]]).T,
color=gliph_color,
capsize=1.5,
zorder=0,
alpha=0.2)
if runtime_error_bar:
plt.errorbar(runtime,
perf,
xerr=runtimes_error_bar[key],
color=gliph_color,
capsize=1.5,
zorder=0,
alpha=0.2)
# Annotate with name
if point_count < 50000:
annotation_name = f"{key} ({point_count / 1000.0:0.1f}k points)"
else:
annotation_name = f"{key} (Full)"
plt.annotate(annotation_name, (runtime, perf),
xytext=(6 * x_offset_sign + label_offset.get(key,
(0, 0))[0],
-2.75 + label_offset.get(key, (0, 0))[1]),
textcoords='offset points',
color=text_color,
ha=alignment,
fontweight=fontweight)
# Set x axis log scale
plt.xscale('log')
# Make vertical bar at 100 on x axis
# plt.axvline(100, color='blue', linestyle='--', linewidth=2, zorder=0)
plt.xlabel("Runtime (ms)")
plt.ylabel("Threeway EPE (m)")
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
# Draw arrow pointing from top right to bottom left
plt.annotate('',
xy=(worst_runtime, worst_perf),
xytext=(worst_runtime / 4, worst_perf - 0.04),
color='gray',
arrowprops=dict(arrowstyle="<-", color='gray'))
# Draw text along arrow
plt.text(worst_runtime / 2,
worst_perf - 0.017,
'Better',
color='gray',
ha='center',
rotation=35,
rotation_mode='anchor')
# Set plt y axis min to 0.05
# plt.annotate('Worse', xy=(worst_runtime, worst_perf), color='gray')
# grid(minor=False, axis='x')
def process_metacategory_counts(result):
full_error_count = result['per_class_bucketed_error_count']
metacatagory_results = {}
# How do we do on vehicles by speed?
for metacatagory in METACATAGORIES:
category_names = METACATAGORIES[metacatagory]
category_idxes = [CATEGORY_NAME_TO_IDX[cat] for cat in category_names]
metacatagory_counts = full_error_count[category_idxes]
# Sum up other axes
metacatagory_counts = np.sum(metacatagory_counts, axis=(1, 2))
metacatagory_results[metacatagory] = {}
for category_result, category_name in zip(metacatagory_counts,
category_names):
metacatagory_results[metacatagory][category_name] = category_result
return metacatagory_results
def process_category_speed_counts(result):
category_speed_counts_raw = result['per_class_bucketed_error_count'].sum(
axis=2)
category_speed_counts_normalized = category_speed_counts_raw / category_speed_counts_raw.sum(
axis=1, keepdims=True)
return category_speed_counts_normalized, category_speed_counts_raw
def bar_offset(pos_idx, num_pos, position_offset=0.2):
"""
Compute the X offset for a bar plot given the number of bars and the
index of the bar.
"""
return -(num_pos + 1) / 2 * position_offset + position_offset * (pos_idx +
1)
BAR_WIDTH = 0.07
num_metacatagories = len(METACATAGORIES)
def merge_dict_list(dict_list):
result_dict = {}
for d in dict_list:
for k, v in d.items():
if k not in result_dict:
result_dict[k] = []
result_dict[k].append(v)
return result_dict
def plot_mover_nonmover_vs_error_by_category(results: List[ResultInfo],
metacatagory, vmax):
if len(results) <= 0:
return
valid_results_pretty_name_set = {
"FastFlow3D", "FastFlow3D XL", "ZeroFlow", "ZeroFlow 2x",
"ZeroFlow XL", "ZeroFlow XL 2x", "NSFP"
}
results = [
r for r in results if r.pretty_name() in valid_results_pretty_name_set
]
for result_idx, result in enumerate(results):
metacatagory_epe_by_speed = result.get_metacatagory_epe_by_speed(
metacatagory)
xs = np.arange(len(metacatagory_epe_by_speed)) + bar_offset(
result_idx, len(results), BAR_WIDTH)
plt.bar(xs,
metacatagory_epe_by_speed,
label=result.pretty_name(),
width=BAR_WIDTH,
color=color(result_idx, len(results)),
zorder=3)
if metacatagory == "BACKGROUND":
plt.xticks([-1, 0, 1], ["", "All", ""])
plt.xlabel(" ")
plt.legend()
else:
speed_buckets = result.speed_bucket_categories()
plt.xticks(np.arange(len(speed_buckets)), [
f"{l:0.1f}-" + (f"{u:0.1f}" if u != np.inf else "$\infty$")
for l, u in speed_buckets
],
rotation=0)
plt.xlabel("Speed Bucket (m/s)")
plt.ylabel("Average EPE (m)")
plt.ylim(0, vmax)
grid()
def table_speed_vs_error(results: List[ResultInfo]):
# for metacatagory in METACATAGORIES:
rows = []
for result in results:
row = [result.pretty_name()]
for metacatagory in METACATAGORIES:
metacatagory_epe_by_speed = result.get_metacatagory_epe_by_speed(
metacatagory)
print(metacatagory, metacatagory_epe_by_speed)
row.extend(metacatagory_epe_by_speed.tolist())
rows.append(row)
return rows
def plot_nonmover_epe_overall(results: List[ResultInfo], vmax):
for result_idx, result in enumerate(results):
nonmover_epe = result.get_nonmover_point_epe()
xs = bar_offset(result_idx, len(results), BAR_WIDTH)
plt.bar(xs,
nonmover_epe,
label=result.pretty_name(),
width=BAR_WIDTH,
color=color(result_idx, len(results)),
zorder=3)
plt.ylabel("Average EPE (m)")
plt.xticks([], [])
plt.ylim(0, vmax)
plt.legend()
grid()
def plot_mover_epe_overall(results: List[ResultInfo], vmax):
for result_idx, result in enumerate(results):
mover_epe = result.get_mover_point_all_epe()
xs = bar_offset(result_idx, len(results), BAR_WIDTH)
plt.bar(xs,
mover_epe,
label=result.pretty_name(),
width=BAR_WIDTH,
color=color(result_idx, len(results)),
zorder=3)
plt.ylabel("Average EPE (m)")
plt.xticks([], [])
plt.ylim(0, vmax)
plt.legend()
grid()
def table_mover_nonmover_epe_overall(results: List[ResultInfo]):
rows = []
for result in results:
row = [result.pretty_name()]
row.append(result.get_nonmover_point_epe())
row.append(result.get_mover_point_all_epe())
rows.append(row)
return rows
def plot_metacatagory_epe_counts(results: List[ResultInfo]):
for meta_idx, metacatagory in enumerate(sorted(METACATAGORIES.keys())):
for result_idx, result in enumerate(results):
# Each error bucket is a single bar in the stacked bar plot.
metacatagory_epe_counts = result.get_metacatagory_count_by_epe(
metacatagory)
x_pos = meta_idx + bar_offset(
len(results) - result_idx - 1, len(results), BAR_WIDTH)
y_height = metacatagory_epe_counts.sum(
) / metacatagory_epe_counts.sum()
bottom = 0
for epe_idx, (epe_count,
(bucket_lower, bucket_upper)) in enumerate(
zip(metacatagory_epe_counts,
result.speed_bucket_categories())):
y_height = epe_count / metacatagory_epe_counts.sum()
epe_color = color2d(result_idx, epe_idx, len(results),
len(metacatagory_epe_counts))
label = None
if epe_idx == len(
metacatagory_epe_counts) - 1 and meta_idx == 0:
label = result.pretty_name()
rect = plt.barh([x_pos], [y_height],
label=label,
height=BAR_WIDTH,
color=epe_color,
left=bottom)
bottom += y_height
# Draw text in middle of bar
plt.text(bottom - y_height / 2,
x_pos,
f"{y_height * 100:0.1f}%",
ha="center",
va="center",
color="white",
fontsize=4)
# xlabels to be the metacatagories
plt.yticks(np.arange(len(METACATAGORIES)),
[METACATAGORY_TO_SHORTNAME[e] for e in METACATAGORIES.keys()],
rotation=0)
plt.xticks(np.linspace(0, 1, 5),
[f"{e}%" for e in np.linspace(0, 100, 5).astype(int)])
plt.xlabel("Percentage of Endpoints Within Error Threshold")
legend = plt.legend(loc="lower left", fancybox=False)
# set the boarder of the legend artist to be transparent
# legend.get_frame().set_edgecolor('none')
plt.tight_layout()
# plt.legend()
def plot_metacatagory_epe_counts_v15(results: List[ResultInfo]):
for meta_idx, metacatagory in enumerate(sorted(METACATAGORIES.keys())):
for result_idx, result in enumerate(results):
# Each error bucket is a single bar in the stacked bar plot.
metacatagory_epe_counts = result.get_metacatagory_count_by_epe(
metacatagory)
x_pos = meta_idx + bar_offset(
len(results) - result_idx - 1, len(results), BAR_WIDTH)
y_height = metacatagory_epe_counts.sum(
) / metacatagory_epe_counts.sum()
bottom = 0
metacatagory_epe_counts_subset = metacatagory_epe_counts[:2]
for epe_idx, epe_count in enumerate(
metacatagory_epe_counts_subset):
y_height = epe_count / metacatagory_epe_counts.sum()
y_sum = metacatagory_epe_counts[:epe_idx + 1].sum(
) / metacatagory_epe_counts.sum()
epe_color = color2d(result_idx, epe_idx, len(results),
len(metacatagory_epe_counts_subset))
label = None
if epe_idx == 0 and meta_idx == 0:
label = result.pretty_name()
rect = plt.barh([x_pos], [y_height],
label=label,
height=BAR_WIDTH,
color=epe_color,
left=bottom)
bottom += y_height
# Draw text in middle of bar
# plt.text(bottom - y_height / 2,
# x_pos,
# f"{y_sum * 100:0.1f}%",
# ha="center",
# va="center",
# color="white",
# fontsize=4)
# xlabels to be the metacatagories
plt.yticks(np.arange(len(METACATAGORIES)),
[METACATAGORY_TO_SHORTNAME[e] for e in METACATAGORIES.keys()],
rotation=0)
plt.xticks(np.linspace(0, 1, 5),
[f"{e}%" for e in np.linspace(0, 100, 5).astype(int)])
plt.xlabel("Endpoints Within Error Threshold")
legend = plt.legend(loc="lower left", fancybox=False)
# set the boarder of the legend artist to be transparent
# legend.get_frame().set_edgecolor('none')
plt.tight_layout()
# plt.legend()
def plot_metacatagory_epe_counts_v2(results: List[ResultInfo]):
for meta_idx, metacatagory in enumerate(sorted(METACATAGORIES.keys())):
for result_idx, result in enumerate(results):
# Each error bucket is a single bar in the stacked bar plot.
metacatagory_epe_counts = result.get_metacatagory_count_by_epe(
metacatagory)
x_pos_center = meta_idx + bar_offset(
len(results) - result_idx - 1, len(results), BAR_WIDTH)
y_height = metacatagory_epe_counts.sum(
) / metacatagory_epe_counts.sum()
for epe_idx, epe_count in enumerate(metacatagory_epe_counts[:2]):
x_offset = bar_offset(epe_idx, 2, BAR_WIDTH / 2)
y_height = metacatagory_epe_counts[:epe_idx + 1].sum(
) / metacatagory_epe_counts.sum()
epe_color = color2d(result_idx, epe_idx, len(results), 2)
label = None
if meta_idx == 0:
label = result.pretty_name()
if epe_idx == 0:
label += " (Strict)"
else:
label += " (Relaxed)"
# if meta_idx == 0 and epe_idx == 0:
# label = result.pretty_name()
plt.barh([x_pos_center + x_offset], [y_height],
label=label,
height=BAR_WIDTH / 2,
color=epe_color)
# xlabels to be the metacatagories
plt.yticks(np.arange(len(METACATAGORIES)),
[METACATAGORY_TO_SHORTNAME[e] for e in METACATAGORIES.keys()],
rotation=0)
plt.xticks(np.linspace(0, 1, 5),
[f"{e}%" for e in np.linspace(0, 100, 5).astype(int)])
plt.xlabel("Percentage of Endpoints Within Error Threshold")
legend = plt.legend(loc="lower left", fancybox=False)
# set the boarder of the legend artist to be transparent
# legend.get_frame().set_edgecolor('none')
plt.tight_layout()
# plt.legend()
def plot_metacatagory_epe_counts_v3(results: List[ResultInfo],
epe_bucket_idx: int):
for meta_idx, metacatagory in enumerate(sorted(METACATAGORIES.keys())):
for result_idx, result in enumerate(results):
# Each error bucket is a single bar in the stacked bar plot.
metacatagory_epe_counts = result.get_metacatagory_count_by_epe(
metacatagory)
x_pos = meta_idx + bar_offset(
len(results) - result_idx - 1, len(results), BAR_WIDTH)
y_height = metacatagory_epe_counts.sum(
) / metacatagory_epe_counts.sum()
y_height = metacatagory_epe_counts[:epe_bucket_idx + 1].sum(
) / metacatagory_epe_counts.sum()
epe_color = color(result_idx, len(results))
label = None
if meta_idx == 0:
label = result.pretty_name()
plt.barh([x_pos], [y_height],
label=label,
height=BAR_WIDTH,
color=epe_color)
# xlabels to be the metacatagories
plt.yticks(np.arange(len(METACATAGORIES)),
[METACATAGORY_TO_SHORTNAME[e] for e in METACATAGORIES.keys()],
rotation=0)
plt.xticks(np.linspace(0, 1, 5),
[f"{e}%" for e in np.linspace(0, 100, 5).astype(int)])
plt.xlabel("Endpoints Within Error Threshold")
legend = plt.legend(loc="lower left", fancybox=False)
# set the boarder of the legend artist to be transparent
# legend.get_frame().set_edgecolor('none')
plt.tight_layout()
# plt.legend()
def table_latency(results: List[ResultInfo]):
table = []
for result in results:
table_row = [
result.pretty_name(),
f"{result.get_latency():0.4f}",
]
table.append(table_row)
return table
def table_epe(results: List[ResultInfo], num_decimal_places : int = 3):
table_rows = []
for result in results: