Main Content

rmseMetric

Deep learning root mean squared error metric

Since R2023b

    Description

    Use a RMSEMetric object to track the root mean squared error (RMSE) when you train a deep neural network.

    To specify which metrics to use during training, specify the Metrics option of the trainingOptions function. You can use this option only when you train a network using the trainnet function.

    To plot the metrics during training, in the training options, specify Plots as "training-progress". If you specify the ValidationData training option, then the software also plots and records the metric values for the validation data. To output the metric values to the Command Window during training, in the training options, set Verbose to true.

    You can also access the metrics after training using the TrainingHistory and ValidationHistory fields from the second output of the trainnet function.

    Creation

    Description

    example

    metric = rmseMetric creates a RMSEMetric object. You can then specify metric as the Metrics name-value argument in the trainingOptions function.

    With no additional options specified, this syntax is equivalent to setting Metrics="rmse" in the training options.

    metric = rmseMetric(Name=Value) sets the Name, NetworkOutput, and NormalizationFactor properties using name-value arguments.

    Properties

    expand all

    Metric name, specified as a string scalar or character vector. The metric name appears in the training plot, the verbose output, and the training information that you can access as the second output of the trainnet function.

    Data Types: char | string

    This property is read-only.

    Name of the layer to apply the metric to, specified as [], a string scalar, or a character vector. When the value is [], the software passes all of the network outputs to the metric.

    Note

    You can apply the built-in metric to only a single output. If you have a network with multiple outputs, then you must specify the NetworkOutput name-value argument. To apply built-in metrics to multiple outputs, you must create a metric object for each output.

    Data Types: char | string

    This property is read-only.

    Divisor for normalizing the RMSE sum, specified as one of these values:

    • "batch-size" — Divide the RMSE sum by the number of elements in the targets.

    • "all-elements" — Divide the RMSE sum by the number of observations.

    Data Types: char | string

    This property is read-only.

    Flag to maximize metric, specified as 0 (false) if the optimal value for the metric occurs when the metric is minimized.

    For this metric, the Maximize value is always set to 0 (false).

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Object Functions

    trainingOptionsOptions for training deep learning neural network
    trainnetTrain deep learning neural network

    Examples

    collapse all

    Plot and record the training and validation RMSE when you train a deep neural network.

    Load the training and test data from the DigitsDataTrain and DigitsDataTest MAT files, respectively. The data set contains synthetic images of handwritten digits and the corresponding angles (in degrees) by which each image is rotated. The anglesTrain and anglesTest variables are the rotation angles in degrees.

    load DigitsDataTrain.mat
    load DigitsDataTest.mat

    You can train a deep learning network to predict the rotation angle of the digit.

    Create an image regression network.

    layers = [
        imageInputLayer([28 28 1])
        convolution2dLayer(3,8,Padding="same")
        batchNormalizationLayer
        reluLayer
        averagePooling2dLayer(2,'Stride',2)
        convolution2dLayer(3,16,Padding="same")
        batchNormalizationLayer
        reluLayer
        averagePooling2dLayer(2,'Stride',2)
        convolution2dLayer(3,32,Padding="same")
        batchNormalizationLayer
        reluLayer
        convolution2dLayer(3,32,Padding="same")
        batchNormalizationLayer
        reluLayer
        dropoutLayer(0.2)
        fullyConnectedLayer(1)];

    Create an RMSEMetric object and set the NormalizationFactor property to "batch-size". You can use this object to record and plot the training and validation RMSE.

    metric = rmseMetric(NormalizationFactor="batch-size")
    metric = 
      RMSEMetric with properties:
    
                       Name: "RMSE"
        NormalizationFactor: "batch-size"
              NetworkOutput: []
                   Maximize: 0
    
    

    Specify the RMSE metric in the training options. To plot the RMSE during training, set Plots to "training-progress". To output the values during training, set Verbose to true.

    options = trainingOptions("adam", ...
        MaxEpochs=5, ...
        Metrics=metric, ...
        ValidationData={XTest,anglesTest}, ...
        ValidationFrequency=50, ...
        Plots="training-progress", ...
        Verbose=true);

    Train the network using the trainnet function.

    [net,info] = trainnet(XTrain,anglesTrain,layers,"mse",options);
        Iteration    Epoch    TimeElapsed    LearnRate    TrainingLoss    ValidationLoss    TrainingRMSE    ValidationRMSE
        _________    _____    ___________    _________    ____________    ______________    ____________    ______________
                0        0       00:00:01        0.001                            688.66                            26.242
                1        1       00:00:01        0.001          648.74                             25.47                  
               50        2       00:00:17        0.001          210.69            324.08          14.515            18.002
              100        3       00:00:29        0.001          130.83             126.2          11.438            11.234
              150        4       00:00:41        0.001          90.575            106.45          9.5171            10.317
              195        5       00:00:52        0.001          88.361            100.23          9.4001            10.012
    Training stopped: Max epochs completed
    

    Access the loss and RMSE values for the validation data.

    info.ValidationHistory
    ans=5×3 table
        Iteration     Loss      RMSE 
        _________    ______    ______
    
             0       688.66    26.242
            50       324.08    18.002
           100        126.2    11.234
           150       106.45    10.317
           195       100.23    10.012
    
    

    More About

    expand all

    Version History

    Introduced in R2023b