离线训练好的神经网络怎样通过MATLAB function调用进Simulink?。

35 visualizzazioni (ultimi 30 giorni)
fofojev
fofojev il 26 Nov 2022
Commentato: 海涛 il 28 Nov 2024
各位前辈好,在做课题的过程中遇到了问题,离线训练好的网络如何通过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,万分感谢各位前辈。
  1 Commento
海涛
海涛 il 28 Nov 2024
你好前辈,请问你解决了吗

Accedi per commentare.

Risposta accettata

cotog
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了
  1 Commento
zhu
zhu il 25 Nov 2024
您好,没懂您意思,请问权值阈值读取后然后怎么使用呢?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 代码生成 in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!