|
|
|
@ -20,6 +20,7 @@ from ..layer_helper import LayerHelper
|
|
|
|
from ..initializer import Normal, Constant
|
|
|
|
from ..initializer import Normal, Constant
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
|
|
|
|
import nn
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['accuracy', 'auc']
|
|
|
|
__all__ = ['accuracy', 'auc']
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,17 +28,10 @@ __all__ = ['accuracy', 'auc']
|
|
|
|
def accuracy(input, label, k=1, correct=None, total=None):
|
|
|
|
def accuracy(input, label, k=1, correct=None, total=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This function computes the accuracy using the input and label.
|
|
|
|
This function computes the accuracy using the input and label.
|
|
|
|
The output is the top_k inputs and their indices.
|
|
|
|
The output is the top k inputs and their indices.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
helper = LayerHelper("accuracy", **locals())
|
|
|
|
helper = LayerHelper("accuracy", **locals())
|
|
|
|
topk_out = helper.create_tmp_variable(dtype=input.dtype)
|
|
|
|
topk_out, topk_indices = nn.topk(input, k=k)
|
|
|
|
topk_indices = helper.create_tmp_variable(dtype="int64")
|
|
|
|
|
|
|
|
helper.append_op(
|
|
|
|
|
|
|
|
type="top_k",
|
|
|
|
|
|
|
|
inputs={"X": [input]},
|
|
|
|
|
|
|
|
outputs={"Out": [topk_out],
|
|
|
|
|
|
|
|
"Indices": [topk_indices]},
|
|
|
|
|
|
|
|
attrs={"k": k})
|
|
|
|
|
|
|
|
acc_out = helper.create_tmp_variable(dtype="float32")
|
|
|
|
acc_out = helper.create_tmp_variable(dtype="float32")
|
|
|
|
if correct is None:
|
|
|
|
if correct is None:
|
|
|
|
correct = helper.create_tmp_variable(dtype="int64")
|
|
|
|
correct = helper.create_tmp_variable(dtype="int64")
|
|
|
|
@ -68,12 +62,7 @@ def auc(input, label, curve='ROC', num_thresholds=200):
|
|
|
|
helper = LayerHelper("auc", **locals())
|
|
|
|
helper = LayerHelper("auc", **locals())
|
|
|
|
topk_out = helper.create_tmp_variable(dtype=input.dtype)
|
|
|
|
topk_out = helper.create_tmp_variable(dtype=input.dtype)
|
|
|
|
topk_indices = helper.create_tmp_variable(dtype="int64")
|
|
|
|
topk_indices = helper.create_tmp_variable(dtype="int64")
|
|
|
|
helper.append_op(
|
|
|
|
topk_out, topk_indices = nn.topk(input, k=k)
|
|
|
|
type="top_k",
|
|
|
|
|
|
|
|
inputs={"X": [input]},
|
|
|
|
|
|
|
|
outputs={"Out": [topk_out],
|
|
|
|
|
|
|
|
"Indices": [topk_indices]},
|
|
|
|
|
|
|
|
attrs={"k": k})
|
|
|
|
|
|
|
|
auc_out = helper.create_tmp_variable(dtype="float32")
|
|
|
|
auc_out = helper.create_tmp_variable(dtype="float32")
|
|
|
|
if correct is None:
|
|
|
|
if correct is None:
|
|
|
|
correct = helper.create_tmp_variable(dtype="int64")
|
|
|
|
correct = helper.create_tmp_variable(dtype="int64")
|
|
|
|
|