@@ -251,7 +251,7 @@ def update(self, distances, seq_num):
251
251
self .instance_error += seq_num - seq_right_count
252
252
self .total_distance += total_distance
253
253
254
- def eval ():
254
+ def eval (self ):
255
255
if self .seq_num == 0 :
256
256
raise ValueError (
257
257
"There is no data in EditDistance Metric. Please check layers.edit_distance output has been added to EditDistance."
@@ -280,6 +280,7 @@ def __init__(self, name=None):
280
280
super (DetectionMAP , self ).__init__ (name )
281
281
# the current map value
282
282
self .value = .0
283
+ self .weight = .0
283
284
284
285
def update (self , value , weight ):
285
286
if not _is_number_or_matrix_ (value ):
@@ -340,8 +341,8 @@ def update(self, labels, predictions, axis=1):
340
341
raise ValueError ("The 'predictions' must be a numpy ndarray." )
341
342
342
343
kepsilon = 1e-7 # to account for floating point imprecisions
343
- thresholds = [(i + 1 ) * 1.0 / (num_thresholds - 1 )
344
- for i in range (num_thresholds - 2 )]
344
+ thresholds = [(i + 1 ) * 1.0 / (self . _num_thresholds - 1 )
345
+ for i in range (self . _num_thresholds - 2 )]
345
346
thresholds = [0.0 - kepsilon ] + thresholds + [1.0 + kepsilon ]
346
347
347
348
# caculate TP, FN, TN, FP count
@@ -358,19 +359,20 @@ def update(self, labels, predictions, axis=1):
358
359
fp += 1
359
360
else :
360
361
tn += 1
361
- tp_list [idx_thresh ] += tp
362
- fn_list [idx_thresh ] += fn
363
- tn_list [idx_thresh ] += tn
364
- fp_list [idx_thresh ] += fp
362
+ self . tp_list [idx_thresh ] += tp
363
+ self . fn_list [idx_thresh ] += fn
364
+ self . tn_list [idx_thresh ] += tn
365
+ self . fp_list [idx_thresh ] += fp
365
366
366
367
def eval (self ):
367
368
epsilon = self ._epsilon
368
369
num_thresholds = self ._num_thresholds
369
- tpr = (tp_list .astype ("float32" ) + epsilon ) / (
370
- tp_list + fn_list + epsilon )
371
- fpr = fp_list .astype ("float32" ) / (fp_list + tn_list + epsilon )
372
- rec = (tp_list .astype ("float32" ) + epsilon ) / (
373
- tp_list + fp_list + epsilon )
370
+ tpr = (self .tp_list .astype ("float32" ) + epsilon ) / (
371
+ self .tp_list + self .fn_list + epsilon )
372
+ fpr = self .fp_list .astype ("float32" ) / (
373
+ self .fp_list + self .tn_list + epsilon )
374
+ rec = (self .tp_list .astype ("float32" ) + epsilon ) / (
375
+ self .tp_list + self .fp_list + epsilon )
374
376
375
377
x = fpr [:num_thresholds - 1 ] - fpr [1 :]
376
378
y = (tpr [:num_thresholds - 1 ] + tpr [1 :]) / 2.0
0 commit comments