Main Content

viewAnomalyDetectionResults

View anomaly detection results

    Description

    example

    viewAnomalyDetectionResults(detector,I,trueLabels,scores,truePosLabels) displays the anomaly detection results for a set of test images I. The function displays the predicted scores against the ground truth trueLabels. truePosLabels lists the class labels in trueLabels that correspond to positive detections.

    Examples

    collapse all

    Load test images and corresponding labels, then create a datastore that reads the test data. The data set consists of grayscale images of handwritten digits 0–9.

    [Xtest,catLabels] = digitTest4DArrayData;
    dsTest = arrayDatastore(Xtest,IterationDimension=4);

    Load a pretrained FCDD anomaly detector. This detector has been trained to classify the digit 8 as normal and all other digits as anomalies. Therefore, specify the set of positive labels as the set of digits between 0 and 9, excluding 8.

    load("digit8AnomalyDetector.mat")
    scoresPred = predict(detector,dsTest);
    posLabels = setdiff(string(0:9),"8");

    View the anomaly detection results.

    viewAnomalyDetectionResults(detector,dsTest,catLabels,scoresPred,posLabels);

    {"String":"","Tex":[],"LaTex":[]}

    Select the Anomaly Histogram tab to view the Anomaly Score vs. Counts histogram plot. Note the Anomaly Threshold of 0.0002963 on the anomaly histogram plot. Above this threshold, the test image is classified as an anomaly.

    vad_2.png

    Select the Confusion Matrix tab to view the performance of the trained anomaly detector. You can also use this matrix to set predicted and ground truth filters. The accuracy of 0.766 represents the ratio of correctly classified images to the total number of images in the data set.

    vad_3.png

    Analyze the false positive images by seting the Predicted parameter to Anomaly and the Ground Truth parameter to Normal in the Settings pane. On each thumbnail of false positive images, the score appears against a red background because of the positive classification. The icon in the top left corner of the thumbnail is a yellow triangle with a white exclamation mark, which indicates the image is misclassified.

    vad_4.png

    Analyze the true negative images by setting the Predicted parameter to Normal and the Ground Truth parameter to Normal. On each thumbnail of true negative images, the score appears against a green background because of the negative classification. The icon in the top left corner of the thumbnail is a blue circle with a white checkmark, which indicates the image is correctly classified.

    vad7.png

    Analyze the true positive images by setting the Predicted parameter to Anomaly and the Ground Truth parameter to Anomaly. Select the image with the filename 31. The anomaly map overlay displays the anomaly heatmap over the image. Clear Anomaly Map Overlay in the Settings pane and observe the difference in the Selected Image tab.

    vad_5.pngvad_6.png

    Input Arguments

    collapse all

    FCDD anomaly detector, specified as a fcddAnomalyDetector object. You must set the Threshold property of the detector before calling this function.

    Images, specified as a datastore.

    Ground truth labels for each image, specified as a numeric vector, logical vector, or categorical array. The viewAnomalyDetectionResults function converts the labels into a logical vector according to the set of positive labels in truePosLabels.

    Predicted anomaly scores, returned as a numeric scalar, numeric vector, or formatted dlarray (Deep Learning Toolbox) object. scores contains one element for each image in I.

    Ground truth positive labels, specified as a vector of the same data type as trueLabels.

    The viewAnomalyDetectionResults function converts all ground truth labels in trueLabels that belong to the set of positive labels to a logical true, indicating a positive detection. The function converts all other ground truth labels to a logical false, indicating a negative detection.

    More About

    collapse all

    Anomaly Detection Figure Window

    The viewAnomalyDetectionResults function opens an interactive figure window that enables you to explore the classification results and anomaly score maps for a set of images. Annotations on the image thumbnails can help you interpret the classification.

    • The number in the colored box indicates the overall anomaly score of the image. When the number is in a green box, the score is below the anomaly threshold and the image is predicted to be normal, or negative. When the number is in a red box, the score is above the anomaly threshold and the image is predicted to be anomalous, or positive.

    • The icon in the upper right corner indicates whether the predicted and ground truth classification agree. When the icon is a blue circle with a white check mark, the prediction and ground truth agree, and the prediction is a true positive or a true negative. When the icon is a yellow triangle with a white exclamation mark, the prediction and ground truth disagree, and the prediction is a false positive or false negative.

    Version History

    Introduced in R2022b