Skip to content

Potential bug/confusion when is_multilabel=True for some metrics #2444

@ozancaglayan

Description

@ozancaglayan

Hello,

in the documentation for Precision, Recall and ClassificationReport, if the task is multilabel, following examples are given:

        Multilabel case, the shapes must be (batch_size, num_categories, ...)

        .. testcode:: 2

            metric = ClassificationReport(output_dict=True, is_multilabel=True)
            metric.attach(default_evaluator, "cr")
            y_true = torch.Tensor([
                [0, 0, 1],
                [0, 0, 0],
                [0, 0, 0],
                [1, 0, 0],
                [0, 1, 1],
            ]).unsqueeze(0)
            y_pred = torch.Tensor([
                [1, 1, 0],
                [1, 0, 1],
                [1, 0, 0],
                [1, 0, 1],
                [1, 1, 0],
            ]).unsqueeze(0)

In all metric docs, a first-dim is added by unsqueeze(0) to both y_true and y_pred, but it is also told that the shapes must be (batch_size, num_categories, ...). From my understanding of the latter, both y_true and y_pred should have n_samples X num_categories shape. In this example, this amounts to 5 x 3 e.g. 5 examples/samples and three output labels, each binary.

  • Why do we add the dummy singleton dim in the first place? If we don't add it, per-label computation is not correct as it takes the sample dimension as the label dimension i.e. if 256 examples are given, 256 metrics are computed for each of them.

Thanks!

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions