离线训练好的神经网络怎样通过MATLAB function调用进Simulink?。
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
各位前辈好,在做课题的过程中遇到了问题,离线训练好的网络如何通过MATLAB function调用进Simulink,我尝试了三种办法:
1.在Command Window加载了训练好的net,Workspace中可以看到,在M-function中使用 load指令,报错Function 'load' is not supported for code generation. Consider using coder.extrinsic('load') to bypass code generation.说load指令只适用于外部,不能用于Simulink,于是根据建议在load指令前添加了coder.extrinsic('load')在程序中,运行后依然报错Undefined function or variable 'net'.
2.于是我想可能net这个变量没有设置为全局变量,于是我分别在Command Window和M-function中设置和声明了net,依旧报错Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
3.走投无路的第三种方案,我觉得虽然Workspace中已经存了网络net,但传送不到simulink中,于是我用From Workspace模块把net传进Simulink中,这个方法依旧行不通啊:'(
所以请问怎样在M-function中调用训练好的net,万分感谢各位前辈。
Risposta accettata
cotog
il 26 Nov 2022
好吧,我来自问自答吧
经过了一早上的查阅,知道了解决的办法
只要查看已经训练好的网络各层之间的权值和偏置就可以了
这是百度到的查看语句:
训练好的权值、阈值的输出方法是:
输入到隐层权值: w1=net.iw{1,1}
隐层阈值: theta1=net.b{1}
隐层到输出层权值: w2=net.lw{2,1};
输出层阈值: theta2=net.b{2}
复制到MATLAB function程序中,直接使用就OK了
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!