2
2
import numpy as np
3
3
import scipy .io as sio
4
4
import inspect
5
+ import sklearn .metrics
5
6
from multiprocessing import Queue
6
7
7
8
# Theano & network
@@ -44,7 +45,9 @@ def test_net():
44
45
num_batch = int (num_data / batch_size )
45
46
46
47
# prepare result container
47
- results = {'cost' : np .zeros (num_batch )}
48
+ results = {'cost' : np .zeros (num_batch ),
49
+ 'mAP' : np .zeros ((num_batch , batch_size ))}
50
+ # Save results for various thresholds
48
51
for thresh in cfg .TEST .VOXEL_THRESH :
49
52
results [str (thresh )] = np .zeros ((num_batch , batch_size , 5 ))
50
53
@@ -55,16 +58,27 @@ def test_net():
55
58
break
56
59
57
60
pred , loss , activations = solver .test_output (batch_img , batch_voxel )
58
- print ('%d/%d, cost is: %f' % (batch_idx , num_batch , loss ))
59
61
60
- for i , thresh in enumerate (cfg .TEST .VOXEL_THRESH ):
61
- for j in range (batch_size ):
62
+ for j in range (batch_size ):
63
+ # Save IoU per thresh
64
+ for i , thresh in enumerate (cfg .TEST .VOXEL_THRESH ):
62
65
r = evaluate_voxel_prediction (pred [j , ...], batch_voxel [j , ...], thresh )
63
66
results [str (thresh )][batch_idx , j , :] = r
64
67
68
+ # Compute AP
69
+ precision = sklearn .metrics .average_precision_score (
70
+ batch_voxel [j , :, 1 ].flatten (), pred [j , :, 1 ].flatten ())
71
+
72
+ results ['mAP' ][batch_idx , j ] = precision
73
+
65
74
# record result for the batch
66
75
results ['cost' ][batch_idx ] = float (loss )
67
76
batch_idx += 1
68
77
78
+ print ('%d/%d, costs: %f, mAP: %f' %
79
+ (batch_idx , num_batch , loss , np .mean (results ['mAP' ][batch_idx ])))
80
+
69
81
print ('Total loss: %f' % np .mean (results ['cost' ]))
82
+ print ('Total mAP: %f' % np .mean (results ['mAP' ]))
83
+
70
84
sio .savemat (result_fn , results )
0 commit comments