Shallow Neural Networks does not work with MATLAB APP after compilation

2 views (last 30 days)
Dear all,
I am trying to implement a trained Shallow Neural Network inside a designed Matlab APP. The ANN has 2 hidden layers and has been calibrated through a code with the function train, and then saved in the workspace, as follows:
[net,tr] = train(net,x,t);
save("namefile.mat",'net')
At this point, for using the ANN inside an .mlapp file, I am loading it with the function "load", and the using it recalling the name of the net itself, as follows:
load("namefile")
output=net(input);
As long as I am using this approach, before the APP compilation, everything works fine with the execution of the .mlapp file. However, after the creation of the standalone application through the "Application Compiler", the prevision line gives the following error:
"Index exceeds the number of array elements. Index must not exceed 1."
I am trying to solve the problem also by using the "sim" function, but it didn't work, since it seems a compatibility issue between the .mlapp and the .exe file.
How can I solve this problem?
Thank you and regards
  1 Comment
Gowtham
Gowtham on 10 Oct 2023
Hi Francesco
To better understand the issue you're facing, it would be helpful if you could provide the relevant code snippets. Please share the code where you train the neural network, save it to a file, and load it in your MATLAB app.

Sign in to comment.

Answers (1)

Aniket
Aniket on 4 Oct 2024
Edited: Aniket on 4 Oct 2024
I was able to reproduce the issue you are facing. The app worked fine in AppDesigner but error comes when using a standalone app.
Adding the following line of code in your callback function resolves this issue.
%#function network
The above line of code is equivalent to a function declaration, which explicitly attaches the 'network' class object to the CTF archive during the compilation process.
Also, I did not face this issue using R2024b. So you may also upgrade to latest version of MATLAB if possible.
You may refer to this link to know more about MATLAB Compiler limitations:
Hope this resolves the issue.

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!