exportNetworkToSimulink - Generate Simulink model that contains deep learning layer blocks and subsystems that correspond to
deep learning layer objects - MATLAB ([original](https://in.mathworks.com/help/deeplearning/ref/dlnetwork.exportnetworktosimulink.html)) ([raw](?raw))
Generate Simulink model that contains deep learning layer blocks and subsystems 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 and subsystems 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 and subsystems, see List of Deep Learning Layer Blocks and Subsystems. If the network contains a layer that does not have a corresponding deep learning layer block or subsystem, then the function generates a placeholder subsystem that contains an Assertion (Simulink) block. You can manually replace the Assertion block with an implementation of the layer.
Input Arguments
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")
Name of the generated Simulink model, specified as a character vector or string.
Data Types: char
| 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
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
Flag to expand layer blocks and subsystems to the top level of the generated model without wrapping the blocks in a subsystem, specified as a numeric or logical1
(true
) or 0
(false
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Flag to open the model after generating it, specified as a numeric or logical1
(true
) or 0
(false
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
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
Flag to use stateful prediction, specified as one of these values:
1
(true
) — Use stateful prediction.0
(false
) — Use stateless prediction.
If the input network contains a supported stateful layer, then the default value is true
. Otherwise, the default value isfalse
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Flag to use frame-based processing for sequence networks, specified as a numeric or logical 1
(true
) or 0
(false
).
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: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Flag to save the input network in the workspace of the generated model, specified as a numeric or logical 1
(true
) or0
(false
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Flag to save the generated model in the folder path as an SLX (*.slx) file, specified as a numeric or logical 1
(true
) or0
(false
).
Specify where to save the model using the ModelPath name-value argument. By default, the exportNetworkToSimulink
function saves the generated model in the current directory.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Output Arguments
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 (networks where theInputNames
andOutputNames
properties are scalar). - Because deep learning layer blocks and subsystems 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 and Subsystems.
- If the input network contains a layer object that does not have a corresponding layer block, the function generates a placeholder subsystem that contains an Assertion (Simulink) block. You can manually replace the Assertion 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 and Subsystems 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
Choose whether or not to save the generated model in the model path as an SLX (*.slx) file by setting the SaveModelToFile flag. Specify the model path using the ModelPath
name-value argument. By default, the exportNetworkToSimulink
function saves the generated model in the current directory.