Main Content

TrainingInfo

Neural network training information

Since R2023b

    Description

    Neural network training information including validation and loss information.

    Creation

    Create a TrainingInfo object using the second output of the trainnet.

    Properties

    expand all

    Information about training iterations, returned as a table.

    The table contains these variables:

    • Iteration — Iteration number

    • Loss — Training loss

    • Metrics specified by the Metrics training option.

    If you train with a stochastic solver (SGDM, Adam, or RMSProp), then the table has these additional variables:

    • Epoch — Epoch number

    • LearnRate — Learning rate

    If you train with the L-BFGS solver, then the table has these additional variables:

    • GradientNorm — Norm of the gradients

    • StepNorm — Norm of the steps

    Data Types: table

    Information about validation iterations, returned as a table.

    The table contains these variables:

    • Iteration — Iteration number

    • Loss — Training loss

    • Metrics specified by the Metrics training option.

    Data Types: table

    Iteration that corresponds to the returned network, returned as a positive integer.

    Data Types: double

    Reason for stopping training, returned as one of these values:

    • "Max epochs completed" — Training reached the number of epochs specified by the MaxEpochs training option.

    • "Max iterations completed" — Training reached the number of iterations specified by the MaxIterations training option.

    • "Stopped by OutputFcn" — Function specified by the OutputFcn training option returned 1 (true).

    • "Met validation criterion" — Validation loss is not lowest for ValidationPatience times.

    • "Stopped manually" — Stop button pressed.

    • "Error occurred" — The software threw an error.

    • "Training loss is NaN" — Training loss is NaN.

    • "Gradient tolerance reached" — Norm of the gradients is lower than the GradientTolerance training option.

    • "Step tolerance reached" — Norm of the steps is lower than the StepTolerance training option.

    • "Suitable learning rate not found" — Line search unable to find suitable learning rate.

    Data Types: string

    Object Functions

    showShow training information plot
    closeClose training information plot

    Examples

    collapse all

    Unzip the digit sample data and create an image datastore. The imageDatastore function automatically labels the images based on folder names.

    unzip("DigitsData.zip")
    imds = imageDatastore("DigitsData", ...
        IncludeSubfolders=true, ...
        LabelSource="foldernames");

    Define the convolutional neural network architecture. Specify the size of the images in the input layer of the network and the number of classes in the final fully connected layer. Each image is 28-by-28-by-1 pixels.

    inputSize = [28 28 1];
    numClasses = numel(categories(imds.Labels));
    
    layers = [
        imageInputLayer(inputSize)
        convolution2dLayer(5,20)
        batchNormalizationLayer
        reluLayer
        fullyConnectedLayer(numClasses)
        softmaxLayer];

    Specify the training options.

    • Train for four epochs using the SGDM solver.

    • Monitor the accuracy metric.

    options = trainingOptions("sgdm", ...
        MaxEpochs=4, ...
        Metrics="accuracy");

    Train the neural network. For classification, use cross-entropy loss. Return the trained network and the training information.

    [net,info] = trainnet(imds,layers,"crossentropy",options);
        Iteration    Epoch    TimeElapsed    LearnRate    TrainingLoss    TrainingAccuracy
        _________    _____    ___________    _________    ____________    ________________
                1        1       00:00:03         0.01          2.7615              3.9062
               50        1       00:00:20         0.01         0.48724              84.375
              100        2       00:00:35         0.01         0.16261              96.094
              150        2       00:00:49         0.01         0.10018              96.094
              200        3       00:01:08         0.01        0.056833                 100
              250        4       00:01:24         0.01        0.031866                 100
              300        4       00:01:36         0.01        0.021502                 100
              312        4       00:01:39         0.01        0.029409              99.219
    Training stopped: Max epochs completed
    

    View the training information.

    info
    info = 
      TrainingInfo with properties:
    
               TrainingHistory: [312x5 table]
             ValidationHistory: [0x0 table]
        OutputNetworkIteration: 312
                    StopReason: "Max epochs completed"
    
    

    Display the training information in a plot using the show function.

    show(info)

    Close the plot using the close function.

    close(info)

    Version History

    Introduced in R2023b