Main Content

trainFCDDAnomalyDetector

Train fully convolutional data description (FCDD) anomaly detection network

Since R2022b

    Description

    example

    detector = trainFCDDAnomalyDetector(normalData,anomalyData,untrainedDetector,options) trains the FCDD anomaly detection network untrainedDetector. The training data consists of normal images in normalData and anomaly images in anomalyData. The options argument controls options for training.

    Note

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

    Note

    It is recommended that you also have Parallel Computing Toolbox™ to use with a CUDA®-enabled NVIDIA® GPU. For information about the supported compute capabilities, see GPU Computing Requirements (Parallel Computing Toolbox).

    detector = trainFCDDAnomalyDetector(normalData,anomalyData,untrainedDetector,options,Name=Value) uses additional options specified by one or more name-value arguments.

    [detector,info] = trainFCDDAnomalyDetector(___) also returns information on the training progress, such as the training accuracy and learning rate for each iteration.

    Examples

    collapse all

    Load a data set that consists of images of digits from 0 to 9.

    dataDir = fullfile(toolboxdir("vision"),"visiondata","digits","synthetic");
    dsTrain = imageDatastore(dataDir,IncludeSubfolders=true, ...
        LabelSource="foldernames");

    Split the training data into normal and anomaly images. For instance, set the images of the digit 8 to be normal, and all other digits to be anomalous.

    trainingLabels = dsTrain.Labels;
    normalDataIdx = find(trainingLabels == "8");
    anomalyDataIdx = find(trainingLabels ~= "8");
    dsNormal = subset(dsTrain,normalDataIdx);
    dsAnomaly = subset(dsTrain,anomalyDataIdx);

    Create an fcddAnomalyDetector object with a ResNet-18 backbone.

    backbone = pretrainedEncoderNetwork("resnet18",3);
    untrainedDetector = fcddAnomalyDetector(backbone);

    Specify training options for SGDM optimization.

    options = trainingOptions("sgdm", ...
        Plots="training-progress", ...
        InitialLearnRate = 0.01, ...
        MaxEpochs=40, ...
        MiniBatchSize=300, ...
        ResetInputNormalization=false, ...
        Shuffle="every-epoch");

    Train the anomaly detector.

    detector = trainFCDDAnomalyDetector(dsNormal,dsAnomaly,untrainedDetector,options);
     
        Epoch    Iteration    TimeElapsed    LearnRate    TrainingFcddLoss
        _____    _________    ___________    _________    ________________
    

    Input Arguments

    collapse all

    Untrained FCDD anomaly detector, specified as an fcddAnomalyDetector object.

    Labeled ground truth normal images, specified as a datastore.

    Labeled ground truth anomaly images, specified as a datastore.

    Training options, specified as a TrainingOptionsSGDM, TrainingOptionsRMSProp, or TrainingOptionsADAM object returned by the trainingOptions (Deep Learning Toolbox) function. To specify the solver name and other options for network training, use the trainingOptions function.

    You must set the BatchNormalizationStatistics property of the object as "moving".

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=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: detector = trainFCDDAnomalyDetector(normalData,anomalyData,untrainedDetector,options,FreezeBackbone=false) does not freeze the backbone of the FCDD network during training.

    Use mask data in the anomaly training data to form the pixelwise loss, specified as a numeric or logical false (0) or true (1). When true, the anomaly training data in anomalyData must be a datastore that returns pairs of images as a two-element cell array of the form {anomalyImage,anomalyMask}. The first element, anomalyImage, is a sample image of an anomaly. The second element, anomalyMask, is a logical image of the same size as anomalyImage and has true valued pixels at locations where anomalyImage has anomaly content.

    Freeze the backbone of the FCDD network during training, specified as a numeric or logical true (1) or false (0). When true, the weight of layers in the backbone does not change during training.

    Output Arguments

    collapse all

    Trained FCDD anomaly detector, returned as an fcddAnomalyDetector object.

    Training progress information, returned as a structure array with these fields.

    • Epoch — Epoch

    • Iteration — Iteration

    • TimeElapsed — Total elapsed duration

    • LearnRate — Learning rate for each iteration

    • TrainingFcddLoss — FCDD loss at the end of each iteration

    • OutputNetworkIteration — Iteration number of returned network

    Version History

    Introduced in R2022b