Main Content

exportNetworkToSimulink

Generate Simulink model that contains deep learning layer blocks that correspond to deep learning layer objects

Since R2024b

    Description

    mdlInfo = exportNetworkToSimulink(net) 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

    collapse all

    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 as Name1=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 an Inport 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 to the top level of the generated model without wrapping the blocks in a subsystem, specified as a boolean.

    Data Types: logical

    Flag to open the model after generating it, specified as a boolean.

    Data Types: 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 a boolean. If you specify false, 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

    Flag to use frame-based processing for sequence networks, specified as a boolean.

    If you specify false:

    • The generated model assumes that the input data uses Simulink step time to represent the frame rate.

    • The generated model sets the time (T) dimension of the inport to the value of the MinLength property of the sequenceInputLayer object in the sequence network.

    Data Types: logical

    Flag to save the input network in the workspace of the generated model, specified as a boolean.

    Data Types: logical

    Output Arguments

    collapse all

    Information about the generated model, returned as a structure. This table describes the fields of the structure.

    FieldDescription
    ModelNameName of the generated model, returned as a character vector.
    NetworkNameName of the network in the generated model workspace, returned as a character vector.
    ModelPathFull file path of the generated model, returned as a character vector.
    InputDataTypeInput data type of the generated model, returned as a character vector.
    BlockParametersParameters 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.
    BlockConnectionsConnections between blocks in the generated model, returned as a table. The table contains the variables Source and Destination. Each row in the table represents the source and destination blocks of a connection in the generated model.
    NumImportsThe number of inports in the generated model, returned as a scalar.
    NumOutportsThe number of outports in the generated model, returned as a scalar.
    SampleTimeThe sample time of the generated model, returned as a character vector.
    StatefulType of prediction that the model uses, either stateless or stateful, returned as a boolean.
    FrameBasedType 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, the exportNetworkToSimulink 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, see List 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 or DAGNetwork object to Simulink, use the dag2dlnetwork function to convert the object to a dlnetwork object and pass that converted object to the exportNetworkToSimulink 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