forked from coxlab/edn-cvpr2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation.py
37 lines (31 loc) · 1.12 KB
/
evaluation.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
import numpy as np
def evaluate_sal_map(salMap, fixMap):
"""Computes AUC for given saliency map 'salMap' and given
fixation map 'fixMap'"""
fixMap = (fixMap>200).astype(int)
salShape = salMap.shape
fixShape = fixMap.shape
predicted = salMap.reshape(salShape[0]*salShape[1], -1,
order='F').flatten()
actual = fixMap.reshape(fixShape[0]*fixShape[1], -1,
order='F').flatten()
labelset = np.arange(2)
auc = area_under_curve(predicted, actual, labelset)
return auc
def area_under_curve(predicted, actual, labelset):
tp, fp = roc_curve(predicted, actual, np.max(labelset))
auc = auc_from_roc(tp, fp)
return auc
def auc_from_roc(tp, fp):
h = np.diff(fp)
auc = np.sum(h*(tp[1:]+tp[:-1]))/2.0
return auc
def roc_curve(predicted, actual, cls):
si = np.argsort(-predicted)
tp = np.cumsum(np.single(actual[si]==cls))
fp = np.cumsum(np.single(actual[si]!=cls))
tp = tp/np.sum(actual==cls)
fp = fp/np.sum(actual!=cls)
tp = np.hstack((0.0, tp, 1.0))
fp = np.hstack((0.0, fp, 1.0))
return tp, fp