efficientADAnomalyDetector - Detect anomalies using EfficientAD network - MATLAB (original) (raw)

Detect anomalies using EfficientAD network

Since R2024b

Description

The efficientADAnomalyDetector object detects images of anomalies using an EfficientAD anomaly detector network. Train the detector using the trainEfficientADAnomalyDetector function. To detect anomalous images, pass the trained detector to the classify function.

Note

This functionality requires Deep Learning Toolbox™ and the Automated Visual Inspection Library for Computer Vision Toolbox™. You can install the Automated Visual Inspection Library for Computer Vision Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Creation

Syntax

Description

detector = efficientADAnomalyDetector creates an EfficientAD anomaly detector from a base patch description network (PDN).

detector = efficientADAnomalyDetector([Name=Value](#namevaluepairarguments)) specifies options for the EfficientAD anomaly detector creation using one or more name-value arguments.

example

Name-Value Arguments

expand all

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: efficientADAnomalyDetector(PDNnet="pdn-small") specifies the patch description network as "pdn-small".

Name of the patch description network (PDN), a convolutional network that serves as the base feature extraction network, specified as one of these values:

For images of variable size, the PDN generates all feature vectors in a single forward pass.

Data Types: char | string

Global anomaly map autoencoder toggle for tile-based training, specified as a numeric or logical 1 (true) or0 (false). If you specifyUseGlobalAnomalyMap as false, theefficientADAnomalyDetector object creates an EfficientAD anomaly detector that uses the student-teacher model to generate the local anomaly map, and turns off the autoencoder, which primarily detects global anomalies. To perform inference on full-size images after tile-based training on patches of images, turn off the autoencoder by specifying UseGlobalAnomalyMap asfalse.

Tip

When you perform tile-based training and GPU memory is limited, reduce the mini-batch size using the MiniBatchSize (Deep Learning Toolbox) argument of the trainingOptions (Deep Learning Toolbox) function, at the expense of slower computation speed.

Optimize anomaly score for logical anomalies, specified as a numeric or logical0 (false) or 1 (true) . If you specifyOptimizeScoreForLogicalAnomalies as true, the efficientADAnomalyDetector object creates an EfficientAD anomaly detector that uses both picturable and unpicturable anomaly scores to optimize logical anomaly detection. Logical anomalies result from missing, misplaced, extraneous, or geometrically faulty features. Specify this option to improve detector performance in images with logical anomalies at the expense of increased computation cost from calculating normalization statistics and additional anomaly scores. To learn more, see Logical Anomaly Detection Method.

Properties

expand all

Anomaly threshold, stored as a numeric scalar. You must set the value of the threshold before calling the classify function. You can calculate a threshold using the anomalyThreshold function.

This property is read-only.

Image size of images used for training and inference, stored as a three-element numeric row vector. The trainEfficientADAnomalyDetector function sets theImageSize property during training, which indicates the size of the training images. The image size can be different from the input layer size of the base feature extraction PDN.

Note

When using the detector, the image size at inference must match the image size used during training.

Object Functions

predict Predict unnormalized anomaly scores
classify Classify image as normal or anomalous
anomalyMap Predict per-pixel anomaly score map

Examples

collapse all

Create an efficientADAnomalyDetector object from a medium-sized base patch description network (PDN).

detector = efficientADAnomalyDetector(Network="pdn-medium")

detector = efficientADAnomalyDetector with properties:

Threshold: []
ImageSize: []
  Network: "pdn-medium"

More About

expand all

The EfficientAD anomaly detector operates on the principle of a student-teacher model, where the teacher is a pre-trained deep neural network that understands normal data behavior, and the student is a smaller network that learns to mimic the teacher's responses on normal data. During training, only normal data (without anomalies) is used, allowing the student to learn a compact representation of what is considered normal. At inference, both the student and teacher evaluate incoming data; anomalies are detected based on the discrepancy between the student's and teacher's outputs, as the student will likely fail to accurately replicate the teacher's behavior on anomalous data, highlighting instances that deviate from the learned normal behavior.

Picturable, or structural, anomalies are anomalies whose location can be clearly depicted on a ground truth map. Unpicturable anomalies are logical anomalies which result from missing, misplaced, extraneous, or geometrically faulty features, and are not easily represented by spatial feature maps. The Picturable and Unpicturable Anomaly Scores (PUAD) method uses EfficientAD to detect picturable anomalies, and a feature-based method to detect unpicturable anomalies. The out-of-distribution approach calculates the unpicturable anomalies as Mahalanobis distances using the student’s former half output [2].

References

[1] Batzner, Kilian, Lars Heckler, and Rebecca König. “EfficientAD: Accurate Visual Anomaly Detection at Millisecond-Level Latencies.” arXiv, February 8, 2024. https://doi.org/10.48550/arXiv.2303.14535.

[2] Sugawara, Shota, and Ryuji Imamura. “PUAD: Frustratingly Simple Method for Robust Anomaly Detection.” In 2024 IEEE International Conference on Image Processing (ICIP), 842–48. Abu Dhabi, United Arab Emirates: IEEE, 2024. https://doi.org/10.1109/ICIP51287.2024.10647438.

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

Version History

Introduced in R2024b