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
| import numpy as np
indexxx = np.array([[8,9,4,7,5,6,3,2,1,0],[9,6,7,2,1,4,3,5,8,0],[7,9,5,3,1,2,4,6,8,0]]) good_index = np.array([1,3,5,7,9]) CMC = np.array([0,0,0,0,0,0,0,0,0,0]) mAP = 0.0
for i in indexxx: cmc = np.array([0,0,0,0,0,0,0,0,0,0]) index = i ngood = len(good_index) mask = np.in1d(index, good_index) rows_good = np.argwhere(mask==True) rows_good = rows_good.flatten() cmc[rows_good[0]:] = 1 print('cmc:',cmc) CMC += cmc
ap = 0.0 for i in range(ngood): d_recall = 1.0/ngood precision = (i+1)*1.0/(rows_good[i]+1) ap = ap + d_recall*precision print('ap:{:.2f}%:'.format(100*ap)) mAP += ap
CMC = CMC/3 mAP = mAP/3
print('top1:{:.2f}% top5:{:.2f}% mAP:{:.2f}%'.format(100*CMC[0],100*CMC[4],100*mAP))
cmc: [0 1 1 1 1 1 1 1 1 1] ap:54.54% cmc: [1 1 1 1 1 1 1 1 1 1] ap:69.26% cmc: [1 1 1 1 1 1 1 1 1 1] ap:100.00% top1:66.67% top5:100.00% mAP:74.60%
|