Metric¶
This module includes a set of metric classes for evaluating the model’s performance. The specific metric classes could be converted from C++ implmentation or implemented directly using Python.
Example usage:
from singa import tensor
from singa import metric
x = tensor.Tensor((3, 5))
x.uniform(0, 1) # randomly genearte the prediction activation
x = tensor.SoftMax(x) # normalize the prediction into probabilities
y = tensor.from_numpy(np.array([0, 1, 3], dtype=np.int)) # set the truth
f = metric.Accuracy()
acc = f.evaluate(x, y) # averaged accuracy over all 3 samples in x
-
class
singa.metric.
Metric
¶ Bases:
object
Base metric class.
Subclasses that wrap the C++ loss classes can use the inherited foward, and evaluate functions of this base class. Other subclasses need to override these functions. Users need to feed in the predictions and ground truth to get the metric values.
-
forward
(x, y)¶ Compute the metric for each sample.
Parameters: Returns: a tensor of floats, one per sample
-
-
class
singa.metric.
Accuracy
¶ Bases:
singa.metric.Metric
Compute the top one accuracy for singel label prediction tasks.
It calls the C++ functions to do the calculation.