Skip to content

Commit 9c83fea

Browse files
authored
Merge pull request #10439 from jacquesqiao/fix-metric
fix fluid Metric
2 parents 2a2c83b + 7f37060 commit 9c83fea

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

python/paddle/fluid/metrics.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def update(self, distances, seq_num):
251251
self.instance_error += seq_num - seq_right_count
252252
self.total_distance += total_distance
253253

254-
def eval():
254+
def eval(self):
255255
if self.seq_num == 0:
256256
raise ValueError(
257257
"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):
280280
super(DetectionMAP, self).__init__(name)
281281
# the current map value
282282
self.value = .0
283+
self.weight = .0
283284

284285
def update(self, value, weight):
285286
if not _is_number_or_matrix_(value):
@@ -340,8 +341,8 @@ def update(self, labels, predictions, axis=1):
340341
raise ValueError("The 'predictions' must be a numpy ndarray.")
341342

342343
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)]
345346
thresholds = [0.0 - kepsilon] + thresholds + [1.0 + kepsilon]
346347

347348
# caculate TP, FN, TN, FP count
@@ -358,19 +359,20 @@ def update(self, labels, predictions, axis=1):
358359
fp += 1
359360
else:
360361
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
365366

366367
def eval(self):
367368
epsilon = self._epsilon
368369
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)
374376

375377
x = fpr[:num_thresholds - 1] - fpr[1:]
376378
y = (tpr[:num_thresholds - 1] + tpr[1:]) / 2.0

0 commit comments

Comments
 (0)