groupSubPlot - Group metrics in training plot - MATLAB (original) (raw)

Group metrics in training plot

Since R2022b

Syntax

Description

groupSubPlot([monitor](#mw%5F6253c844-b9b4-48a0-8c57-c68c28504221),[groupName](#mw%5F5a9f87f1-8780-4fd6-847c-4b61fa0b65cb),[metricNames](#mw%5F71fa6bff-91be-4bf5-869c-9143f42529e4)) groups the specified metrics in a single training subplot with the _y_-axis label groupName. By default, the software plots each ungrouped metric in its own training subplot.

To group metrics, all metrics must have the same y-axis scale. For more information, seeyscale.

example

Examples

collapse all

Use a TrainingProgressMonitor object to track training progress and produce training plots for custom training loops.

Create a TrainingProgressMonitor object. The monitor automatically tracks the start time and the elapsed time. The timer starts when you create the object.

Tip

To ensure that the elapsed time accurately reflects the training time, make sure you create the TrainingProgressMonitor object close to the start of your custom training loop.

monitor = trainingProgressMonitor;

Before you start the training, specify names for the information and metric values.

monitor.Info = ["LearningRate","Epoch","Iteration"]; monitor.Metrics = ["TrainingLoss","ValidationLoss","TrainingAccuracy","ValidationAccuracy"];

Specify the horizontal axis label for the training plot. Group the training and validation loss in the same subplot. Group the training and validation accuracy in the same plot.

monitor.XLabel = "Iteration"; groupSubPlot(monitor,"Loss",["TrainingLoss","ValidationLoss"]); groupSubPlot(monitor,"Accuracy",["TrainingAccuracy","ValidationAccuracy"]);

Specify a logarithmic scale for the loss. You can also switch the y-axis scale by clicking the log scale button in the axes toolbar.

yscale(monitor,"Loss","log")

During training:

epoch = 0; iteration = 0;

monitor.Status = "Running";

while epoch < maxEpochs && ~monitor.Stop epoch = epoch + 1;

while hasData(mbq) && ~monitor.Stop
    iteration = iteration + 1;

    % Add code to calculate metric and information values.
    % lossTrain = ...

   updateInfo(monitor, ...
        LearningRate=learnRate, ...
        Epoch=string(epoch) + " of " + string(maxEpochs), ...
        Iteration=string(iteration) + " of " + string(numIterations));

   recordMetrics(monitor,iteration, ...
        TrainingLoss=lossTrain, ...
        TrainingAccuracy=accuracyTrain, ...
        ValidationLoss=lossValidation, ...
        ValidationAccuracy=accuracyValidation);

    monitor.Progress = 100*iteration/numIterations;
end

end

The Training Progress window shows animated plots of the metrics, as well as the information values, training progress bar, and elapsed time.

Training Progress window. The first plot shows the training and validation loss and the second plot shows the training and validation accuracy.

Input Arguments

collapse all

Name of the subplot group, specified as a string scalar or character vector. The software groups the specified metrics in a single training subplot with the_y_-axis label groupName.

Data Types: char | string

Metric names, specified as a string scalar, character vector, string array, or cell array of character vectors. Each metric name must be an element of the Metrics property of monitor and can only appear in one subplot.

Data Types: char | string | cell

Version History

Introduced in R2022b