FilesLast commitLast update
1 month ago
8 days ago
8 days ago
1 month ago
17 days ago
21 days ago
1 month ago
14 days ago
README

ConfusionMatrix

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products √
Atlas inference products √
Atlas training products √

Function Description

  • Operator function: computes the confusion matrix of a classification task. Given the ground-truth labels and the predicted labels predictions, the operator counts the number of occurrences of each (label, prediction) pair and generates a num_classes×num_classes matrix. When weights is not empty, the contribution of each match is the corresponding weight value instead of 1.

  • Computation formula:

    If weights is specified:

    y[labelsi,predictionsi]=y[labelsi,predictionsi]+weightsiy[labels_i, predictions_i] = y[labels_i, predictions_i] + weights_i

    Otherwise:

    y[labelsi,predictionsi]=y[labelsi,predictionsi]+1y[labels_i, predictions_i] = y[labels_i, predictions_i] + 1

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
labels Input Ground-truth labels, a 1-dimensional tensor, with the value range [0, num_classes). INT8, INT32, UINT8, FLOAT16, FLOAT ND
predictions Input Predicted labels, a 1-dimensional tensor, whose shape and dtype are the same as those of labels. INT8, INT32, UINT8, FLOAT16, FLOAT ND
weights Input Weight of each sample, which can be empty. The shape is the same as that of labels; when it is not empty, the dtype must be the same as the dtype of the output y (that is, the same as the dtype attribute). FLOAT, FLOAT16, INT32, INT8, UINT8 ND
num_classes Attribute Number of classes, with the value range [1, 4096]. INT -
dtype Attribute Data type of the output tensor. STRING -
y Output Confusion matrix, whose shape is [num_classes, num_classes]. FLOAT, FLOAT16, INT32, INT8, UINT8 ND

Constraint Description

  • The shapes of labels and predictions must be the same.
  • The dtypes of labels and predictions must be the same.
  • When weights is not empty, its shape must be the same as that of labels, and its dtype must be the same as the dtype of the output y (that is, the dtype attribute).
  • The values in labels and predictions must be in the range [0, num_classes).
  • The value range of num_classes is [1, 4096].
  • labels and predictions are 1-dimensional tensors, and the supported data types are FLOAT, FLOAT16, INT32, INT8, and UINT8.
  • Accuracy constraint: when the output is FLOAT16, the count is accurate within the exact integer representation range of fp16 (≤2048); if the count of a single bucket exceeds this range, precision loss occurs (accumulation is performed at the output precision). For scenarios with large counts, it is recommended to use float32 or int32 for the output.

Invocation Description

Invocation Method Invocation Sample Description
Graph-mode invocation test_geir_confusion_matrix Invokes the ConfusionMatrix operator by building a graph through the operator IR.