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.
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
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.
Compute the metric for each sample.
a tensor of floats, one per sample