patchCoreAnomalyDetector - Detect anomalies using PatchCore network - MATLAB (original) (raw)

Detect anomalies using PatchCore network

Since R2023a

Description

The patchCoreAnomalyDetector object detects images of anomalies using a PatchCore anomaly detector network. Train the detector using the trainPatchCoreAnomalyDetector 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 = patchCoreAnomalyDetector creates a PatchCore anomaly detector from a ResNet-18 backbone network.

detector = patchCoreAnomalyDetector(Backbone=[backbone](#mw%5F507b071e-92bf-4e28-ad0c-199f470bbd3c)) specifies the base feature extraction backbone network from which to create the PatchCore anomaly detector.

example

Input Arguments

expand all

Name of the pretrained backbone network that serves as the base feature extraction network, specified as a dlnetwork (Deep Learning Toolbox) object or one of these values:

You must install the associated add-on for the selected pretrained network.

If you specify the network as a dlnetwork (Deep Learning Toolbox) object, it must accept a single input and return one or more outputs.

Data Types: char | string | dlnetwork

Properties

expand all

Anomaly threshold, specified 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 trainPatchCoreAnomalyDetector 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 ofbackbone.

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 a patchCoreAnomalyDetector object from a ResNet-50 backbone network.

detector = patchCoreAnomalyDetector(Backbone="resnet50")

detector = patchCoreAnomalyDetector with properties:

Threshold: []
ImageSize: []

References

[1] Roth, Karsten, Latha Pemula, Joaquin Zepeda, Bernhard Schölkopf, Thomas Brox, and Peter Gehler. “Towards Total Recall in Industrial Anomaly Detection.” arXiv, May 5, 2022. https://arxiv.org/abs/2106.08265.

Extended Capabilities

Version History

Introduced in R2023a

expand all

Specify the backbone feature extraction network as a dlnetwork object by using the backbone input argument. For example, given a custom dlnetwork (Deep Learning Toolbox) object, dlnet, the argumentBackbone specifies dlnet as the backbone feature extraction network.