exportNetworkToSimulink - Generate Simulink model that contains deep learning layer blocks that correspond to deep learning
layer objects - MATLAB ([original](https://www.mathworks.com/help/deeplearning/ref/dlnetwork.exportnetworktosimulink.html)) ([raw](?raw))
Generate Simulink model that contains deep learning layer blocks that correspond to deep learning layer objects
Since R2024b
Syntax
Description
[mdlInfo](#mw%5Fc55872a5-322b-4e8e-be20-e59812c07497) = exportNetworkToSimulink([net](#mw%5F1b39a89e-4f15-44de-ad8b-5055dea6cbe1))
creates a Simulink® model for a trained dlnetwork
object, net
. The model uses a fixed-step solver and contains deep learning layer blocks that correspond to layers in the network. The function returns a structure that contains information about the generated model.
For a list of deep learning layer blocks, see List of Deep Learning Layer Blocks. If the network contains a layer that does not have a corresponding deep learning layer block, the function generates a placeholder subsystem that contains a Stop Simulation (Simulink) block. You can manually replace the Stop Simulation block with an implementation of the layer.
Input Arguments
net
— Trained deep learning network
dlnetwork
object
Trained deep learning network to export as a Simulink model, specified as a dlnetwork
object.
Data Types: dlnetwork
Name-Value Arguments
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.
Example: exportNetworkToSimulink(myNetwork,ModelName="myExportedModel")
ModelName
— Name of generated Simulink model
'my_model'
(default) | character vector | string
Name of the generated Simulink model, specified as a character vector or string.
Data Types: char
| string
ModelPath
— Folder path for generated model
character vector | string
Folder path for saving the generated model, specified as a character vector or string. If you do not specify ModelPath
, the function saves the model to the current working directory.
Data Types: char
| string
InputDataType
— Data type for generated inports
character vector | string
Data type for generated inports, specified as a character vector or string. The value must correspond to a data type that is supported as the input type of anInport block, such as 'uint8'
,'single'
, or 'Inherit: auto'
. Other blocks in the generated model inherit the input type from the Inport blocks.
If you do not specify InputDataType
, the generated inports use the value 'Inherit: auto'
.
Data Types: char
| string
ExpandNetworkSubsystem
— Flag to expand layer blocks to top level
false
(default) | true
Flag to expand layer blocks to the top level of the generated model without wrapping the blocks in a subsystem, specified as a boolean.
Data Types: logical
OpenSystem
— Flag to open generated model
false
(default) | true
Flag to open the model after generating it, specified as a boolean.
Data Types: logical
SampleTime
— Model sample time
-1
(default) | '_`Ts`_'
| '[_`Ts`_ 0]'
Sample time to use for the generated model, specified as a character vector or string. To use an inherited sample time, use a character vector or string of the form'_`Ts`_'
or'[_`Ts`_ 0]'
, where_`Ts`_
is the sample time. For more information, see Specify Sample Time (Simulink).
Data Types: char
| string
Stateful
— Flag to use stateful prediction
false
(default) | true
Flag to use stateful prediction, specified as a boolean. If you specifyfalse
, the generated model uses stateless prediction. If you do not specify Stateful
and the input network contains a stateful layer, the generated model uses stateful prediction by default.
Data Types: logical
FrameBased
— Flag to use frame-based processing
false
(default) | true
Flag to use frame-based processing for sequence networks, specified as a boolean.
If you specify false
, the generated model uses sample-based processing. The model assumes that the input data uses Simulink step time to represent the frame rate.
If you specify true
, the generated model uses frame-based processing. The model sets the time (T
) dimension of the inport to the value of the MinLength
property of the sequenceInputLayer object in the sequence network.
For more information about sample- and frame-based processing, see Sample- and Frame-Based Concepts (DSP System Toolbox).
Data Types: logical
SaveNetworkInModelWorkspace
— Flag to save input network in model workspace
false
(default) | true
Flag to save the input network in the workspace of the generated model, specified as a boolean.
Data Types: logical
Output Arguments
mdlInfo
— Information about generated model
structure
Information about the generated model, returned as a structure. This table describes the fields of the structure.
Field | Description |
---|---|
ModelName | Name of the generated model, returned as a character vector. |
NetworkName | Name of the network in the generated model workspace, returned as a character vector. |
ModelPath | Full file path of the generated model, returned as a character vector. |
InputDataType | Input data type of the generated model, returned as a character vector. |
BlockParameters | Parameters of blocks in the generated model, returned as a structure array. Each structure in the array contains a field for each parameter of a block. |
BlockConnections | Connections between blocks in the generated model, returned as a table. The table contains the variables Source andDestination. Each row in the table represents the source and destination blocks of a connection in the generated model. |
NumInports | The number of inports in the generated model, returned as a scalar. |
NumOutports | The number of outports in the generated model, returned as a scalar. |
SampleTime | The sample time of the generated model, returned as a character vector. |
Stateful | Type of prediction that the model uses, either stateless or stateful, returned as a boolean. |
FrameBased | Type of processing that the model uses, either frame-based or sample-based, returned as a boolean. |
Limitations
- The
exportNetworkToSimulink
function supports only networks that have one input and one output. - Because deep learning layer blocks do not support the batch (
B
) dimension, theexportNetworkToSimulink
function ignores batch dimensions in layer objects and produces models that assume only one observation. - The function supports only a limited set of layer objects and does not support certain property values for certain layer objects. For a list of supported layer objects and unsupported property values, see List of Deep Learning Layer Blocks.
- If the input network contains a layer object that does not have a corresponding layer block, the function generates a placeholder subsystem that contains a Stop Simulation (Simulink) block. You can manually replace the Stop Simulation block with an implementation of the layer. For more information, see Implement Unsupported Deep Learning Layer Blocks.
- If the input network contains a layer object that has a corresponding layer block but the object uses a property value that the block does not support, the function either throws an error or substitutes a different value. For specific behaviors, seeList of Deep Learning Layer Blocks or each layer block reference page. To change the value of a layer object property to a supported value, use the Deep Network Designer app.
Tips
- Because the generated model references the input network, you can update the weights that the model uses by retraining the network without re-exporting to Simulink.
- To export a
SeriesNetwork
orDAGNetwork
object to Simulink, use the dag2dlnetwork function to convert the object to adlnetwork
object and pass that converted object to theexportNetworkToSimulink
function. - For networks that contain ProjectedLayer objects, use the unpackProjectedLayers function.
- For networks that contain networkLayer objects, use the expandLayers function.
Version History
Introduced in R2024b