Main Content

patchCoreAnomalyDetector

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

    Description

    detector = patchCoreAnomalyDetector creates a PatchCore anomaly detector from a ResNet-18 backbone network.

    detector = patchCoreAnomalyDetector(Backbone=backbone) 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:

    • "resnet18" — ResNet-18 convolutional neural network. See resnet18 (Deep Learning Toolbox) for more information.

    • "resnet50" — ResNet-50 convolutional neural network. See resnet50 (Deep Learning Toolbox) for more information.

    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 the ImageSize property during training, which indicates the size of the training images. The image size can be different from the input layer size of backbone.

    Note

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

    Object Functions

    predictPredict unnormalized anomaly scores
    classifyClassify image as normal or anomalous
    anomalyMapPredict 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