metric_op

accuracy

paddle.fluid.layers.accuracy(input, label, k=1, correct=None, total=None)[source]

accuracy layer. Refer to the https://en.wikipedia.org/wiki/Precision_and_recall

This function computes the accuracy using the input and label. If the correct label occurs in top k predictions, then correct will increment by one. Note: the dtype of accuracy is determined by input. the input and label dtype can be different.

Parameters:
  • input (Variable) – The input of accuracy layer, which is the predictions of network. Carry LoD information is supported.
  • label (Variable) – The label of dataset.
  • k (int) – The top k predictions for each class will be checked.
  • correct (Variable) – The correct predictions count.
  • total (Variable) – The total entries count.
Returns:

The correct rate.

Return type:

Variable

Examples

import paddle.fluid as fluid
data = fluid.layers.data(name="data", shape=[-1, 32, 32], dtype="float32")
label = fluid.layers.data(name="label", shape=[-1,1], dtype="int32")
predict = fluid.layers.fc(input=data, size=10)
accuracy_out = fluid.layers.accuracy(input=predict, label=label, k=5)

auc

paddle.fluid.layers.auc(input, label, curve='ROC', num_thresholds=4095, topk=1, slide_steps=1)[source]

Area Under the Curve (AUC) Layer

This implementation computes the AUC according to forward output and label. It is used very widely in binary classification evaluation.

Note: If input label contains values other than 0 and 1, it will be cast to bool. Find the relevant definitions here.

There are two types of possible curves:

  1. ROC: Receiver operating characteristic;
  2. PR: Precision Recall
Parameters:
  • input (Variable) – A floating-point 2D Variable, values are in the range [0, 1]. Each row is sorted in descending order. This input should be the output of topk. Typically, this Variable indicates the probability of each label.
  • label (Variable) – A 2D int Variable indicating the label of the training data. The height is batch size and width is always 1.
  • curve (str) – Curve type, can be ‘ROC’ or ‘PR’. Default ‘ROC’.
  • num_thresholds (int) – The number of thresholds to use when discretizing the roc curve. Default 200.
  • topk (int) – only topk number of prediction output will be used for auc.
  • slide_steps – when calc batch auc, we can not only use step currently but the previous steps can be used. slide_steps=1 means use the current step, slide_steps=3 means use current step and the previous second steps, slide_steps=0 use all of the steps.
Returns:

A scalar representing the current AUC.

Return type:

Variable

Examples

import paddle.fluid as fluid
data = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
label = fluid.layers.data(name="label", shape=[1], dtype="int32")
predict = fluid.layers.fc(input=data, size=2)
auc_out = fluid.layers.auc(input=predict, label=label)