yscale
Description
Examples
Track Training Progress for Custom Training Loop
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:
Evaluate the
Stop
property at the start of each step in your custom training loop. When you click the Stop button in the Training Progress window, theStop
property changes to1
. Training stops if your training loop exits when theStop
property is1
.Update the information values. The updated values appear in the Training Progress window.
Record the metric values. The recorded values appear in the training plot.
Update the training progress percentage based on the fraction of iterations completed.
Note
The following example code is a template. You must edit this training loop to compute your metric and information values. For a complete example that you can run in MATLAB, see Monitor Custom Training Loop Progress 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.
The training plots update each time you call
recordMetrics
.The values under Information update each time you call
updateInfo
.The elapsed time updates each time you call
recordMetrics
orupdateInfo
and when you update the Progress property.
Track Experiment Progress, Display Information and Record Metric Values, and Produce Training Plots
Use an experiments.Monitor
object to track the progress of the training,
display information and metric values in the experiment results table, and produce
training plots for custom training experiments.
Before starting the training, specify the names of the information and metric columns of the Experiment Manager results table.
monitor.Info = ["GradientDecayFactor","SquaredGradientDecayFactor"]; monitor.Metrics = ["TrainingLoss","ValidationLoss"];
Specify the horizontal axis label for the training plot. Group the training and validation loss in the same subplot.
monitor.XLabel = "Iteration"; groupSubPlot(monitor,"Loss",["TrainingLoss","ValidationLoss"]);
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")
Update the values of the gradient decay factor and the squared gradient decay factor for the trial in the results table.
updateInfo(monitor, ... GradientDecayFactor=gradientDecayFactor, ... SquaredGradientDecayFactor=squaredGradientDecayFactor);
After each iteration of the custom training loop, record the value of training and validation loss for the trial in the results table and the training plot.
recordMetrics(monitor,iteration, ... TrainingLoss=trainingLoss, ... ValidationLoss=validationLoss);
Update the training progress for the trial based on the fraction of iterations completed.
monitor.Progress = 100 * (iteration/numIterations);
Input Arguments
monitor
— Metric monitor
TrainingProgressMonitor
object | experiments.Monitor
object
Metric monitor, specified as a TrainingProgressMonitor
or an experiments.Monitor
object.
axesName
— Name of plot axes
string | character array
Name of plot axes, specified as a string or a character array. The name of the axes
must match the name of a metric. If you use the groupSubPlot
function to group metrics, then axesName
must be the name of the
group.
Data Types: char
| string
scale
— Axis scale
"linear"
(default) | "log"
Axis scale, specified as one of these values.
Value | Description | Example |
---|---|---|
"linear" | Linear scale |
|
"log" | Log scale
Note When you specify a logarithmic scale, the axes might exclude coordinates in some cases:
|
|
Version History
Introduced in R2024a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)