Load Pretrained Networks in Matlab function block

5 次查看(过去 30 天)
Hi,
I want use pretrained LSTM network in simulink matlab function block but ı get this error.
function y= fnc( Va,Vb,Vc,Ia,Ib,Ic)
input= [Va, Vb, Vc, Ia, Ib, Ic];
input=rescale(input);
XTrain = {input'};
net = coder.loadDeepLearningNetwork('alphabeta.mat');
output= predict(net, XTrain, 'MiniBatchSize', 1);
y=output{1};
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
For deep learning, the simulation target language must be set to C++. Function 'MATLAB Function' (#117.120.166), line 6, column 7: "coder.loadDeepLearningNetwork('alphabeta.mat')" Launch diagnostic report.

回答(1 个)

Paul
Paul 2025-6-11
编辑:Paul 2025-6-11
According to the doc pages coder.loadDeepLearningNetwork and predict- (not recommended) and the error message this function might work (not tested)
function y= fnc( Va,Vb,Vc,Ia,Ib,Ic)
persistent net
if isempty(net)
net = coder.loadDeepLearningNetwork('alphabeta.mat');
end
input= [Va, Vb, Vc, Ia, Ib, Ic];
input=rescale(input);
XTrain = {input'};
output= predict(net, XTrain, 'MiniBatchSize', 1);
y = ????; % assign a dummy value to y that is of the same size and type of output{1}
y=output{1};
end
Also be sure to go to Model Settings -> Simulation Target -> Language and select C++ from the dropdown menu.

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by