activations - (Not recommended) Compute deep learning network layer activations - MATLAB (original) (raw)

(Not recommended) Compute deep learning network layer activations

Syntax

Description

You can compute deep learning network layer activations on either a CPU or GPU. Using a GPU requires a Parallel Computing Toolbox™ license and a supported GPU device. For information about supported devices, seeGPU Computing Requirements (Parallel Computing Toolbox). Specify the hardware requirements using theExecutionEnvironment name-value argument.

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations([net](#d126e4116),[images](#mw%5F70f86305-04b8-41c4-9276-0d1a9bcb9e96%5Fsep%5Fmw%5F99c47767-d581-463d-a32e-fd1427314607),[layer](#d126e5498)) returns the network activations for the layer with name or numberlayer using the specified images.

example

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations([net](#d126e4116),[sequences](#mw%5F70f86305-04b8-41c4-9276-0d1a9bcb9e96%5Fsep%5Fmw%5F86d8ee87-82c1-4872-85eb-a67e710ba850),[layer](#d126e5498)) returns the network activations for the layer using the specified sequences.

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations([net](#d126e4116),[features](#mw%5F70f86305-04b8-41c4-9276-0d1a9bcb9e96%5Fsep%5Fmw%5F783e4ab8-2920-4f09-94e7-019a462a52c0),[layer](#d126e5498)) returns the network activations for the layer using the specified feature data.

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations([net](#d126e4116),[X1,...,XN](#mw%5F70f86305-04b8-41c4-9276-0d1a9bcb9e96%5Fsep%5Fmw%5Fca2bcb5b-09ef-4e31-b103-c4100ac1a741),[layer](#d126e5498)) returns the network activations for the layer using the data in the numeric or cell arrays X1, …, XN for the multi-input network net. The input Xi corresponds to the network input net.InputNames(i).

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations([net](#d126e4116),[mixed](#mw%5F70f86305-04b8-41c4-9276-0d1a9bcb9e96%5Fsep%5Fmw%5Fb88600ab-1c39-4500-aaa1-813282327d59),[layer](#d126e5498)) returns the network activations for the layer using the trained networknet with multiple inputs of mixed data types.

[act](#mw%5Fb65e2845-af4a-42ab-ae94-cbd612c5324b) = activations(___,[Name=Value](#namevaluepairarguments)) returns network activations with additional options specified by one or more name-value pair arguments. For example, OutputAs="rows" specifies the activation output format as "rows". Use this syntax with any of the input arguments in previous syntaxes. Specify name-value arguments after all other input arguments.

Examples

collapse all

Visualize the activations of a neural network.

Load a pretrained SqueezeNet neural network.

Read an example image.

I = imread("peppers.png");

Evaluate the network activations for the layer with the name"fire2-squeeze1x1".

act = activations(net,I,"fire2-squeeze1x1");

Display the activations for each channel.

act = mat2gray(act); act = imtile(act); figure imshow(act)

montage plot showing neural network activations

Input Arguments

collapse all

Trained network, specified as a SeriesNetwork or a DAGNetwork object. You can get a trained network by importing a pretrained network (for example, by using the googlenet function) or by training your own network usingtrainNetwork.

Image data, specified as one of the following.

Data Type Description Example Usage
Datastore ImageDatastore Datastore of images saved on disk Make predictions with images saved on disk, where the images are the same size.When the images are different sizes, use anAugmentedImageDatastore object.
augmentedImageDatastore Datastore that applies random affine geometric transformations, including resizing, rotation, reflection, shear, and translation Make predictions with images saved on disk, where the images are different sizes.
TransformedDatastore Datastore that transforms batches of data read from an underlying datastore using a custom transformation function Transform datastores with outputs not supported byactivations.Apply custom transformations to datastore output.
CombinedDatastore Datastore that reads from two or more underlying datastores Make predictions using networks with multiple inputs.Combine predictors from different data sources.
Custom mini-batch datastore Custom datastore that returns mini-batches of data Make predictions using data in a format that other datastores do not support.For details, see Develop Custom Mini-Batch Datastore.
Numeric array Images specified as a numeric array Make predictions using data that fits in memory and does not require additional processing like resizing.
Table Images specified as a table Make predictions using data stored in a table.

When you use a datastore with networks with multiple inputs, the datastore must be aTransformedDatastore orCombinedDatastore object.

Tip

For sequences of images, for example, video data, use the sequences input argument.

Datastore

Datastores read mini-batches of images and responses. Use datastores when you have data that does not fit in memory or when you want to resize the input data.

These datastores are directly compatible with activations for image data.:

Tip

Use augmentedImageDatastore for efficient preprocessing of images for deep learning, including image resizing. Do not use the ReadFcn option ofImageDatastore objects.

ImageDatastore allows batch reading of JPG or PNG image files using prefetching. If you set the ReadFcn option to a custom function, then ImageDatastore does not prefetch and is usually significantly slower.

You can use other built-in datastores for making predictions by using the transform andcombine functions. These functions can convert the data read from datastores to the format required by classify.

The required format of the datastore output depends on the network architecture.

Network Architecture Datastore Output Example Output
Single input Table or cell array, where the first column specifies the predictors.Table elements must be scalars, row vectors, or 1-by-1 cell arrays containing a numeric array.Custom datastores must output tables. data = read(ds) data = 4×1 table Predictors __________________ {224×224×3 double} {224×224×3 double} {224×224×3 double} {224×224×3 double}
data = read(ds) data = 4×1 cell array {224×224×3 double} {224×224×3 double} {224×224×3 double} {224×224×3 double}
Multiple input Cell array with at least numInputs columns, wherenumInputs is the number of network inputs.The first numInputs columns specify the predictors for each input.The order of inputs is given by theInputNames property of the network. data = read(ds) data = 4×2 cell array {224×224×3 double} {128×128×3 double} {224×224×3 double} {128×128×3 double} {224×224×3 double} {128×128×3 double} {224×224×3 double} {128×128×3 double}

The format of the predictors depends on the type of data.

Data Format
2-D images _h_-by-w_-by-c numeric array, where h, w, and_c are the height, width, and number of channels of the images, respectively
3-D images _h_-by-_w_-by-_d_-by-c numeric array, where h, w,d, and c are the height, width, depth, and number of channels of the images, respectively

For more information, see Datastores for Deep Learning.

Numeric Array

For data that fits in memory and does not require additional processing like augmentation, you can specify a data set of images as a numeric array.

The size and shape of the numeric array depends on the type of image data.

Data Format
2-D images _h_-by-_w_-by-c_-by-N numeric array, where h, w, and_c are the height, width, and number of channels of the images, respectively, and N is the number of images
3-D images _h_-by-_w_-by-_d_-by-_c_-by-N numeric array, where h, w,d, and c are the height, width, depth, and number of channels of the images, respectively, and N is the number of images

Table

As an alternative to datastores or numeric arrays, you can also specify images in a table.

When you specify images in a table, each row in the table corresponds to an observation.

For image input, the predictors must be in the first column of the table, specified as one of the following:

Tip

This argument supports complex-valued predictors. To input complex-valued data into aSeriesNetwork or DAGNetwork object, theSplitComplexInputs option of the input layer must be1 (true).

Sequence or time series data, specified as one of the following.

Data Type Description Example Usage
Datastore TransformedDatastore Datastore that transforms batches of data read from an underlying datastore using a custom transformation function Transform datastores with outputs not supported byactivations.Apply custom transformations to datastore output.
CombinedDatastore Datastore that reads from two or more underlying datastores Make predictions using networks with multiple inputs.Combine predictors from different data sources.
Custom mini-batch datastore Custom datastore that returns mini-batches of data Make predictions using data in a format that other datastores do not support.For details, see Develop Custom Mini-Batch Datastore.
Numeric or cell array A single sequence specified as a numeric array or a data set of sequences specified as cell array of numeric arrays Make predictions using data that fits in memory and does not require additional processing like custom transformations.

Datastore

Datastores read mini-batches of sequences and responses. Use datastores when you have data that does not fit in memory or when you want to apply transformations to the data.

These datastores are directly compatible with activations for sequence data:

You can use other built-in datastores for making predictions by using the transform and combine functions. These functions can convert the data read from datastores to the table or cell array format required byactivations. For example, you can transform and combine data read from in-memory arrays and CSV files using anArrayDatastore and an TabularTextDatastore object, respectively.

The datastore must return data in a table or cell array. Custom mini-batch datastores must output tables.

Datastore Output Example Output
Table data = read(ds) data = 4×2 table Predictors __________________ {12×50 double} {12×50 double} {12×50 double} {12×50 double}
Cell array data = read(ds) data = 4×2 cell array {12×50 double} {12×50 double} {12×50 double} {12×50 double}

The format of the predictors depends on the type of data.

Data Format of Predictors
Vector sequence _c_-by-s matrix, where c is the number of features of the sequence and s is the sequence length
1-D image sequence _h_-by-_c_-by-s array, where h and c correspond to the height and number of channels of the image, respectively, and s is the sequence length.Each sequence in the mini-batch must have the same sequence length.
2-D image sequence _h_-by-w_-by-c_-by-s array, where h, w, and_c correspond to the height, width, and number of channels of the image, respectively, and_s is the sequence length.Each sequence in the mini-batch must have the same sequence length.
3-D image sequence _h_-by-_w_-by-_d_-by-c_-by-s array, where h, w,d, and c correspond to the height, width, depth, and number of channels of the image, respectively, and_s is the sequence length.Each sequence in the mini-batch must have the same sequence length.

For predictors returned in tables, the elements must contain a numeric scalar, a numeric row vector, or a 1-by-1 cell array containing a numeric array.

For more information, see Datastores for Deep Learning.

Numeric or Cell Array

For data that fits in memory and does not require additional processing like custom transformations, you can specify a single sequence as a numeric array or a data set of sequences as a cell array of numeric arrays.

For cell array input, the cell array must be an_N_-by-1 cell array of numeric arrays, where_N_ is the number of observations. The size and shape of the numeric array representing a sequence depends on the type of sequence data.

Input Description
Vector sequences c_-by-s matrices, where_c is the number of features of the sequences and s is the sequence length
1-D image sequences _h_-by-_c_-by-s arrays, where h and c correspond to the height and number of channels of the images, respectively, and s is the sequence length
2-D image sequences _h_-by-w_-by-c_-by-s arrays, where h, w, and_c correspond to the height, width, and number of channels of the images, respectively, and_s is the sequence length
3-D image sequences _h_-by-_w_-by-_d_-by-_c_-by-s, where h, w,d, and c correspond to the height, width, depth, and number of channels of the 3-D images, respectively, and s is the sequence length

Tip

This argument supports complex-valued predictors. To input complex-valued data into a SeriesNetwork or DAGNetwork object, theSplitComplexInputs option of the input layer must be1 (true).

Feature data, specified as one of the following.

Data Type Description Example Usage
Datastore TransformedDatastore Datastore that transforms batches of data read from an underlying datastore using a custom transformation function Transform datastores with outputs not supported byactivations.Apply custom transformations to datastore output.
CombinedDatastore Datastore that reads from two or more underlying datastores Make predictions using networks with multiple inputs.Combine predictors from different data sources.
Custom mini-batch datastore Custom datastore that returns mini-batches of data Make predictions using data in a format that other datastores do not support.For details, see Develop Custom Mini-Batch Datastore.
Table Feature data specified as a table Make predictions using data stored in a table.
Numeric array Feature data specified as numeric array Make predictions using data that fits in memory and does not require additional processing like custom transformations.

Datastore

Datastores read mini-batches of feature data and responses. Use datastores when you have data that does not fit in memory or when you want to apply transformations to the data.

These datastores are directly compatible with activations for feature data:

You can use other built-in datastores for making predictions by using the transform andcombine functions. These functions can convert the data read from datastores to the table or cell array format required by activations. For more information, see Datastores for Deep Learning.

For networks with multiple inputs, the datastore must be a TransformedDatastore orCombinedDatastore object.

The datastore must return data in a table or a cell array. Custom mini-batch datastores must output tables. The format of the datastore output depends on the network architecture.

Network Architecture Datastore Output Example Output
Single input layer Table or cell array with at least one column, where the first column specifies the predictors.Table elements must be scalars, row vectors, or 1-by-1 cell arrays containing a numeric array.Custom mini-batch datastores must output tables. Table for network with one input:data = read(ds)data = 4×2 table Predictors __________________ {24×1 double} {24×1 double} {24×1 double} {24×1 double}
Cell array for network with one input:data = read(ds) data = 4×1 cell array {24×1 double} {24×1 double} {24×1 double} {24×1 double}
Multiple input layers Cell array with at least numInputs columns, wherenumInputs is the number of network inputs.The first numInputs columns specify the predictors for each input.The order of inputs is given by theInputNames property of the network. Cell array for network with two inputs:data = read(ds)data = 4×3 cell array {24×1 double} {28×1 double} {24×1 double} {28×1 double} {24×1 double} {28×1 double} {24×1 double} {28×1 double}

The predictors must be c_-by-1 column vectors, where_c is the number of features.

For more information, see Datastores for Deep Learning.

Table

For feature data that fits in memory and does not require additional processing like custom transformations, you can specify feature data and responses as a table.

Each row in the table corresponds to an observation. The arrangement of predictors in the table columns depends on the type of task.

Task Predictors
Feature classification Features specified in one or more columns as scalars.

Numeric Array

For feature data that fits in memory and does not require additional processing like custom transformations, you can specify feature data as a numeric array.

The numeric array must be an_N_-by-numFeatures numeric array, where_N_ is the number of observations and numFeatures is the number of features of the input data.

Tip

This argument supports complex-valued predictors. To input complex-valued data into aSeriesNetwork or DAGNetwork object, theSplitComplexInputs option of the input layer must be1 (true).

Numeric or cell arrays for networks with multiple inputs.

For image, sequence, and feature predictor input, the format of the predictors must match the formats described in the images,sequences, or features argument descriptions, respectively.

For an example showing how to train a network with multiple inputs, see Train Network on Image and Feature Data.

To input complex-valued data into a DAGNetwork orSeriesNetwork object, the SplitComplexInputs option of the input layer must be 1 (true).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | cell
Complex Number Support: Yes

Mixed data, specified as one of the following.

Data Type Description Example Usage
TransformedDatastore Datastore that transforms batches of data read from an underlying datastore using a custom transformation function Make predictions using networks with multiple inputs.Transform outputs of datastores not supported byactivations so they have the required format.Apply custom transformations to datastore output.
CombinedDatastore Datastore that reads from two or more underlying datastores Make predictions using networks with multiple inputs.Combine predictors from different data sources.
Custom mini-batch datastore Custom datastore that returns mini-batches of data Make predictions using data in a format that other datastores do not support.For details, see Develop Custom Mini-Batch Datastore.

You can use other built-in datastores for making predictions by using the transform and combine functions. These functions can convert the data read from datastores to the table or cell array format required by activations. For more information, see Datastores for Deep Learning.

The datastore must return data in a table or a cell array. Custom mini-batch datastores must output tables. The format of the datastore output depends on the network architecture.

Datastore Output Example Output
Cell array with numInputs columns, wherenumInputs is the number of network inputs.The order of inputs is given by the InputNames property of the network. data = read(ds) data = 4×3 cell array {24×1 double} {28×1 double} {24×1 double} {28×1 double} {24×1 double} {28×1 double} {24×1 double} {28×1 double}

For image, sequence, and feature predictor input, the format of the predictors must match the formats described in the images, sequences, orfeatures argument descriptions, respectively.

For an example showing how to train a network with multiple inputs, see Train Network on Image and Feature Data.

Tip

To convert a numeric array to a datastore, use arrayDatastore.

Layer to extract activations from, specified as a numeric index or a character vector.

To compute the activations of a SeriesNetwork object, specify the layer using its numeric index, or as a character vector corresponding to the layer name.

To compute the activations of a DAGNetwork object, specify the layer as the character vector corresponding to the layer name. If the layer has multiple outputs, specify the layer and output as the layer name, followed by the character “/”, followed by the name of the layer output. That is,layer is of the form'layerName/outputName'.

Example: 3

Example: 'conv1'

Example: 'mpool/out'

Name-Value Arguments

collapse all

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: MiniBatchSize=256 specifies the mini-batch size as 256.

Format of output activations, specified as"channels", "rows", or"columns". For descriptions of the output formats, see act.

For image input, if the OutputAs option is"channels", then the images in the input data can be larger than the input size of the image input layer of the network. For other output formats, the images in the input must have the same size as the input size of the image input layer of the network.

Size of mini-batches to use for prediction, specified as a positive integer. Larger mini-batch sizes require more memory, but can lead to faster predictions.

Option to pad, truncate, or split sequences, specified as one of these values:

To learn more about the effect of padding and truncating sequences, see Sequence Padding and Truncation.

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

Value by which to pad input sequences, specified as a scalar.

Do not pad sequences with NaN, because doing so can propagate errors throughout the neural network.

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

Direction of padding or truncation, specified as one of the following:

Because recurrent layers process sequence data one time step at a time, when the recurrent layer OutputMode property is "last", any padding in the final time steps can negatively influence the layer output. To pad or truncate sequence data on the left, set the SequencePaddingDirection option to "left".

For sequence-to-sequence neural networks (when the OutputMode property is "sequence" for each recurrent layer), any padding in the first time steps can negatively influence the predictions for the earlier time steps. To pad or truncate sequence data on the right, set the SequencePaddingDirection option to "right".

To learn more about the effect of padding and truncating sequences, see Sequence Padding and Truncation.

Performance optimization, specified as one of the following:

If Acceleration is "auto", then MATLAB® applies a number of compatible optimizations and does not generate a MEX function.

The "auto" and "mex" options can offer performance benefits at the expense of an increased initial run time. Subsequent calls with compatible parameters are faster. Use performance optimization when you plan to call the function multiple times using new input data.

The "mex" option generates and executes a MEX function based on the network and parameters used in the function call. You can have several MEX functions associated with a single network at one time. Clearing the network variable also clears any MEX functions associated with that network.

The "mex" option supports networks that contain the layers listed on the Supported Layers (GPU Coder) page, except forsequenceInputLayer objects.

The "mex" option is available when you use a single GPU.

To use the "mex" option, you must have a C/C++ compiler installed and the GPU Coder™ Interface for Deep Learning support package. Install the support package using the Add-On Explorer in MATLAB. For setup instructions, see Set Up Compiler (GPU Coder). GPU Coder is not required.

For quantized networks, the "mex" option requires a CUDA® enabled NVIDIA® GPU with compute capability 6.1, 6.3, or higher.

MATLAB Compiler™ does not support deploying networks when you use the"mex" option.

Hardware resource, specified as one of the following:

For more information on when to use the different execution environments, see Scale Up Deep Learning in Parallel, on GPUs, and in the Cloud.

The "gpu", "multi-gpu", and"parallel" options require Parallel Computing Toolbox. To use a GPU for deep learning, you must also have a supported GPU device. For information on supported devices, seeGPU Computing Requirements (Parallel Computing Toolbox). If you choose one of these options and Parallel Computing Toolbox or a suitable GPU is not available, then the software returns an error.

To make predictions in parallel with networks with recurrent layers (by settingExecutionEnvironment to either "multi-gpu" or "parallel"), the SequenceLength option must be "shortest" or "longest".

Networks with custom layers that contain State parameters do not support making predictions in parallel.

Output Arguments

collapse all

Activations from the network layer, returned as a numeric array or a cell array of numeric arrays. The format of act depends on the type of input data, the type of layer output, and the specifiedOutputAs option.

Image or Folded Sequence Output

If the layer outputs image or folded sequence data, thenact is a numeric array.

OutputAs act
"channels" For 2-D image output,act is an_h_-by-_w_-by-c_-by-n array, where h,w, and c are the height, width, and number of channels for the output of the chosen layer, respectively, and_n is the number of images. In this case, act(:,:,:,i) contains the activations for theith image.For 3-D image output, act is an_h_-by-_w_-by-d_-by-c_-by-n array, where h,w, d, and_c are the height, width, depth, and number of channels for the output of the chosen layer, respectively, and_n is the number of images. In this case, act(:,:,:,:,i) contains the activations for theith image.For folded 2-D image sequence output,act is an_h_-by-_w_-by-_c_-by-(n*s) array, where h,w, and c are the height, width, and number of channels for the output of the chosen layer, respectively,n is the number of sequences, and s is the sequence length. In this case,act(:,:,:,(t-1)*n+k) contains the activations for time step t of the kth sequence.For folded 3-D image sequence output, act is an_h_-by-_w_-by-d_-by-c_-by-(n*s) array, where h,w, d, and_c are the height, width, depth, and number of channels for the output of the chosen layer, respectively, n is the number of sequences, and_s is the sequence length. In this case,act(:,:,:,:,(t-1)*n+k) contains the activations for time step t of the kth sequence.
"rows" For 2-D and 3-D image output,act is an_n_-by-m matrix, where n is the number of images and m is the number of output elements from the layer. In this case,act(i,:) contains the activations for the ith image.For folded 2-D and 3-D image sequence output, act is an (n*s)-by-m matrix, where n is the number of sequences, s is the sequence length, and m is the number of output elements from the layer. In this case,act((t-1)*n+k,:) contains the activations for time step t of the kth sequence.
"columns" For 2-D and 3-D image output,act is an_m_-by-n matrix, where m is the number of output elements from the chosen layer and_n_ is the number of images. In this case, act(:,i) contains the activations for the ith image.For folded 2-D and 3-D image sequence output, act is an_m_-by-(n*s) matrix, where m is the number of output elements from the chosen layer,n is the number of sequences, and s is the sequence length. In this case, act(:,(t-1)*n+k) contains the activations for time stept of the kth sequence.

Sequence Output

If layer has sequence output (for example, LSTM layers with the output mode "sequence"), thenact is a cell array. In this case, the"OutputAs" option must be"channels".

OutputAs act
"channels" For vector sequence output,act is an_n_-by-1 cell array of_c_-by-s matrices, where n is the number of sequences, c is the number of features in the sequence, and_s_ is the sequence length.For 2-D image sequence output,act is an_n_-by-1 cell array of_h_-by-_w_-by-_c_-by-s matrices, where n is the number of sequences, h,w, and c are the height, width, and the number of channels of the images, respectively, and s is the sequence length.For 3-D image sequence output, act is an_n_-by-1 cell array of_h_-by-_w_-by-_c_-by-d_-by-s matrices, where n is the number of sequences, h,w, d, and_c are the height, width, depth, and the number of channels of the images, respectively, and s is the sequence length.In these cases,act{i} contains the activations of the ith sequence.

Feature Vector and Single Time Step Output

If layer outputs a feature vector or a single time step of a sequence (for example, an LSTM layer with the output mode"last"), then act is a numeric array.

OutputAs act
"channels" For a feature vector or single time step containing vector data, act is a _c_-by-n matrix, where n is the number of observations and c is the number of features.For a single time step containing 2-D image data,act is a_h_-by-_w_-by-_c_-by-n array, where n is the number of sequences and h,w, and c are the height, width, and the number of channels of the images, respectively.For a single time step containing 3-D image data,act is a_h_-by-_w_-by-_c_-by-d_-by-n array, where n is the number of sequences and h,w, d, and_c are the height, width, depth, and the number of channels of the images, respectively.
"rows" _n_-by-m matrix, where n is the number of observations and m is the number of output elements from the chosen layer. In this case, act(i,:) contains the activations for the ith sequence.
"columns" m_-by-n matrix, where m is the number of output elements from the chosen layer and_n is the number of observations. In this case,act(:,i) contains the activations for the ith image.

Algorithms

collapse all

When you train a neural network using the trainnet or trainNetwork functions, or when you use prediction or validation functions with DAGNetwork and SeriesNetwork objects, the software performs these computations using single-precision, floating-point arithmetic. Functions for prediction and validation include predict, classify, and activations. The software uses single-precision arithmetic when you train neural networks using both CPUs and GPUs.

To provide the best performance, deep learning using a GPU in MATLAB is not guaranteed to be deterministic. Depending on your network architecture, under some conditions you might get different results when using a GPU to train two identical networks or make two predictions using the same network and data.

Extended Capabilities

expand all

Usage notes and limitations:

For more information about generating code for deep learning neural networks, seeWorkflow for Deep Learning Code Generation with MATLAB Coder (MATLAB Coder).

Usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2016a

expand all

Starting in R2024a, DAGNetwork and SeriesNetwork objects are not recommended, use dlnetwork objects instead. This recommendation means that the activations function is also not recommended. Use the predict function instead and specify the Outputs option.

There are no plans to remove support for DAGNetwork andSeriesNetwork objects. However, dlnetwork objects have these advantages and are recommended instead:

To convert a trained DAGNetwork or SeriesNetwork object to a dlnetwork object, use the dag2dlnetwork function.

This table shows a typical usage of the activations function and how to update your code to use dlnetwork objects instead.

Not Recommended Recommended
act = activations(net,X,layerName); act = minibatchpredict(net,X,Outputs=layerName);

Starting in R2022b, when you make predictions with sequence data using thepredict, classify,predictAndUpdateState, classifyAndUpdateState, and activations functions and the SequenceLength option is an integer, the software pads sequences to the length of the longest sequence in each mini-batch and then splits the sequences into mini-batches with the specified sequence length. If SequenceLength does not evenly divide the sequence length of the mini-batch, then the last split mini-batch has a length shorter thanSequenceLength. This behavior prevents time steps that contain only padding values from influencing predictions.

In previous releases, the software pads mini-batches of sequences to have a length matching the nearest multiple of SequenceLength that is greater than or equal to the mini-batch length and then splits the data. To reproduce this behavior, manually pad the input data such that the mini-batches have the length of the appropriate multiple of SequenceLength. For sequence-to-sequence workflows, you may also need to manually remove time steps of the output that correspond to padding values.