simulink中的Stateful Predict模块可实现此功能。

提示:matlab2021版本才有此模块!!!
Model Example
1、 Load Pretrained Network
load JapaneseVowelsNet;
2、 Load Test Data
[XTest,YTest] = japaneseVowelsTestData;
X = XTest{94};
numTimeSteps = size(X,2);
3、 Simulink Model for Predicting Responses
open_system('StatefulPredictExample');

4、 Configure Model for Simulation
set_param('StatefulPredictExample/Input','Value','X');
set_param('StatefulPredictExample/Index','uplimit','numTimeSteps-1');
set_param('StatefulPredictExample/Stateful Predict','NetworkFilePath','JapaneseVowelsNet.mat');
set_param('StatefulPredictExample', 'SimulationMode', 'Normal');
5、 Run the Simulation
out = sim('StatefulPredictExample');
6、 Plot the prediction scores
scores = squeeze(out.yPred.Data(:,:,1:numTimeSteps));
classNames = string(net.Layers(end).Classes);
figure
lines = plot(scores');
xlim([1 numTimeSteps])
legend("Class " + classNames,'Location','northwest')
xlabel("Time Step")
ylabel("Score")
title("Prediction Scores Over Time Steps")

trueLabel = YTest(94);
lines(trueLabel).LineWidth = 3;

matlab官方文档:https://www.mathworks.com/help/releases/R2021a/deeplearning/ug/predict-update-network-simulink.html
|