Main Content

Experiment Manager

Design and run experiments to train and compare deep learning networks

Since R2020a

Description

The Experiment Manager app enables you to create deep learning experiments to train networks under multiple initial conditions and compare the results. For example, you can use deep learning experiments to:

  • Sweep through a range of hyperparameter values or use Bayesian optimization to find optimal training options. Bayesian optimization requires Statistics and Machine Learning Toolbox™.

  • Use the built-in function trainNetwork or define your own custom training function. The trainNetwork function requires Deep Learning Toolbox™.

  • Compare the results of using different data sets or test different deep network architectures.

To set up your experiment quickly, you can start with a preconfigured template. The experiment templates support workflows that include image classification and regression, sequence classification, audio classification, semantic segmentation, and custom training loops.

Experiment Manager provides visualization tools such as training plots and confusion matrices, filters to refine your experiment results, and annotations to record your observations. To improve reproducibility, every time that you run an experiment, Experiment Manager stores a copy of the experiment definition. You can access past experiment definitions to keep track of the hyperparameter combinations that produce each of your results.

Experiment Manager organizes your experiments and results in projects.

  • You can store several experiments in the same project.

  • Each experiment contains a set of results for each time that you run the experiment.

  • Each set of results consists of one or more trials corresponding to a different combination of hyperparameters.

By default, Experiment Manager runs one trial at a time. If you have Parallel Computing Toolbox™, you can configure your experiment to run multiple trials at the same time or to run a single trial at a time on multiple GPUs, on a cluster, or in the cloud. If you have MATLAB® Parallel Server™, you can also offload experiments as batch jobs in a remote cluster so that you can continue working or close your MATLAB session during training. For more information, see Use Experiment Manager to Train Networks in Parallel and Offload Experiments as Batch Jobs to Cluster.

The Experiment Browser pane displays the hierarchy of experiments and results in the project. For instance, this project has two experiments, each of which has several sets of results.

Experiment Browser showing two experiments. Experiment1 is a built-in training experiment with four results. Experiment2 is a custom training experiment with two results.

The blue flask indicates a built-in training experiment that uses the trainNetwork function. The green beaker indicates a custom training experiment that relies on a different training function. To open the configuration for an experiment and view its results, double-click the name of the experiment or a set of results.

Experiment Manager app

Open the Experiment Manager App

  • MATLAB Toolstrip: On the Apps tab, under Machine Learning and Deep Learning, click the app icon.

  • MATLAB command prompt: Enter experimentManager.

Examples

expand all

This example shows how to use the experiment template for image classification by sweeping hyperparameters. With this template, you can quickly set up a built-in training experiment that uses the trainNetwork function. The trainNetwork function requires Deep Learning Toolbox.

Open the example to load a project with a preconfigured experiment that you can inspect and run. To open the experiment, in the Experiment Browser pane, double-click Experiment1.

Alternatively, you can configure the experiment yourself by following these steps.

1. Open Experiment Manager. If a project is already open in MATLAB, Experiment Manager prompts you to load the current project. Otherwise, a dialog box provides links to the getting started tutorials and your recent projects, as well as buttons to create a new project or open an example from the documentation.

2. Under New, select Project. A dialog box lists several templates that support workflows including image classification and regression, sequence classification, audio classification, semantic segmentation, and custom training loops.

3. Under Image Classification Experiments, select Image Classification by Sweeping Hyperparameters.

4. Specify the name and location for the new project. Experiment Manager opens a new experiment in the project. The Experiment pane displays the description, hyperparameters, setup function, and metrics that define the experiment.

5. In the Description field, enter a description of the experiment:

Classification of digits, using various initial learning rates.

6. Under Hyperparameters, replace the value of myInitialLearnRate with 0.0025:0.0025:0.015. Verify that Strategy is set to Exhaustive Sweep.

7. Under Setup Function, click Edit. The setup function opens in MATLAB Editor. The setup function specifies the training data, network architecture, and training options for the experiment. In this experiment, the setup function has these sections:

  • Load Training Data defines image datastores containing the training and validation data for the experiment. The experiment uses the Digits data set, which consists of 10,000 28-by-28 pixel grayscale images of digits from 0 to 9, categorized by the digit they represent. For more information on this data set, see Image Data Sets.

  • Define Network Architecture defines the architecture for a simple convolutional neural network for deep learning classification.

  • Specify Training Options defines a trainingOptions object for the experiment. In this experiment, the setup function loads the values for the initial learning rate from the myInitialLearnRate entry in the hyperparameter table.

When you run the experiment, Experiment Manager trains the network defined by the setup function six times. Each trial uses one of the learning rates specified in the hyperparameter table. By default, Experiment Manager runs one trial at a time. If you have Parallel Computing Toolbox, you can run multiple trials at the same time or offload your experiment as a batch job in a cluster:

  • To run one trial of the experiment at a time, on the Experiment Manager toolstrip, under Mode, select Sequential and click Run.

  • To run multiple trials at the same time, under Mode, select Simultaneous and click Run. If there is no current parallel pool, Experiment Manager starts one using the default cluster profile. Experiment Manager then runs as many simultaneous trials as there are workers in your parallel pool. For best results, before you run your experiment, start a parallel pool with as many workers as GPUs. For more information, see Use Experiment Manager to Train Networks in Parallel and GPU Computing Requirements (Parallel Computing Toolbox).

  • To offload the experiment as a batch job, under Mode, select Batch Sequential or Batch Simultaneous, specify your Cluster and Pool Size, and click Run. For more information, see Offload Experiments as Batch Jobs to Cluster.

A table of results displays the accuracy and loss for each trial.

To display the training plot and track the progress of each trial while the experiment is running, under Review Results, click Training Plot. You can also monitor the training progress in the MATLAB Command Window.

To display the confusion matrix for the validation data in each completed trial, under Review Results, click Validation Data.

When the experiment finishes, you can sort the table by column or filter trials by using the Filters pane. You can also record observations by adding annotations to the results table. For more information, see Sort, Filter, and Annotate Experiment Results.

To test the performance of an individual trial, export the trained network or the training information for the trial. On the Experiment Manager toolstrip, select Export > Trained Network or Export > Training Information, respectively. For more information, see net and info. To save the contents of the results table as a table array in the MATLAB workspace, select Export > Results Table.

To close the experiment, in the Experiment Browser pane, right-click the name of the project and select Close Project. Experiment Manager closes all of the experiments and results contained in the project.

This example shows how to use the experiment template for image regression by sweeping hyperparameters. With this template, you can quickly set up a built-in training experiment that uses the trainNetwork function. The trainNetwork function requires Deep Learning Toolbox.

Open the example to load a project with a preconfigured experiment that you can inspect and run. To open the experiment, in the Experiment Browser pane, double-click Experiment1.

Alternatively, you can configure the experiment yourself by following these steps.

1. Open Experiment Manager. If a project is already open in MATLAB, Experiment Manager prompts you to load the current project. Otherwise, a dialog box provides links to the getting started tutorials and your recent projects, as well as buttons to create a new project or open an example from the documentation.

2. Under New, select Project. A dialog box lists several templates that support workflows including image classification and regression, sequence classification, audio classification, semantic segmentation, and custom training loops.

3. Under Image Regression Experiments, select Image Regression by Sweeping Hyperparameters.

4. Specify the name and location for the new project. Experiment Manager opens a new experiment in the project. The Experiment pane displays the description, hyperparameters, setup function, and metrics that define the experiment.

5. In the Description field, enter a description of the experiment:

Regression to predict angles of rotation of digits, using various initial learning rates.

6. Under Hyperparameters, replace the value of myInitialLearnRate with 0.001:0.001:0.006. Verify that Strategy is set to Exhaustive Sweep.

7. Under Setup Function, click Edit. The setup function opens in MATLAB Editor. The setup function specifies the training data, network architecture, and training options for the experiment. In this experiment, the setup function has these sections:

  • Load Training Data defines the training and validation data for the experiment as 4-D arrays. The training and validation data each consist of 5000 images from the Digits data set. Each image shows a digit from 0 to 9, rotated by a certain angle. The regression values correspond to the angles of rotation. For more information on this data set, see Image Data Sets.

  • Define Network Architecture defines the architecture for a simple convolutional neural network for deep learning regression.

  • Specify Training Options defines a trainingOptions object for the experiment. In this experiment, the setup function loads the values for the initial learning rate from the myInitialLearnRate entry in the hyperparameter table.

When you run the experiment, Experiment Manager trains the network defined by the setup function six times. Each trial uses one of the learning rates specified in the hyperparameter table. By default, Experiment Manager runs one trial at a time. If you have Parallel Computing Toolbox, you can run multiple trials at the same time or offload your experiment as a batch job in a cluster:

  • To run one trial of the experiment at a time, on the Experiment Manager toolstrip, under Mode, select Sequential and click Run.

  • To run multiple trials at the same time, under Mode, select Simultaneous and click Run. If there is no current parallel pool, Experiment Manager starts one using the default cluster profile. Experiment Manager then runs as many simultaneous trials as there are workers in your parallel pool. For best results, before you run your experiment, start a parallel pool with as many workers as GPUs. For more information, see Use Experiment Manager to Train Networks in Parallel and GPU Computing Requirements (Parallel Computing Toolbox).

  • To offload the experiment as a batch job, under Mode, select Batch Sequential or Batch Simultaneous, specify your Cluster and Pool Size, and click Run. For more information, see Offload Experiments as Batch Jobs to Cluster.

A table of results displays the root mean squared error (RMSE) and loss for each trial.

To display the training plot and track the progress of each trial while the experiment is running, under Review Results, click Training Plot. You can also monitor the training progress in the MATLAB Command Window.

When the experiment finishes, you can sort the table by column or filter trials by using the Filters pane. You can also record observations by adding annotations to the results table. For more information, see Sort, Filter, and Annotate Experiment Results.

To test the performance of an individual trial, export the trained network or the training information for the trial. On the Experiment Manager toolstrip, select Export > Trained Network or Export > Training Information, respectively. For more information, see net and info. To save the contents of the results table as a table array in the MATLAB workspace, select Export > Results Table.

To close the experiment, in the Experiment Browser pane, right-click the name of the project and select Close Project. Experiment Manager closes all of the experiments and results contained in the project.

This example shows how to use the training experiment template for image classification using a custom training loop. With this template, you can quickly set up a custom training experiment.

Open the example to load a project with a preconfigured experiment that you can inspect and run. To open the experiment, in the Experiment Browser pane, double-click Experiment1.

Alternatively, you can configure the experiment yourself by following these steps.

1. Open Experiment Manager. If a project is already open in MATLAB, Experiment Manager prompts you to load the current project. Otherwise, a dialog box provides links to the getting started tutorials and your recent projects, as well as buttons to create a new project or open an example from the documentation.

2. Under New, select Project. A dialog box lists several templates that support workflows including image classification and regression, sequence classification, audio classification, semantic segmentation, and custom training loops.

3. Under Image Classification Experiments, select Image Classification Using Custom Training Loop.

4. Select the location and name for a new project. Experiment Manager opens a new experiment in the project. The Experiment pane displays the description, hyperparameters, and training function that define the experiment.

3. In the Description field, enter a description of the experiment:

Classification of digits, using various initial learning rates.

4. Under Hyperparameters, replace the value of myInitialLearnRate with 0.0025:0.0025:0.015. Verify that Strategy is set to Exhaustive Sweep.

5. Under Training Function, click Edit. The training function opens in MATLAB Editor. The training function specifies the training data, network architecture, training options, and training procedure used by the experiment. In this experiment, the training function has these sections:

  • Load Training Data defines the training data for the experiment as 4-D arrays. The experiment uses the Digits data set, which consists of 5,000 28-by-28 pixel grayscale images of digits from 0 to 9, categorized by the digit they represent. For more information on this data set, see Image Data Sets.

  • Define Network Architecture defines the architecture for a simple convolutional neural network for deep learning classification. To train the network with a custom training loop, the training function represents the network as a dlnetwork object.

  • Specify Training Options defines the training options used by the experiment. In this experiment, the training function loads the values for the initial learning rate from the myInitialLearnRate entry in the hyperparameter table.

  • Train Model defines the custom training loop used by the experiment. For each epoch, the custom training loop shuffles the data and iterates over mini-batches of data. For each mini-batch, the custom training loop evaluates the model gradients, state, and loss, determines the learning rate for the time-based decay learning rate schedule, and updates the network parameters. To track the progress of the training and record the value of the training loss, the training function uses the experiments.Monitor object monitor.

When you run the experiment, Experiment Manager trains the network defined by the training function six times. Each trial uses one of the learning rates specified in the hyperparameter table. By default, Experiment Manager runs one trial at a time. If you have Parallel Computing Toolbox, you can run multiple trials at the same time or offload your experiment as a batch job in a cluster:

  • To run one trial of the experiment at a time, on the Experiment Manager toolstrip, under Mode, select Sequential and click Run.

  • To run multiple trials at the same time, under Mode, select Simultaneous and click Run. If there is no current parallel pool, Experiment Manager starts one using the default cluster profile. Experiment Manager then runs as many simultaneous trials as there are workers in your parallel pool. For best results, before you run your experiment, start a parallel pool with as many workers as GPUs. For more information, see Use Experiment Manager to Train Networks in Parallel and GPU Computing Requirements (Parallel Computing Toolbox).

  • To offload the experiment as a batch job, under Mode, select Batch Sequential or Batch Simultaneous, specify your Cluster and Pool Size, and click Run. For more information, see Offload Experiments as Batch Jobs to Cluster.

A table of results displays the training loss for each trial.

To display the training plot and track the progress of each trial while the experiment is running, under Review Results, click Training Plot.

When the experiment finishes, you can sort the table by column or filter trials by using the Filters pane. You can also record observations by adding annotations to the results table. For more information, see Sort, Filter, and Annotate Experiment Results.

To test the performance of an individual trial, export the training output for the trial. On the Experiment Manager toolstrip, select Export > Training Output. In this experiment, the training output is a structure that contains the values of the training loss and the trained network. To save the contents of the results table as a table array in the MATLAB workspace, select Export > Results Table.

To close the experiment, in the Experiment Browser pane, right-click the name of the project and select Close Project. Experiment Manager closes all of the experiments and results contained in the project.

This example shows how to set up a built-in training experiment using Experiment Manager. Built-in training experiments rely on the trainNetwork function and support workflows such as image classification, image regression, sequence classification, and semantic segmentation. The trainNetwork function requires Deep Learning Toolbox.

Built-in training experiments consist of a description, a table of hyperparameters, a setup function, and a collection of metric functions to evaluate the results of the experiment.

In the Description field, enter a description of the experiment.

Under Hyperparameters, select the strategy and specify the hyperparameters to use for your experiment:

 Exhaustive Sweep

 Bayesian Optimization

The Setup Function configures the training data, network architecture, and training options for the experiment. The input to the setup function is a structure with fields from the hyperparameter table. The output of the setup function must match the input of the trainNetwork function. This table lists the supported signatures for the setup function.

Goal of ExperimentSetup Function Signature
Train a network for image classification and regression tasks using the images and responses specified by images and the training options defined by options.
function [images,layers,options] = Experiment_setup(params)
...
end
Train a network using the images specified by images and responses specified by responses.
function [images,responses,layers,options] = Experiment_setup(params)
...
end
Train a network for sequence or time-series classification and regression tasks (for example, an LSTM or GRU network) using the sequences and responses specified by sequences.
function [sequences,layers,options] = Experiment_setup(params)
...
end
Train a network using the sequences specified by sequences and responses specified by responses.
function [sequences,reponses,layers,options] = Experiment_setup(params)
...
end
Train a network for feature classification or regression tasks (for example, a multilayer perceptron, or MLP, network) using the feature data and responses specified by features.
function [features,layers,options] = Experiment_setup(params)
...
end
Train a network using the feature data specified by features and responses specified by responses.
function [features,responses,layers,options] = Experiment_setup(params)
...
end

Tip

When writing your setup function, follow these guidelines:

  • Load training and validation data from a location that is accessible to all your workers. For example, store your data outside the project and access the data by using an absolute path. Alternatively, create a datastore object that can access the data on another machine by setting up the AlternateFileSystemRoots property of the datastore. For more information, see Set Up Datastore for Processing on Different Machines or Clusters.

  • For networks containing batch normalization layers, if the BatchNormalizationStatistics training option is population, Experiment Manager displays final validation metric values that are often different from the validation metrics evaluated during training. The difference in values is the result of additional operations performed after the network finishes training. For more information, see Batch Normalization Layer.

  • The execution modes that you can use for your experiment depend on the settings you specify for the training options ExecutionEnvironment and DispatchInBackground.

    Execution ModeValid Settings for ExecutionEnvironmentValid Settings for DispatchInBackground
    Sequential"auto", "cpu", "gpu", "multi-gpu", "parallel"true, false
    Simultaneous"auto", "cpu", "gpu"false
    Batch Sequential"auto", "cpu", "gpu", "parallel"true, false
    Batch Simultaneous"auto", "cpu", "gpu"false

    For more information, see Use Experiment Manager to Train Networks in Parallel and Offload Experiments as Batch Jobs to Cluster.

The Metrics section specifies functions to evaluate the results of the experiment. The input to a metric function is a structure with three fields:

The output of a metric function must be a scalar number, a logical value, or a string.

If your experiment uses Bayesian optimization, select a metric to optimize from the Optimize list. In the Direction list, specify that you want to Maximize or Minimize this metric. Experiment Manager uses this metric to determine the best combination of hyperparameters for your experiment. You can choose a standard training or validation metric (such as accuracy, RMSE, or loss) or a custom metric from the table.

This example shows how to set up a custom training experiment using Experiment Manager. Custom training experiments support workflows that require a training function other than trainNetwork. These workflows include:

  • Training a network that is not defined by a layer graph.

  • Training a network using a custom learning rate schedule.

  • Updating the learnable parameters of a network by using a custom function.

  • Training a generative adversarial network (GAN).

  • Training a Siamese network.

Custom training experiments consist of a description, a table of hyperparameters, and a training function.

In the Description field, enter a description of the experiment.

Under Hyperparameters, select the strategy and specify the hyperparameters to use for your experiment:

 Exhaustive Sweep

 Bayesian Optimization

The Training Function specifies the training data, network architecture, training options, and training procedure used by the experiment. The inputs to the training function are:

  • A structure with fields from the hyperparameter table

  • An experiments.Monitor object that you can use to track the progress of the training, update information fields in the results table, record values of the metrics used by the training, and produce training plots

Experiment Manager saves the output of the training function, so you can export it to the MATLAB workspace when the training is complete.

Tip

When writing your training function, follow these guidelines:

  • Load training and validation data from a location that is accessible to all your workers. For example, store your data outside the project and access the data by using an absolute path. Alternatively, create a datastore object that can access the data on another machine by setting up the AlternateFileSystemRoots property of the datastore. For more information, see Set Up Datastore for Processing on Different Machines or Clusters.

  • Both information and metric columns display numerical values in the results table for your experiment. Additionally, metric values are recorded in the training plot. Use information columns for values that you want to display in the results table but not in the training plot.

  • When the training is complete, the Review Results gallery in the toolstrip displays a button for each figure that you create in your training function (since R2023a). To display a figure in the Visualizations pane, click the corresponding button in the Custom Plot section of the gallery. Specify the name of the button by using the Name property of the figure. If you do not name your figure, Experiment Manager derives the name of the button from the axes or figure title.

If your experiment uses Bayesian optimization, in the Metrics section, under Optimize, enter the name of a metric to optimize. In the Direction list, specify that you want to Maximize or Minimize this metric. Experiment Manager uses this metric to determine the best combination of hyperparameters for your experiment. You can choose any metric that you define using the experiments.Monitor object for the training function.

Experiment Manager provides two options for interrupting experiments:

  • Stop marks any running trials as Stopped and saves their results. When the experiment stops, you can display the training plot and export the training results for these trials.

  • Cancel marks any running trials as Canceled and discards their results. When the experiment stops, you cannot display the training plot or export the training results for these trials.

Both options save the results of any completed trials and cancel any queued trials. Typically, Cancel is faster than Stop.

Instead of interrupting the entire experiment, you can stop an individual trial that is running or cancel an individual queued trial. In the Actions column of the results table, click the Stop button or the Cancel button for the trial.

Results table showing Stop icon for a running trial.

To reduce the size of your experiments, discard the results of trials that are no longer relevant. In the Actions column of the results table, click the Discard button for a trial. Experiment Manager deletes the training results, training plot, and confusion matrix for the trial from your project.

Results table showing Discard icon for a completed trial.

When the training is complete, you can restart a trial that you stopped, canceled, or discarded. In the Actions column of the results table, click the Restart button for the trial.

Results table showing Restart icon for a stopped trial.

Alternatively, to restart multiple trials, in the Experiment Manager toolstrip, open the Restart list, select one or more restarting criteria, and click Restart . Restarting criteria include All Canceled, All Stopped, All Error, and All Discarded.

Note

Stop, cancel, and restart options are not available for all experiment types, strategies, or execution modes.

This example shows how to compare your results and record your observations after running an experiment.

When you run an experiment, Experiment Manager trains the network defined by the setup function multiple times. Each trial uses a different combination of hyperparameters. When the experiment finishes, a table displays training and validation metrics (such as RMSE and loss) for each trial. To compare the results of an experiment, you can use these metrics to sort the results table and filter trials.

To sort the trials in the results table, use the drop-down list for the column corresponding to a training or validation metric.

  1. Point to the header of a column by which you want to sort.

  2. Click the triangle icon.

  3. Select Sort in Ascending Order or Sort in Descending Order.

    Results table showing drop down list for the Validation Accuracy column.

To filter trials from the results table, use the Filters pane. This pane shows histograms for the numeric metrics in the results table. To remove a histogram from the Filters pane, in the results table, open the drop-down list for the corresponding column and clear the Show Filter check box.

  1. On the Experiment Manager toolstrip, select Filters.

  2. Adjust the sliders under the histogram for the training or validation metric by which you want to filter.

    Histogram for Validation Accuracy, with filter sliders set to 60 and 62.

    The results table shows only the trials with a metric value in the selected range.

    Results table showing only trials with Validation Accuracy between 60 and 62.

  3. To restore all of the trials in the results table, close the Experiment Result pane and reopen the results from the Experiment Browser pane.

To record observations about the results of your experiment, add an annotation.

  1. Right-click a cell in the results table and select Add Annotation. Alternatively, select a cell in the results table and, on the Experiment Manager toolstrip, select Annotations > Add Annotation.

    Results table showing drop down list for the Validation Accuracy cell with the largest value.

  2. In the Annotations pane, enter your observations in the text box. You can add multiple annotations for each cell in the results table.

    Annotation text says, "Largest validation accuracy."

  3. To sort annotations, use the Sort By drop-down list. You can sort by creation time or trial number.

    Sorting options include: Creation Time: Older to Newer (Default), Creation Time: Newer to Older, Trial Number: Lowest to Highest, and Trial Number: Highest to Lowest.

  4. To highlight the cell that corresponds to an annotation, click the link above the annotation.

  5. To delete an annotation, click the delete button to the right of the annotation.

This example shows how to inspect the configuration of an experiment that produced a given result.

After you run an experiment, you can open the Experiment Source pane to see a read-only copy of the experiment description and hyperparameter table, as well as links to all of the functions used by the experiment. You can use the information in this pane to track the configuration of data, network, and training options that produces each of your results.

For instance, suppose that you run an experiment multiple times. Each time that you run the experiment, you change the contents of the setup function but always use the same function name. The first time that you run the experiment, you use the default network provided by the experiment template for image classification. The second time that you run the experiment, you modify the setup function to load a pretrained GoogLeNet network, replacing the final layers with new layers for transfer learning. For an example that uses these two network architectures, see Create a Deep Learning Experiment for Classification.

On the first Experiment Result pane, click the View Experiment Source link. Experiment Manager opens an Experiment Source pane that contains the experiment definition that produced the first set of results. Click the link at the bottom of the pane to open the setup function that you used the first time you ran the experiment. You can copy this setup function to rerun the experiment using the simple classification network.

On the second Experiment Result pane, click the View Experiment Source link. Experiment Manager opens an Experiment Source pane that contains the experiment definition that produced the second set of results. Click the link at the bottom of the pane to open the setup function that you used the second time you ran the experiment. You can copy this setup function to rerun the experiment using transfer learning.

Experiment Manager stores a copy of all the functions that you use, so you do not have to manually rename these functions when you modify and rerun an experiment.

Related Examples

Tips

Version History

Introduced in R2020a

expand all