Main Content

scores2label

Convert prediction scores to labels

Since R2024a

    Description

    example

    labels = scores2label(scores,classNames) converts the specified prediction scores to labels by returning labels with the highest score in the channel dimension.

    labels = scores2label(scores,classNames,dim) additionally specifies the channel dimension of the prediction scores.

    Examples

    collapse all

    Load a pretrained SqueezeNet neural network.

    [net,classNames] = imagePretrainedNetwork;

    Read an image from a PNG file and classify it. To classify the image, first convert it to the data type single.

    im = imread("peppers.png");
    figure
    imshow(im)

    X = single(im);
    scores = predict(net,X);
    [label,score] = scores2label(scores,classNames);

    Display the predicted label and corresponding score with the image.

    figure
    imshow(im)
    title(string(label) + " (Score: " + score + ")")

    Input Arguments

    collapse all

    Scores, specified as a numeric array or dlarray object.

    Class names, specified as a string array, categorical array, or cell array of character vectors.

    Data Types: string | cell | categorical

    Channel dimension, specified as one of these values:

    • "auto" — Automatically determine channel dimension from number of elements in classNames. If there is exactly one dimension of size numel(classNames) that has elements that sum to one, then the function uses this dimension. Otherwise, the function throws an error.

    • Positive integer — Use the specified dimension as the channel dimension. Use this option when there are multiple dimensions of size numel(classNames).

    The scores2label function finds the top scores over the specified dimension.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

    Output Arguments

    collapse all

    Labels with the highest score in the channel dimension of scores, returned as a categorical array.

    Extended Capabilities

    Version History

    Introduced in R2024a