Shallow Neural Networks does not work with MATLAB APP after compilation

2 ビュー (過去 30 日間)
Francesco Pelella
Francesco Pelella 2023 年 9 月 28 日
編集済み: Aniket 2024 年 10 月 4 日
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 件のコメント
Gowtham
Gowtham 2023 年 10 月 10 日
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.

サインインしてコメントする。

回答 (1 件)

Aniket
Aniket 2024 年 10 月 4 日
編集済み: Aniket 2024 年 10 月 4 日
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.

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by