Main Content

Debug Deep Learning Experiments

Since R2023a

In Experiment Manager, you use MATLAB® functions to configure the training data, network architecture, and training options, specify the training procedure, and evaluate the results of your deep learning experiment. You can diagnose problems in these functions by stepping through your code line-by-line and examining the values of your variables.

Start Debugging Session

You can debug your code before or after you run the experiment.

To debug your code before you run the experiment:

  1. Open the experiment.

  2. In the Experiment Manager toolstrip, select Run > Debug .

  3. In dialog box, specify the hyperparameter values for your experiment.

  4. Click Start.

To debug your code after you run the experiment:

  1. Open the results for the experiment.

  2. In the results table, select a trial to debug. To ensure reproducibility, Experiment Manager reuses the hyperparameter values and the random seed saved for this trial.

  3. Right-click the trial and select Debug .

Experiment Manager opens the setup or training function in MATLAB Editor, places a breakpoint in the first line of code, and runs the function.

Experiment Manager sets a breakpoint on the first line of code in your setup or training function.

Debug Setup and Training Functions

When you debug your setup or training function, MATLAB pauses at each line of code that has a breakpoint. Then you can add other breakpoints to your function, view the values of your variables, step through the code line-by-line, or continue to the next breakpoint. For more information, see Debug MATLAB Code Files.

If you are debugging a custom training experiment, the Training Progress window plots the metric values for your experiment. For more information, see Monitor Custom Training Loop Progress.

Tip

To examine the values stored in the MetricData and InfoData properties of the trainingProgressMonitor object associated with the Training Progress window, pause the execution before you reach the end of your training function. When the function runs to completion, Experiment Manager closes the Training Progress window and deletes the trainingProgressMonitor object.

Verify Your Results

After your function runs to completion, verify your results by examining the hyperparameters and output values stored in the workspace variables

  • functionName_params — A structure with fields from the Experiment Manager hyperparameter table

  • functionName_output — A cell array that contains the output values returned by the setup or training function

where functionName is the name of the setup or training function.

Debug Metric Functions

After you debug the setup function for a built-in training experiment, you can inspect the training data and training options in the MATLAB Workspace browser or visualize the network layers in the Deep Network Designer app. You can also call the built-in training function trainNetwork and step through your metric functions:

  1. In the MATLAB Command Window, call trainNetwork using the output of your setup function. For example, if your setup function is called RegressionExperiment_setup, enter:

    [tNet,tInfo] = trainNetwork(RegressionExperiment_setup_output{:});
  2. Create a structure called trialInfo that contains the fields trainedNetwork, trainingInfo, and parameters. For values, use the outputs of the trainNetwork function and the hyperparameters used for training. For example, if your setup function is called RegressionExperiment_setup, enter:

    trialInfo = struct(trainedNetwork=tNet, ...
        trainingInfo=tInfo, ...
        parameters=RegressionExperiment_setup_params);
  3. In Experiment Manager, in the experiment definition tab, under Metrics, select the name of a metric function and click Edit. The metric function opens in MATLAB Editor.

  4. In the metric function, set breakpoints as described in Set Breakpoints.

    Set a breakpoint on a line of code in the metric function.

  5. In the MATLAB Command Window, call the metric function using the trialInfo structure as the input to the function. For example, if your metric function is called Accuracy, enter:

    metricOutput = Accuracy(trialInfo)

    MATLAB pauses at each line of code that has a breakpoint. When the function execution stops at the breakpoint, you can view the values of your variables, step through the code line-by-line, or continue to the next breakpoint. After the function runs to completion, examine the output value. The output must be a scalar number, a logical value, or a string.

See Also

Apps

Functions

Objects

Related Topics