how can ı use "minibatchpredict(net,XTest);" command on simulink?
Ältere Kommentare anzeigen
I trained a LSTM network.
How can I use "scores = minibatchpredict(net,XTest);" and "YPred = predict(net, XTest);" commands on Simulink?
Antworten (1)
AJ Ibraheem
am 6 Okt. 2025
Bearbeitet: Walter Roberson
am 6 Okt. 2025
1 Stimme
The 'Stateful Predict' block might be what you're looking for. See https://uk.mathworks.com/help/deeplearning/ref/statefulpredict.html
5 Kommentare
Bahadir
am 6 Okt. 2025
AJ Ibraheem
am 7 Okt. 2025
> The results of Stateful Predict is different from minibatchpredict.
Yes it is understandable that you're getting different results. The stateful predict block would update the network states after prediction, to get the same result with the predict block, you'd have to follow [YPred, net.State] = predict(net, XTest) https://uk.mathworks.com/help/deeplearning/ref/dlnetwork.predict.html#d126e73498
> Using a MATLAB function block (as opposed to the Stateful predict block) for neural network prediction is valid.
It is possible that a layer in your network is not supported for the mkldnn target.
Do you mind sharing more about your current setup?
Walter Roberson
am 7 Okt. 2025
Using a Redistributable is not enough: you need to use the actual Visual C++ compiler. https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false
Bahadir
am 8 Okt. 2025
Spoorthy Kannur
am 11 Nov. 2025
Hi Bahadir,
You may try the following:
In Simulink, you can use your trained network for prediction inside a MATLAB Function block, but there are a few important details to ensure it behaves consistently with MATLAB, in your case:
function y = fnc(u)
persistent net
if isempty(net)
net = coder.loadDeepLearningNetwork('32.mat');
end
% Preprocess input the same way as during training
input = rescale(u);
XTrain = {input'};
% Perform prediction
YPred = predict(net, XTrain);
y = YPred{1};
end
1. Use a supported compiler: “minibatchpredict” ( https://www.mathworks.com/help/deeplearning/ref/minibatchpredict.html) is not codegen-compatible, but “predict” is (https://www.mathworks.com/help/deeplearning/ref/dlnetwork.predict.html). Select a supported compiler using (Visual Studio C++ is required; MinGW64 won’t work for deep learning code generation):
mex -setup cpp
2. Match data preprocessing: Apply the same scaling or reshaping you used during training (e.g., sequence dimension order).
3. Choose the right block execution rate: For sequence data, ensure the Simulink sample time matches your network input timestep.
If your results still differ slightly from MATLAB, check whether the MATLAB version of “predict” was run statefully or statelessly, since LSTMs maintain hidden states across calls — this can cause small output differences unless you reset or manage the network state manually in Simulink.
If this does resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html)
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!