Accuracy of exported model is lower in Simulink
7 views (last 30 days)
Show older comments
I trained a CNN-LSTM with the deep learning toolbox in Matlab and exported the model later with the exportNetworkToSimulink() in order to deploy it in a Simulink environment. Although, the data I'm feeding into the net is similiar to what it has been trained to, its accuracy is pretty low.
I saved the net as a mat-file and used then later a Predict-Block in Simulink, where I referred to the mat-file. In this approach, the net accuracy was similiar to what it was trained. After looking inside the Predict-Block, I figured out that it seems to be some kind of MATLAB-Function block that's executed outside Simulink, I guess? But the only problem that I have is, that the workaround with the Predict-Block is more time-consuming that the exported model (assessed by the Simulink-Profiler).
Can anyone help or is there an issue while exporting the network? Thanks! (Some specs below :P)
net design:
layers = [
sequenceInputLayer(7,"Name","input")
convolution1dLayer(60,32,"Name","convolution1","Padding","same")
tanhLayer("Name","tanhlayer")
layerNormalizationLayer("Name","layernorm1")
convolution1dLayer(60,64,"Name","convolution2","Padding","same")
leakyReluLayer(0.1,"Name","leakyrelu")
layerNormalizationLayer("Name","layernorm2")
lstmLayer(30,"OutputMode","sequence")
fullyConnectedLayer(1,"Name","fc")];
the result i get when im trying to export the net:
>> exportNetworkToSimulink(net)
> In layerblocks.internal/NetworkToSimulinkExporter/createNewModel
In layerblocks.internal/NetworkToSimulinkExporter
In exportNetworkToSimulink
Warning: Failed to update the model. Check the model to resolve any issues.
> In layerblocks.internal/NetworkToSimulinkExporter/exportNetwork
In layerblocks.internal/NetworkToSimulinkExporter
In exportNetworkToSimulink
0 Comments
Answers (1)
Rishav
on 11 Aug 2025
Hi Vishal,
The Predict Block provides better accuracy since it runs MATLAB code in the background (interpreted, not code-generated), so it matches MATLAB's behavior and supports more layers.
On the other hand, "exportNetworkToSimulink()" tries to convert the network to a Simulink block for code generation, where some layers are sometimes substituted with approximations when exported, leading to lesser accuracy.
You can use the "analyzeNetwork(net)" function in MATLAB to detect any possible problems before training.
Please refer to the following documentation for the same:
0 Comments
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!