Skip to content

Commit 0a9e92e

Browse files
committed
mAP
1 parent 48f7b40 commit 0a9e92e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/test_net.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
import scipy.io as sio
44
import inspect
5+
import sklearn.metrics
56
from multiprocessing import Queue
67

78
# Theano & network
@@ -44,7 +45,9 @@ def test_net():
4445
num_batch = int(num_data / batch_size)
4546

4647
# 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
4851
for thresh in cfg.TEST.VOXEL_THRESH:
4952
results[str(thresh)] = np.zeros((num_batch, batch_size, 5))
5053

@@ -55,16 +58,27 @@ def test_net():
5558
break
5659

5760
pred, loss, activations = solver.test_output(batch_img, batch_voxel)
58-
print('%d/%d, cost is: %f' % (batch_idx, num_batch, loss))
5961

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):
6265
r = evaluate_voxel_prediction(pred[j, ...], batch_voxel[j, ...], thresh)
6366
results[str(thresh)][batch_idx, j, :] = r
6467

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+
6574
# record result for the batch
6675
results['cost'][batch_idx] = float(loss)
6776
batch_idx += 1
6877

78+
print('%d/%d, costs: %f, mAP: %f' %
79+
(batch_idx, num_batch, loss, np.mean(results['mAP'][batch_idx])))
80+
6981
print('Total loss: %f' % np.mean(results['cost']))
82+
print('Total mAP: %f' % np.mean(results['mAP']))
83+
7084
sio.savemat(result_fn, results)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Theano>=0.8
33
EasyDict
44
Pillow
55
pyyaml
6+
sklearn

0 commit comments

Comments
 (0)