-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevaluation_utils.py
1087 lines (907 loc) · 49.8 KB
/
evaluation_utils.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
# Copyright (c) Gorilla Lab, SCUT.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Modified based on https://github.com/hughw19/NOCS_CVPR2019."""
import os
import sys
import numpy as np
import glob
import math
import _pickle as cPickle
from tqdm import tqdm
import cv2
import matplotlib.pyplot as plt
from ctypes import *
import math
def trim_zeros(x):
"""It's common to have tensors larger than the available data and
pad with zeros. This function removes rows that are all zeros.
x: [rows, columns].
"""
pre_shape = x.shape
assert len(x.shape) == 2, x.shape
new_x = x[~np.all(x == 0, axis=1)]
post_shape = new_x.shape
assert pre_shape[0] == post_shape[0]
assert pre_shape[1] == post_shape[1]
return new_x
def get_3d_bbox(scale, shift=0):
"""
Input:
scale: [3] or scalar
shift: [3] or scalar
Return
bbox_3d: [3, N]
"""
if hasattr(scale, "__iter__"):
bbox_3d = np.array([[scale[0] / 2, +scale[1] / 2, scale[2] / 2],
[scale[0] / 2, +scale[1] / 2, -scale[2] / 2],
[-scale[0] / 2, +scale[1] / 2, scale[2] / 2],
[-scale[0] / 2, +scale[1] / 2, -scale[2] / 2],
[+scale[0] / 2, -scale[1] / 2, scale[2] / 2],
[+scale[0] / 2, -scale[1] / 2, -scale[2] / 2],
[-scale[0] / 2, -scale[1] / 2, scale[2] / 2],
[-scale[0] / 2, -scale[1] / 2, -scale[2] / 2]]) + shift
else:
bbox_3d = np.array([[scale / 2, +scale / 2, scale / 2],
[scale / 2, +scale / 2, -scale / 2],
[-scale / 2, +scale / 2, scale / 2],
[-scale / 2, +scale / 2, -scale / 2],
[+scale / 2, -scale / 2, scale / 2],
[+scale / 2, -scale / 2, -scale / 2],
[-scale / 2, -scale / 2, scale / 2],
[-scale / 2, -scale / 2, -scale / 2]]) + shift
bbox_3d = bbox_3d.transpose()
return bbox_3d
def transform_coordinates_3d(coordinates, RT):
"""
Input:
coordinates: [3, N]
RT: [4, 4]
Return
new_coordinates: [3, N]
"""
assert coordinates.shape[0] == 3
coordinates = np.vstack([coordinates, np.ones(
(1, coordinates.shape[1]), dtype=np.float32)])
new_coordinates = RT @ coordinates
new_coordinates = new_coordinates[:3, :]/new_coordinates[3, :]
return new_coordinates
def compute_ap_from_matches_scores(pred_match, pred_scores, gt_match):
# sort the scores from high to low
# print(pred_match.shape, pred_scores.shape)
assert pred_match.shape[0] == pred_scores.shape[0]
score_indices = np.argsort(pred_scores)[::-1]
pred_scores = pred_scores[score_indices]
pred_match = pred_match[score_indices]
precisions = np.cumsum(pred_match > -1) / (np.arange(len(pred_match)) + 1)
recalls = np.cumsum(pred_match > -1).astype(np.float32) / len(gt_match)
# Pad with start and end values to simplify the math
precisions = np.concatenate([[0], precisions, [0]])
recalls = np.concatenate([[0], recalls, [1]])
# Ensure precision values decrease but don't increase. This way, the
# precision value at each recall threshold is the maximum it can be
# for all following recall thresholds, as specified by the VOC paper.
for i in range(len(precisions) - 2, -1, -1):
precisions[i] = np.maximum(precisions[i], precisions[i + 1])
# Compute mean AP over recall range
indices = np.where(recalls[:-1] != recalls[1:])[0] + 1
ap = np.sum((recalls[indices] - recalls[indices - 1])
* precisions[indices])
return ap
def compute_3d_iou_new(RT_1, RT_2, scales_1, scales_2, handle_visibility, class_name_1, class_name_2):
'''Computes IoU overlaps between two 3d bboxes.
bbox_3d_1, bbox_3d_1: [3, 8]
'''
# flatten masks
def asymmetric_3d_iou(RT_1, RT_2, scales_1, scales_2):
noc_cube_1 = get_3d_bbox(scales_1, 0)
bbox_3d_1 = transform_coordinates_3d(noc_cube_1, RT_1)
noc_cube_2 = get_3d_bbox(scales_2, 0)
bbox_3d_2 = transform_coordinates_3d(noc_cube_2, RT_2)
bbox_1_max = np.amax(bbox_3d_1, axis=1)
bbox_1_min = np.amin(bbox_3d_1, axis=1)
bbox_2_max = np.amax(bbox_3d_2, axis=1)
bbox_2_min = np.amin(bbox_3d_2, axis=1)
overlap_min = np.maximum(bbox_1_min, bbox_2_min)
overlap_max = np.minimum(bbox_1_max, bbox_2_max)
# intersections and union
if np.amin(overlap_max - overlap_min) < 0:
intersections = 0
else:
intersections = np.prod(overlap_max - overlap_min)
union = np.prod(bbox_1_max - bbox_1_min) + \
np.prod(bbox_2_max - bbox_2_min) - intersections
overlaps = intersections / union
return overlaps
if RT_1 is None or RT_2 is None:
return -1
symmetry_flag = False
if (class_name_1 in ['bottle', 'bowl', 'can'] and class_name_1 == class_name_2) or (class_name_1 == 'mug' and class_name_1 == class_name_2 and handle_visibility == 0):
# print('*'*10)
noc_cube_1 = get_3d_bbox(scales_1, 0)
noc_cube_2 = get_3d_bbox(scales_2, 0)
bbox_3d_2 = transform_coordinates_3d(noc_cube_2, RT_2)
def y_rotation_matrix(theta):
return np.array([[np.cos(theta), 0, np.sin(theta), 0],
[0, 1, 0, 0],
[-np.sin(theta), 0, np.cos(theta), 0],
[0, 0, 0, 1]])
n = 20
max_iou = 0
for i in range(n):
rotated_RT_1 = RT_1@y_rotation_matrix(2*math.pi*i/float(n))
max_iou = max(max_iou,
asymmetric_3d_iou(rotated_RT_1, RT_2, scales_1, scales_2))
else:
max_iou = asymmetric_3d_iou(RT_1, RT_2, scales_1, scales_2)
return max_iou
def compute_combination_RT_degree_cm_symmetry(RT_1, RT_2, scale, class_id, handle_visibility, synset_names):
'''
:param RT_1: [4, 4]. homogeneous affine transformation
:param RT_2: [4, 4]. homogeneous affine transformation
:return: theta: angle difference of R in degree, shift: l2 difference of T in centimeter
synset_names = ['BG', # 0
'bottle', # 1
'bowl', # 2
'camera', # 3
'can', # 4
'cap', # 5
'phone', # 6
'monitor', # 7
'laptop', # 8
'mug' # 9
]
synset_names = ['BG', # 0
'bottle', # 1
'bowl', # 2
'camera', # 3
'can', # 4
'laptop', # 5
'mug' # 6
]
'''
# make sure the last row is [0, 0, 0, 1]
if RT_1 is None or RT_2 is None:
return -1
try:
assert np.array_equal(RT_1[3, :], RT_2[3, :])
assert np.array_equal(RT_1[3, :], np.array([0, 0, 0, 1]))
except AssertionError:
print(RT_1[3, :], RT_2[3, :])
exit()
R1 = RT_1[:3, :3] / np.cbrt(np.linalg.det(RT_1[:3, :3]))
T1 = RT_1[:3, 3]
R2 = RT_2[:3, :3] / np.cbrt(np.linalg.det(RT_2[:3, :3]))
T2 = RT_2[:3, 3]
# symmetric when rotating around y-axis
if synset_names[class_id] in ['bottle', 'can', 'bowl']:
y = np.array([0, 1, 0])
y1 = R1 @ y
y2 = R2 @ y
theta = np.arccos(
y1.dot(y2) / (np.linalg.norm(y1) * np.linalg.norm(y2)))
# symmetric when rotating around y-axis
elif synset_names[class_id] == 'mug' and handle_visibility == 0:
y = np.array([0, 1, 0])
y1 = R1 @ y
y2 = R2 @ y
theta = np.arccos(
y1.dot(y2) / (np.linalg.norm(y1) * np.linalg.norm(y2)))
elif synset_names[class_id] in ['phone', 'eggbox', 'glue']:
y_180_RT = np.diag([-1.0, 1.0, -1.0])
R = R1 @ R2.transpose()
R_rot = R1 @ y_180_RT @ R2.transpose()
theta = min(np.arccos((np.trace(R) - 1) / 2),
np.arccos((np.trace(R_rot) - 1) / 2))
else:
R = R1 @ R2.transpose()
theta = np.arccos(np.clip((np.trace(R) - 1) / 2, -1.0, 1.0))
theta *= 180 / np.pi
shift = np.linalg.norm(T1 - T2) / scale
result = np.array([theta, shift])
return result
def compute_combination_3d_matches(gt_class_ids, gt_RTs, gt_scales, gt_handle_visibility, synset_names,
pred_boxes, pred_class_ids, pred_scores, pred_RTs, pred_scales,
iou_3d_thresholds, degree_thesholds, shift_thesholds, score_threshold=0):
"""Finds matches between prediction and ground truth instances.
Returns:
gt_matches: 2-D array. For each GT box it has the index of the matched
predicted box.
pred_matches: 2-D array. For each predicted box, it has the index of
the matched ground truth box.
overlaps: [pred_boxes, gt_boxes] IoU overlaps.
"""
# Trim zero padding
# TODO: cleaner to do zero unpadding upstream
num_pred = len(pred_class_ids)
num_gt = len(gt_class_ids)
indices = np.zeros(0)
if num_pred:
pred_boxes = trim_zeros(pred_boxes).copy()
pred_scores = pred_scores[:pred_boxes.shape[0]].copy()
# Sort predictions by score from high to low
indices = np.argsort(pred_scores)[::-1]
pred_boxes = pred_boxes[indices].copy()
pred_class_ids = pred_class_ids[indices].copy()
pred_scores = pred_scores[indices].copy()
pred_scales = pred_scales[indices].copy()
pred_RTs = pred_RTs[indices].copy()
# Compute IoU overlaps [pred_bboxs gt_bboxs]
#overlaps = [[0 for j in range(num_gt)] for i in range(num_pred)]
overlaps = np.zeros((num_pred, num_gt), dtype=np.float32)
RT_overlaps = np.zeros((num_pred, num_gt, 2), dtype=np.float32)
for i in range(num_pred):
for j in range(num_gt):
# overlaps[i, j] = compute_3d_iou(pred_3d_bboxs[i], gt_3d_bboxs[j], gt_handle_visibility[j],
# synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
overlaps[i, j] = compute_3d_iou_new(pred_RTs[i], gt_RTs[j], pred_scales[i, :], gt_scales[j],
gt_handle_visibility[j], synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
RT_overlaps[i, j, :] = compute_combination_RT_degree_cm_symmetry(pred_RTs[i], gt_RTs[j], np.cbrt(
np.linalg.det(gt_RTs[j, :3, :3])), gt_class_ids[j], gt_handle_visibility[j], synset_names)
# Loop through predictions and find matching ground truth boxes
num_iou_3d_thres = len(iou_3d_thresholds)
num_degree_thes = len(degree_thesholds)
num_shift_thes = len(shift_thesholds)
pred_matches = -1 * \
np.ones([num_degree_thes, num_shift_thes, num_iou_3d_thres, num_pred])
gt_matches = -1 * \
np.ones([num_degree_thes, num_shift_thes, num_iou_3d_thres, num_gt])
for s, iou_thres in enumerate(iou_3d_thresholds):
for d, degree_thres in enumerate(degree_thesholds):
for t, shift_thres in enumerate(shift_thesholds):
for i in range(len(pred_boxes)):
# Find best matching ground truth box
# 1. Sort matches by score
sorted_ixs_by_iou = np.argsort(overlaps[i])[::-1]
# 2. Remove low scores
low_score_idx = np.where(
overlaps[i, sorted_ixs_by_iou] < score_threshold)[0]
if low_score_idx.size > 0:
sorted_ixs_by_iou = sorted_ixs_by_iou[:low_score_idx[0]]
# 3. Find the match
for j in sorted_ixs_by_iou:
if gt_matches[d, t, s, j] > -1:
continue
# If we reach IoU smaller than the threshold, end the loop
iou = overlaps[i, j]
r_error = RT_overlaps[i, j, 0]
t_error = RT_overlaps[i, j, 1]
if iou < iou_thres or r_error > degree_thres or t_error > shift_thres:
break
if not pred_class_ids[i] == gt_class_ids[j]:
continue
if iou >= iou_thres or r_error <= degree_thres or t_error <= shift_thres:
gt_matches[d, t, s, j] = i
pred_matches[d, t, s, i] = j
break
return gt_matches, pred_matches, indices
def compute_combination_mAP(final_results, synset_names, degree_thresholds=[5, 10, 15], shift_thresholds=[0.1, 0.2], iou_3d_thresholds=[0.1]):
num_classes = len(synset_names)
degree_thres_list = list(degree_thresholds) + [360]
num_degree_thres = len(degree_thres_list)
shift_thres_list = list(shift_thresholds) + [100]
num_shift_thres = len(shift_thres_list)
iou_thres_list = list(iou_3d_thresholds)
num_iou_thres = len(iou_thres_list)
aps = np.zeros((num_classes + 1, num_degree_thres,
num_shift_thres, num_iou_thres))
pred_matches_all = [np.zeros(
(num_degree_thres, num_shift_thres, num_iou_thres, 0)) for _ in range(num_classes)]
gt_matches_all = [np.zeros(
(num_degree_thres, num_shift_thres, num_iou_thres, 0)) for _ in range(num_classes)]
pred_scores_all = [np.zeros(
(num_degree_thres, num_shift_thres, num_iou_thres, 0)) for _ in range(num_classes)]
for progress, result in tqdm(enumerate(final_results)):
gt_class_ids = result['gt_class_ids'].astype(np.int32)
gt_RTs = np.array(result['gt_RTs'])
gt_scales = np.array(result['gt_scales'])
gt_handle_visibility = result['gt_handle_visibility']
pred_bboxes = np.array(result['pred_bboxes'])
pred_class_ids = result['pred_class_ids']
pred_scales = result['pred_scales']
pred_scores = result['pred_scores']
pred_RTs = np.array(result['pred_RTs'])
if len(gt_class_ids) == 0 and len(pred_class_ids) == 0:
continue
for cls_id in range(1, num_classes):
# get gt and predictions in this class
cls_gt_class_ids = gt_class_ids[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros(0)
cls_gt_scales = gt_scales[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros((0, 3))
cls_gt_RTs = gt_RTs[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros((0, 4, 4))
cls_pred_class_ids = pred_class_ids[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros(0)
cls_pred_bboxes = pred_bboxes[pred_class_ids == cls_id, :] if len(
pred_class_ids) else np.zeros((0, 4))
cls_pred_scores = pred_scores[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros(0)
cls_pred_RTs = pred_RTs[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros((0, 4, 4))
cls_pred_scales = pred_scales[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros((0, 3))
if synset_names[cls_id] != 'mug':
cls_gt_handle_visibility = np.ones_like(cls_gt_class_ids)
else:
cls_gt_handle_visibility = gt_handle_visibility[gt_class_ids == cls_id] if len(
gt_class_ids) else np.ones(0)
gt_match, pred_match, pred_indiced = compute_combination_3d_matches(cls_gt_class_ids, cls_gt_RTs, cls_gt_scales, cls_gt_handle_visibility, synset_names,
cls_pred_bboxes, cls_pred_class_ids, cls_pred_scores, cls_pred_RTs, cls_pred_scales,
iou_thres_list, degree_thres_list, shift_thres_list)
if len(pred_indiced):
cls_pred_class_ids = cls_pred_class_ids[pred_indiced]
cls_pred_RTs = cls_pred_RTs[pred_indiced]
cls_pred_scores = cls_pred_scores[pred_indiced]
cls_pred_bboxes = cls_pred_bboxes[pred_indiced]
pred_matches_all[cls_id] = np.concatenate(
(pred_matches_all[cls_id], pred_match), axis=-1)
cls_pred_scores_tile = np.tile(
cls_pred_scores, (num_degree_thres, num_shift_thres, num_iou_thres, 1))
pred_scores_all[cls_id] = np.concatenate(
(pred_scores_all[cls_id], cls_pred_scores_tile), axis=-1)
assert pred_matches_all[cls_id].shape[-1] == pred_scores_all[cls_id].shape[-1]
gt_matches_all[cls_id] = np.concatenate(
(gt_matches_all[cls_id], gt_match), axis=-1)
for cls_id in range(1, num_classes):
class_name = synset_names[cls_id]
for s, iou_thres in enumerate(iou_thres_list):
for d, degree_thres in enumerate(degree_thres_list):
for t, shift_thres in enumerate(shift_thres_list):
aps[cls_id, d, t, s] = compute_ap_from_matches_scores(pred_matches_all[cls_id][d, t, s, :],
pred_scores_all[cls_id][d,
t, s, :],
gt_matches_all[cls_id][d, t, s, :])
# for i in range(6):
# print(i+1)
# print('IoU75, 5 degree, 5% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(5), shift_thres_list.index(0.05), iou_thres_list.index(0.75)]*100))
# print('IoU75, 10 degree, 5% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(10), shift_thres_list.index(0.05), iou_thres_list.index(0.75)]*100))
# print('IoU75, 5 degree, 10% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(5), shift_thres_list.index(0.10), iou_thres_list.index(0.75)]*100))
# print('IoU50, 5 degree, 20% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(5), shift_thres_list.index(0.20), iou_thres_list.index(0.50)]*100))
# print('IoU50, 10 degree, 10% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(10), shift_thres_list.index(0.10), iou_thres_list.index(0.50)]*100))
# print('IoU50, 10 degree, 20% translation: {:.2f}'.format(aps[i+1, degree_thres_list.index(10), shift_thres_list.index(0.20), iou_thres_list.index(0.50)]*100))
# print('ALL:')
aps[-1, :, :, :] = np.mean(aps[1:-1, :, :, :], axis=0)
print('IoU75, 5 degree, 5% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(5), shift_thres_list.index(0.05), iou_thres_list.index(0.75)]*100))
print('IoU75, 10 degree, 5% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(10), shift_thres_list.index(0.05), iou_thres_list.index(0.75)]*100))
print('IoU75, 5 degree, 10% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(5), shift_thres_list.index(0.10), iou_thres_list.index(0.75)]*100))
print('IoU50, 5 degree, 20% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(5), shift_thres_list.index(0.20), iou_thres_list.index(0.50)]*100))
print('IoU50, 10 degree, 10% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(10), shift_thres_list.index(0.10), iou_thres_list.index(0.50)]*100))
print('IoU50, 10 degree, 20% translation: {:.2f}'.format(
aps[-1, degree_thres_list.index(10), shift_thres_list.index(0.20), iou_thres_list.index(0.50)]*100))
return aps
def compute_3d_matches_for_each_gt(gt_class_ids, gt_RTs, gt_scales, gt_handle_visibility, synset_names,
pred_boxes, pred_class_ids, pred_scores, pred_RTs, pred_scales):
# Trim zero padding
# TODO: cleaner to do zero unpadding upstream
num_pred = len(pred_class_ids)
num_gt = len(gt_class_ids)
indices = np.zeros(0)
if num_pred:
pred_boxes = trim_zeros(pred_boxes).copy()
pred_scores = pred_scores[:pred_boxes.shape[0]].copy()
# Sort predictions by score from high to low
indices = np.argsort(pred_scores)[::-1]
pred_boxes = pred_boxes[indices].copy()
pred_class_ids = pred_class_ids[indices].copy()
pred_scores = pred_scores[indices].copy()
pred_scales = pred_scales[indices].copy()
pred_RTs = pred_RTs[indices].copy()
overlaps = np.zeros((num_gt, num_pred), dtype=np.float32)
# print("num_gt:", num_gt, "num_pred:", num_pred)
for j in range(num_gt):
for i in range(num_pred):
# overlaps[i, j] = compute_3d_iou(pred_3d_bboxs[i], gt_3d_bboxs[j], gt_handle_visibility[j],
# synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
overlaps[j, i] = compute_3d_iou_new(pred_RTs[i], gt_RTs[j], pred_scales[i, :], gt_scales[j],
gt_handle_visibility[j], synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
# num_iou_3d_thres = len(iou_3d_thresholds)
pred_matches = -1 * np.ones([num_pred, ])
gt_matches = -1 * np.ones([num_gt,], dtype=np.int32)
for i in range(num_gt):
sorted_ixs = np.argsort(overlaps[i])[::-1]
for j in sorted_ixs:
if pred_matches[j] > -1:
continue
if not pred_class_ids[j] == gt_class_ids[i]:
continue
gt_matches[i] = j
pred_matches[j] = i
break
return gt_matches, indices
def compute_3d_matches(gt_class_ids, gt_RTs, gt_scales, gt_handle_visibility, synset_names,
pred_boxes, pred_class_ids, pred_scores, pred_RTs, pred_scales,
iou_3d_thresholds, score_threshold=0):
"""Finds matches between prediction and ground truth instances.
Returns:
gt_matches: 2-D array. For each GT box it has the index of the matched
predicted box.
pred_matches: 2-D array. For each predicted box, it has the index of
the matched ground truth box.
overlaps: [pred_boxes, gt_boxes] IoU overlaps.
"""
# Trim zero padding
# TODO: cleaner to do zero unpadding upstream
num_pred = len(pred_class_ids)
num_gt = len(gt_class_ids)
indices = np.zeros(0)
if num_pred:
pred_boxes = trim_zeros(pred_boxes).copy()
pred_scores = pred_scores[:pred_boxes.shape[0]].copy()
# Sort predictions by score from high to low
indices = np.argsort(pred_scores)[::-1]
pred_boxes = pred_boxes[indices].copy()
pred_class_ids = pred_class_ids[indices].copy()
pred_scores = pred_scores[indices].copy()
pred_scales = pred_scales[indices].copy()
pred_RTs = pred_RTs[indices].copy()
# Compute IoU overlaps [pred_bboxs gt_bboxs]
#overlaps = [[0 for j in range(num_gt)] for i in range(num_pred)]
overlaps = np.zeros((num_pred, num_gt), dtype=np.float32)
for i in range(num_pred):
for j in range(num_gt):
# overlaps[i, j] = compute_3d_iou(pred_3d_bboxs[i], gt_3d_bboxs[j], gt_handle_visibility[j],
# synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
overlaps[i, j] = compute_3d_iou_new(pred_RTs[i], gt_RTs[j], pred_scales[i, :], gt_scales[j],
gt_handle_visibility[j], synset_names[pred_class_ids[i]], synset_names[gt_class_ids[j]])
# Loop through predictions and find matching ground truth boxes
num_iou_3d_thres = len(iou_3d_thresholds)
pred_matches = -1 * np.ones([num_iou_3d_thres, num_pred])
gt_matches = -1 * np.ones([num_iou_3d_thres, num_gt])
for s, iou_thres in enumerate(iou_3d_thresholds):
for i in range(len(pred_boxes)):
# Find best matching ground truth box
# 1. Sort matches by score
sorted_ixs = np.argsort(overlaps[i])[::-1]
# 2. Remove low scores
low_score_idx = np.where(
overlaps[i, sorted_ixs] < score_threshold)[0]
if low_score_idx.size > 0:
sorted_ixs = sorted_ixs[:low_score_idx[0]]
# 3. Find the match
for j in sorted_ixs:
# If ground truth box is already matched, go to next one
#print('gt_match: ', gt_match[j])
if gt_matches[s, j] > -1:
continue
# If we reach IoU smaller than the threshold, end the loop
iou = overlaps[i, j]
#print('iou: ', iou)
if iou < iou_thres:
break
# Do we have a match?
if not pred_class_ids[i] == gt_class_ids[j]:
continue
if iou > iou_thres:
gt_matches[s, j] = i
pred_matches[s, i] = j
break
return gt_matches, pred_matches, overlaps, indices
def compute_RT_degree_cm_symmetry(RT_1, RT_2, class_id, handle_visibility, synset_names):
'''
:param RT_1: [4, 4]. homogeneous affine transformation
:param RT_2: [4, 4]. homogeneous affine transformation
:return: theta: angle difference of R in degree, shift: l2 difference of T in centimeter
synset_names = ['BG', # 0
'bottle', # 1
'bowl', # 2
'camera', # 3
'can', # 4
'cap', # 5
'phone', # 6
'monitor', # 7
'laptop', # 8
'mug' # 9
]
synset_names = ['BG', # 0
'bottle', # 1
'bowl', # 2
'camera', # 3
'can', # 4
'laptop', # 5
'mug' # 6
]
'''
# make sure the last row is [0, 0, 0, 1]
if RT_1 is None or RT_2 is None:
return -1
try:
assert np.array_equal(RT_1[3, :], RT_2[3, :])
assert np.array_equal(RT_1[3, :], np.array([0, 0, 0, 1]))
except AssertionError:
print(RT_1[3, :], RT_2[3, :])
exit()
R1 = RT_1[:3, :3] / np.cbrt(np.linalg.det(RT_1[:3, :3]))
T1 = RT_1[:3, 3]
R2 = RT_2[:3, :3] / np.cbrt(np.linalg.det(RT_2[:3, :3]))
T2 = RT_2[:3, 3]
# symmetric when rotating around y-axis
if synset_names[class_id] in ['bottle', 'can', 'bowl']:
y = np.array([0, 1, 0])
y1 = R1 @ y
y2 = R2 @ y
theta = np.arccos(
y1.dot(y2) / (np.linalg.norm(y1) * np.linalg.norm(y2)))
# symmetric when rotating around y-axis
elif synset_names[class_id] == 'mug' and handle_visibility == 0:
y = np.array([0, 1, 0])
y1 = R1 @ y
y2 = R2 @ y
theta = np.arccos(
y1.dot(y2) / (np.linalg.norm(y1) * np.linalg.norm(y2)))
elif synset_names[class_id] in ['phone', 'eggbox', 'glue']:
y_180_RT = np.diag([-1.0, 1.0, -1.0])
R = R1 @ R2.transpose()
R_rot = R1 @ y_180_RT @ R2.transpose()
theta = min(np.arccos((np.trace(R) - 1) / 2),
np.arccos((np.trace(R_rot) - 1) / 2))
else:
R = R1 @ R2.transpose()
theta = np.arccos(np.clip((np.trace(R) - 1) / 2, -1.0, 1.0))
theta *= 180 / np.pi
shift = np.linalg.norm(T1 - T2) * 100
result = np.array([theta, shift])
return result
def compute_RT_overlaps(gt_class_ids, gt_RTs, gt_handle_visibility,
pred_class_ids, pred_RTs,
synset_names):
"""Finds overlaps between prediction and ground truth instances.
Returns:
overlaps: [pred_boxes, gt_boxes] IoU overlaps.
"""
# print('num of gt instances: {}, num of pred instances: {}'.format(len(gt_class_ids), len(gt_class_ids)))
num_pred = len(pred_class_ids)
num_gt = len(gt_class_ids)
# Compute IoU overlaps [pred_bboxs gt_bboxs]
#overlaps = [[0 for j in range(num_gt)] for i in range(num_pred)]
overlaps = np.zeros((num_pred, num_gt, 2))
for i in range(num_pred):
for j in range(num_gt):
overlaps[i, j, :] = compute_RT_degree_cm_symmetry(pred_RTs[i],
gt_RTs[j],
gt_class_ids[j],
gt_handle_visibility[j],
synset_names)
return overlaps
def compute_match_from_degree_cm(overlaps, pred_class_ids, gt_class_ids, degree_thres_list, shift_thres_list):
num_degree_thres = len(degree_thres_list)
num_shift_thres = len(shift_thres_list)
num_pred = len(pred_class_ids)
num_gt = len(gt_class_ids)
pred_matches = -1 * np.ones((num_degree_thres, num_shift_thres, num_pred))
gt_matches = -1 * np.ones((num_degree_thres, num_shift_thres, num_gt))
if num_pred == 0 or num_gt == 0:
return gt_matches, pred_matches
assert num_pred == overlaps.shape[0]
assert num_gt == overlaps.shape[1]
assert overlaps.shape[2] == 2
for d, degree_thres in enumerate(degree_thres_list):
for s, shift_thres in enumerate(shift_thres_list):
for i in range(num_pred):
# Find best matching ground truth box
# 1. Sort matches by scores from low to high
sum_degree_shift = np.sum(overlaps[i, :, :], axis=-1)
sorted_ixs = np.argsort(sum_degree_shift)
# 2. Remove low scores
# low_score_idx = np.where(sum_degree_shift >= 100)[0]
# if low_score_idx.size > 0:
# sorted_ixs = sorted_ixs[:low_score_idx[0]]
# 3. Find the match
for j in sorted_ixs:
# If ground truth box is already matched, go to next one
#print(j, len(gt_match), len(pred_class_ids), len(gt_class_ids))
if gt_matches[d, s, j] > -1 or pred_class_ids[i] != gt_class_ids[j]:
continue
# If we reach IoU smaller than the threshold, end the loop
if overlaps[i, j, 0] > degree_thres or overlaps[i, j, 1] > shift_thres:
continue
gt_matches[d, s, j] = i
pred_matches[d, s, i] = j
break
return gt_matches, pred_matches
def compute_independent_mAP(final_results, synset_names, degree_thresholds=[360], shift_thresholds=[100], iou_3d_thresholds=[0.1], iou_pose_thres=0.1, use_matches_for_pose=True, logger=None, plot_figure=True, log_dir=None):
num_classes = len(synset_names)
degree_thres_list = list(degree_thresholds) + [360]
num_degree_thres = len(degree_thres_list)
shift_thres_list = list(shift_thresholds) + [100]
num_shift_thres = len(shift_thres_list)
iou_thres_list = list(iou_3d_thresholds)
num_iou_thres = len(iou_thres_list)
if use_matches_for_pose:
assert iou_pose_thres in iou_thres_list
iou_3d_aps = np.zeros((num_classes + 1, num_iou_thres))
iou_pred_matches_all = [np.zeros((num_iou_thres, 0))
for _ in range(num_classes)]
iou_pred_scores_all = [np.zeros((num_iou_thres, 0))
for _ in range(num_classes)]
iou_gt_matches_all = [np.zeros((num_iou_thres, 0))
for _ in range(num_classes)]
pose_aps = np.zeros((num_classes + 1, num_degree_thres, num_shift_thres))
pose_pred_matches_all = [
np.zeros((num_degree_thres, num_shift_thres, 0)) for _ in range(num_classes)]
pose_gt_matches_all = [
np.zeros((num_degree_thres, num_shift_thres, 0)) for _ in range(num_classes)]
pose_pred_scores_all = [
np.zeros((num_degree_thres, num_shift_thres, 0)) for _ in range(num_classes)]
# loop over results to gather pred matches and gt matches for iou and pose metrics
progress = 0
for progress, result in tqdm(enumerate(final_results)):
gt_class_ids = result['gt_class_ids'].astype(np.int32)
gt_RTs = np.array(result['gt_RTs'])
gt_scales = np.array(result['gt_scales'])
gt_handle_visibility = result['gt_handle_visibility']
pred_bboxes = np.array(result['pred_bboxes'])
pred_class_ids = result['pred_class_ids']
pred_scales = result['pred_scales']
pred_scores = result['pred_scores']
pred_RTs = np.array(result['pred_RTs'])
if len(gt_class_ids) == 0 and len(pred_class_ids) == 0:
continue
for cls_id in range(1, num_classes):
# get gt and predictions in this class
cls_gt_class_ids = gt_class_ids[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros(0)
cls_gt_scales = gt_scales[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros((0, 3))
cls_gt_RTs = gt_RTs[gt_class_ids == cls_id] if len(
gt_class_ids) else np.zeros((0, 4, 4))
# ipdb.set_trace()
cls_pred_class_ids = pred_class_ids[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros(0)
cls_pred_bboxes = pred_bboxes[pred_class_ids == cls_id, :] if len(
pred_class_ids) else np.zeros((0, 4))
cls_pred_scores = pred_scores[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros(0)
cls_pred_RTs = pred_RTs[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros((0, 4, 4))
cls_pred_scales = pred_scales[pred_class_ids == cls_id] if len(
pred_class_ids) else np.zeros((0, 3))
# calculate the overlap between each gt instance and pred instance
if synset_names[cls_id] != 'mug':
cls_gt_handle_visibility = np.ones_like(cls_gt_class_ids)
else:
cls_gt_handle_visibility = gt_handle_visibility[gt_class_ids == cls_id] if len(
gt_class_ids) else np.ones(0)
iou_cls_gt_match, iou_cls_pred_match, _, iou_pred_indices = compute_3d_matches(cls_gt_class_ids, cls_gt_RTs, cls_gt_scales, cls_gt_handle_visibility, synset_names,
cls_pred_bboxes, cls_pred_class_ids, cls_pred_scores, cls_pred_RTs, cls_pred_scales,
iou_thres_list)
if len(iou_pred_indices):
cls_pred_class_ids = cls_pred_class_ids[iou_pred_indices]
cls_pred_RTs = cls_pred_RTs[iou_pred_indices]
cls_pred_scores = cls_pred_scores[iou_pred_indices]
cls_pred_bboxes = cls_pred_bboxes[iou_pred_indices]
# print("iou_pred_matches_all shape:", iou_pred_matches_all[cls_id].shape, "iou_cls_pred_match shape:", iou_cls_pred_match.shape)
# assert False
iou_pred_matches_all[cls_id] = np.concatenate(
(iou_pred_matches_all[cls_id], iou_cls_pred_match), axis=-1)
cls_pred_scores_tile = np.tile(cls_pred_scores, (num_iou_thres, 1))
iou_pred_scores_all[cls_id] = np.concatenate(
(iou_pred_scores_all[cls_id], cls_pred_scores_tile), axis=-1)
assert iou_pred_matches_all[cls_id].shape[1] == iou_pred_scores_all[cls_id].shape[1]
iou_gt_matches_all[cls_id] = np.concatenate(
(iou_gt_matches_all[cls_id], iou_cls_gt_match), axis=-1)
if use_matches_for_pose:
thres_ind = list(iou_thres_list).index(iou_pose_thres)
iou_thres_pred_match = iou_cls_pred_match[thres_ind, :]
cls_pred_class_ids = cls_pred_class_ids[iou_thres_pred_match > -1] if len(
iou_thres_pred_match) > 0 else np.zeros(0)
cls_pred_RTs = cls_pred_RTs[iou_thres_pred_match > -1] if len(
iou_thres_pred_match) > 0 else np.zeros((0, 4, 4))
cls_pred_scores = cls_pred_scores[iou_thres_pred_match > -1] if len(
iou_thres_pred_match) > 0 else np.zeros(0)
cls_pred_bboxes = cls_pred_bboxes[iou_thres_pred_match > -1] if len(
iou_thres_pred_match) > 0 else np.zeros((0, 4))
iou_thres_gt_match = iou_cls_gt_match[thres_ind, :]
cls_gt_class_ids = cls_gt_class_ids[iou_thres_gt_match > -1] if len(
iou_thres_gt_match) > 0 else np.zeros(0)
cls_gt_RTs = cls_gt_RTs[iou_thres_gt_match > -1] if len(
iou_thres_gt_match) > 0 else np.zeros((0, 4, 4))
cls_gt_handle_visibility = cls_gt_handle_visibility[iou_thres_gt_match > -1] if len(
iou_thres_gt_match) > 0 else np.zeros(0)
RT_overlaps = compute_RT_overlaps(cls_gt_class_ids, cls_gt_RTs, cls_gt_handle_visibility,
cls_pred_class_ids, cls_pred_RTs,
synset_names)
pose_cls_gt_match, pose_cls_pred_match = compute_match_from_degree_cm(RT_overlaps,
cls_pred_class_ids,
cls_gt_class_ids,
degree_thres_list,
shift_thres_list)
pose_pred_matches_all[cls_id] = np.concatenate(
(pose_pred_matches_all[cls_id], pose_cls_pred_match), axis=-1)
cls_pred_scores_tile = np.tile(
cls_pred_scores, (num_degree_thres, num_shift_thres, 1))
pose_pred_scores_all[cls_id] = np.concatenate(
(pose_pred_scores_all[cls_id], cls_pred_scores_tile), axis=-1)
assert pose_pred_scores_all[cls_id].shape[2] == pose_pred_matches_all[cls_id].shape[2], '{} vs. {}'.format(
pose_pred_scores_all[cls_id].shape, pose_pred_matches_all[cls_id].shape)
pose_gt_matches_all[cls_id] = np.concatenate(
(pose_gt_matches_all[cls_id], pose_cls_gt_match), axis=-1)
# draw iou 3d AP vs. iou thresholds
fig_iou = plt.figure(figsize=(30,10))
# ax_iou = plt.subplot(111)
ax_iou = plt.subplot(131)
plt.ylabel('AP')
plt.ylim((0, 1))
plt.tick_params(labelsize=20)
plt.xlabel('3D IoU thresholds', fontsize=24)
iou_dict = {}
iou_dict['thres_list'] = iou_thres_list
for cls_id in range(1, num_classes):
class_name = synset_names[cls_id]
for s, iou_thres in enumerate(iou_thres_list):
iou_3d_aps[cls_id, s] = compute_ap_from_matches_scores(iou_pred_matches_all[cls_id][s, :],
iou_pred_scores_all[cls_id][s, :],
iou_gt_matches_all[cls_id][s, :])
ax_iou.plot(iou_thres_list, iou_3d_aps[cls_id, :], label=class_name)
iou_3d_aps[-1, :] = np.mean(iou_3d_aps[1:-1, :], axis=0)
ax_iou.plot(iou_thres_list, iou_3d_aps[-1, :], label='mean')
iou_dict['aps'] = iou_3d_aps
for i, degree_thres in enumerate(degree_thres_list):
for j, shift_thres in enumerate(shift_thres_list):
for cls_id in range(1, num_classes):
cls_pose_pred_matches_all = pose_pred_matches_all[cls_id][i, j, :]
cls_pose_gt_matches_all = pose_gt_matches_all[cls_id][i, j, :]
cls_pose_pred_scores_all = pose_pred_scores_all[cls_id][i, j, :]
pose_aps[cls_id, i, j] = compute_ap_from_matches_scores(cls_pose_pred_matches_all,
cls_pose_pred_scores_all,
cls_pose_gt_matches_all)
pose_aps[-1, i, j] = np.mean(pose_aps[1:-1, i, j])
ax_trans = plt.subplot(132)
plt.ylim((0, 1))
plt.tick_params(labelsize=20)
plt.xlabel('Rotation/degree', fontsize=24)
for cls_id in range(1, num_classes):
class_name = synset_names[cls_id]
# print(class_name)
ax_trans.plot(
degree_thres_list[:-1], pose_aps[cls_id, :-1, -1], label=class_name)
ax_trans.plot(degree_thres_list[:-1], pose_aps[-1, :-1, -1], label='mean')
# pose_dict['aps'] = pose_aps
ax_rot = plt.subplot(133)
plt.ylim((0, 1))
plt.tick_params(labelsize=20)
plt.xlabel('translation/cm', fontsize=24)
for cls_id in range(1, num_classes):
class_name = synset_names[cls_id]
# print(class_name)
ax_rot.plot(shift_thres_list[:-1],
pose_aps[cls_id, -1, :-1], label=class_name)
ax_rot.plot(shift_thres_list[:-1], pose_aps[-1, -1, :-1], label='mean')
plt.legend(loc='lower right')
plot_save_path = os.path.join(log_dir, 'visual')
if not os.path.isdir(plot_save_path):
os.mkdir(plot_save_path)
output_path = os.path.join(
plot_save_path, 'mAP_{}-{}cm.png'.format(shift_thres_list[0], shift_thres_list[-2]))
ax_rot.legend()
if plot_figure:
fig_iou.savefig(output_path)
plt.close(fig_iou)
if logger is not None:
logger.warning('3D IoU at 25: {:.1f}'.format(
iou_3d_aps[-1, iou_thres_list.index(0.25)] * 100))
logger.warning('3D IoU at 50: {:.1f}'.format(
iou_3d_aps[-1, iou_thres_list.index(0.5)] * 100))
logger.warning('3D IoU at 75: {:.1f}'.format(
iou_3d_aps[-1, iou_thres_list.index(0.75)] * 100))
logger.warning('5 degree, 2cm: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(5), shift_thres_list.index(2)] * 100))
logger.warning('5 degree, 5cm: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(5), shift_thres_list.index(5)] * 100))
logger.warning('10 degree, 2cm: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(10), shift_thres_list.index(2)] * 100))
logger.warning('10 degree, 5cm: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(10), shift_thres_list.index(5)] * 100))
logger.warning('10 degree, 10cm: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(10), shift_thres_list.index(10)] * 100))
logger.warning('10 degree: {:.1f}'.format(
pose_aps[-1, degree_thres_list.index(10), -1] * 100))
logger.warning('10 cm: {:.1f}'.format(
pose_aps[-1, -1, shift_thres_list.index(10)] * 100))
# print per class iou
logger.warning('####### Per Class result ###################')
for idx in range(1, len(synset_names)):
logger.warning('category {}'.format(synset_names[idx]))
logger.warning('mAP:')
logger.warning('3D IoU at 25: {:.1f}'.format(iou_3d_aps[idx, iou_thres_list.index(0.25)] * 100))
logger.warning('3D IoU at 50: {:.1f}'.format(iou_3d_aps[idx, iou_thres_list.index(0.5)] * 100))
logger.warning('3D IoU at 75: {:.1f}'.format(iou_3d_aps[idx, iou_thres_list.index(0.75)] * 100))
logger.warning('5 degree, 2cm: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(5), shift_thres_list.index(2)] * 100))
logger.warning('5 degree, 5cm: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(5), shift_thres_list.index(5)] * 100))
logger.warning('10 degree, 2cm: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(10), shift_thres_list.index(2)] * 100))
logger.warning('10 degree, 5cm: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(10), shift_thres_list.index(5)] * 100))
logger.warning('10 degree, 10cm: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(10), shift_thres_list.index(10)] * 100))
logger.warning('10 degree: {:.1f}'.format(pose_aps[idx, degree_thres_list.index(10), -1] * 100))
logger.warning('10cm: {:.1f}'.format(pose_aps[idx, -1, shift_thres_list.index(10)] * 100))
# else:
# print('3D IoU at 25: {:.1f}'.format(
# iou_3d_aps[-1, iou_thres_list.index(0.25)] * 100))
# print('3D IoU at 50: {:.1f}'.format(
# iou_3d_aps[-1, iou_thres_list.index(0.5)] * 100))
# print('3D IoU at 75: {:.1f}'.format(
# iou_3d_aps[-1, iou_thres_list.index(0.75)] * 100))
# print('5 degree, 2cm: {:.1f}'.format(