From 94d2cf82728df5cb4c794c1b557b9efba1d67dbd Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Fri, 17 Sep 2021 11:08:11 +0800 Subject: [PATCH] update acc func using topk v2 (#35789) --- python/paddle/metric/metrics.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/paddle/metric/metrics.py b/python/paddle/metric/metrics.py index 415e5d05aac..d75c95b4372 100644 --- a/python/paddle/metric/metrics.py +++ b/python/paddle/metric/metrics.py @@ -22,7 +22,6 @@ import numpy as np from ..fluid.data_feeder import check_variable_and_dtype from ..fluid.layer_helper import LayerHelper -from ..fluid.layers.nn import topk from ..fluid.framework import core, _varbase_creator, in_dygraph_mode import paddle from paddle import _C_ops @@ -798,7 +797,7 @@ def accuracy(input, label, k=1, correct=None, total=None, name=None): if total is None: total = _varbase_creator(dtype="int32") - topk_out, topk_indices = topk(input, k=k) + topk_out, topk_indices = paddle.topk(input, k=k) _acc, _, _ = _C_ops.accuracy(topk_out, topk_indices, label, correct, total) return _acc @@ -806,7 +805,7 @@ def accuracy(input, label, k=1, correct=None, total=None, name=None): helper = LayerHelper("accuracy", **locals()) check_variable_and_dtype(input, 'input', ['float16', 'float32', 'float64'], 'accuracy') - topk_out, topk_indices = topk(input, k=k) + topk_out, topk_indices = paddle.topk(input, k=k) acc_out = helper.create_variable_for_type_inference(dtype="float32") if correct is None: correct = helper.create_variable_for_type_inference(dtype="int32") -- GitLab