torchnet.meter¶
Meters provide a way to keep track of important statistics in an online manner.
TNT also provides convenient ways to visualize and manage meters via the torchnet.logger.MeterLogger
class.

class
torchnet.meter.meter.
Meter
[source]¶ Meters provide a way to keep track of important statistics in an online manner.
This class is abstract, but provides a standard interface for all meters to follow.
Classification Meters¶
APMeter¶

class
torchnet.meter.
APMeter
[source]¶ The APMeter measures the average precision per class.
The APMeter is designed to operate on NxK Tensors output and target, and optionally a Nx1 Tensor weight where (1) the output contains model output scores for N examples and K classes that ought to be higher when the model is more convinced that the example should be positively labeled, and smaller when the model believes the example should be negatively labeled (for instance, the output of a sigmoid function); (2) the target contains only values 0 (for negative examples) and 1 (for positive examples); and (3) the weight ( > 0) represents weight for each sample.

add
(output, target, weight=None)[source]¶ Add a new observation
Parameters:  output (Tensor) – NxK tensor that for each of the N examples indicates the probability of the example belonging to each of the K classes, according to the model. The probabilities should sum to one over all classes
 target (Tensor) – binary NxK tensort that encodes which of the K classes are associated with the Nth input (eg: a row [0, 1, 0, 1] indicates that the example is associated with classes 2 and 4)
 weight (optional, Tensor) – Nx1 tensor representing the weight for each example (each weight > 0)

mAPMeter¶

class
torchnet.meter.
mAPMeter
[source]¶ The mAPMeter measures the mean average precision over all classes.
The mAPMeter is designed to operate on NxK Tensors output and target, and optionally a Nx1 Tensor weight where (1) the output contains model output scores for N examples and K classes that ought to be higher when the model is more convinced that the example should be positively labeled, and smaller when the model believes the example should be negatively labeled (for instance, the output of a sigmoid function); (2) the target contains only values 0 (for negative examples) and 1 (for positive examples); and (3) the weight ( > 0) represents weight for each sample.
ConfusionMeter¶

class
torchnet.meter.
ConfusionMeter
(k, normalized=False)[source]¶ Maintains a confusion matrix for a given calssification problem.
The ConfusionMeter constructs a confusion matrix for a multiclass classification problems. It does not support multilabel, multiclass problems: for such problems, please use MultiLabelConfusionMeter.
Parameters:  k (int) – number of classes in the classification problem
 normalized (boolean) – Determines whether or not the confusion matrix is normalized or not

add
(predicted, target)[source]¶ Computes the confusion matrix of K x K size where K is no of classes
Parameters:  predicted (tensor) – Can be an N x K tensor of predicted scores obtained from the model for N examples and K classes or an Ntensor of integer values between 0 and K1.
 target (tensor) – Can be a Ntensor of integer values assumed to be integer values between 0 and K1 or N x K tensor, where targets are assumed to be provided as onehot vectors
Regression/Loss Meters¶
AUCMeter¶

class
torchnet.meter.
AUCMeter
[source]¶ The AUCMeter measures the area under the receiveroperating characteristic (ROC) curve for binary classification problems. The area under the curve (AUC) can be interpreted as the probability that, given a randomly selected positive example and a randomly selected negative example, the positive example is assigned a higher score by the classification model than the negative example.
The AUCMeter is designed to operate on onedimensional Tensors output and target, where (1) the output contains model output scores that ought to be higher when the model is more convinced that the example should be positively labeled, and smaller when the model believes the example should be negatively labeled (for instance, the output of a signoid function); and (2) the target contains only values 0 (for negative examples) and 1 (for positive examples).
Miscellaneous Meters¶
TimeMeter¶

class
torchnet.meter.
TimeMeter
(unit)[source]¶ <a name=”TimeMeter”> #### tnt.TimeMeter(@ARGP) @ARGT
The tnt.TimeMeter is designed to measure the time between events and can be used to measure, for instance, the average processing time per batch of data. It is different from most other meters in terms of the methods it provides:
The tnt.TimeMeter provides the following methods:
 reset() resets the timer, setting the timer and unit counter to zero.
 value() returns the time passed since the last reset(); divided by the counter value when unit=true.