提交 cd54a31c 编写于 作者: Q qiaolongfei

fix fluid Metric

上级 55e714e0
...@@ -251,7 +251,7 @@ class EditDistance(MetricBase): ...@@ -251,7 +251,7 @@ class EditDistance(MetricBase):
self.instance_error += seq_num - seq_right_count self.instance_error += seq_num - seq_right_count
self.total_distance += total_distance self.total_distance += total_distance
def eval(): def eval(self):
if self.seq_num == 0: if self.seq_num == 0:
raise ValueError( raise ValueError(
"There is no data in EditDistance Metric. Please check layers.edit_distance output has been added to EditDistance." "There is no data in EditDistance Metric. Please check layers.edit_distance output has been added to EditDistance."
...@@ -340,8 +340,8 @@ class Auc(MetricBase): ...@@ -340,8 +340,8 @@ class Auc(MetricBase):
raise ValueError("The 'predictions' must be a numpy ndarray.") raise ValueError("The 'predictions' must be a numpy ndarray.")
kepsilon = 1e-7 # to account for floating point imprecisions kepsilon = 1e-7 # to account for floating point imprecisions
thresholds = [(i + 1) * 1.0 / (num_thresholds - 1) thresholds = [(i + 1) * 1.0 / (self._num_thresholds - 1)
for i in range(num_thresholds - 2)] for i in range(self._num_thresholds - 2)]
thresholds = [0.0 - kepsilon] + thresholds + [1.0 + kepsilon] thresholds = [0.0 - kepsilon] + thresholds + [1.0 + kepsilon]
# caculate TP, FN, TN, FP count # caculate TP, FN, TN, FP count
...@@ -358,19 +358,20 @@ class Auc(MetricBase): ...@@ -358,19 +358,20 @@ class Auc(MetricBase):
fp += 1 fp += 1
else: else:
tn += 1 tn += 1
tp_list[idx_thresh] += tp self.tp_list[idx_thresh] += tp
fn_list[idx_thresh] += fn self.fn_list[idx_thresh] += fn
tn_list[idx_thresh] += tn self.tn_list[idx_thresh] += tn
fp_list[idx_thresh] += fp self.fp_list[idx_thresh] += fp
def eval(self): def eval(self):
epsilon = self._epsilon epsilon = self._epsilon
num_thresholds = self._num_thresholds num_thresholds = self._num_thresholds
tpr = (tp_list.astype("float32") + epsilon) / ( tpr = (self.tp_list.astype("float32") + epsilon) / (
tp_list + fn_list + epsilon) self.tp_list + self.fn_list + epsilon)
fpr = fp_list.astype("float32") / (fp_list + tn_list + epsilon) fpr = self.fp_list.astype("float32") / (
rec = (tp_list.astype("float32") + epsilon) / ( self.fp_list + self.tn_list + epsilon)
tp_list + fp_list + epsilon) rec = (self.tp_list.astype("float32") + epsilon) / (
self.tp_list + self.fp_list + epsilon)
x = fpr[:num_thresholds - 1] - fpr[1:] x = fpr[:num_thresholds - 1] - fpr[1:]
y = (tpr[:num_thresholds - 1] + tpr[1:]) / 2.0 y = (tpr[:num_thresholds - 1] + tpr[1:]) / 2.0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册