How to generate C++ Code from predictAndUpdateState() function of LSTM NN?

조회 수: 8 (최근 30일)
Simon Linek
Simon Linek 2021년 2월 26일
댓글: 世记 2023년 10월 26일
Hi lovely people,
we are working on a project where we want to use a Time-Series LSTM Neural Network to forecast multiple time steps in the future by using the predictAndUpdateState() function iteratively in a loop, so the network can keep its state, while on every iteration the network is fed with input from its own previous predictions and other forecast data we aquire from different sources. In general it looks like this:
net = getLSTMNN;
cT = initialValue;
numTimeSteps = 120;
XInput = (cT, getCurrentData);
for i = 1:numTimeSteps
if i ~= 1
XInput = (YPred(:,i-1), getForecastData(i-1));
end
[net,YPred(:,i)] = predictAndUpdateState(net,XInput);
end
For context: the LSTM is intended to be used as a predictor within a model predictive controller.
We are aware that the official Matlab Ref-Page of predictAndUpdateState does not list C++ Code generation as supported, only GPU CUDA Code for NVIDIA GPUs, which we cannot make use of. But there is an example where the predictAndUpdateState() of a Stateful LSTM is used to generate Code for an ARM-based Rasperry Pi (Link). Thats why we are searching for a way to generate "pure" C++ CPU Code from a predictAndUpdateState() function which is not CUDA dependent or intended for ARM systems.
Any help, advice or tips on how to achieve this would be greatly appreciated!
EDIT: We are on 2020b.
Many thanks,
Simon
  댓글 수: 1
世记
世记 2023년 10월 26일
Hi Simon,
I wonder if you have solved this problem as im facing the same one right now.
If you do , please give some suggestions for me and that will be very helpful.

댓글을 달려면 로그인하십시오.

채택된 답변

Sindhu Karri
Sindhu Karri 2021년 3월 5일
Hii Simon,
In the example which you have mentioned, C++ code is generated with ARM Compute Library and currently there is no work around for generating C++ code for predictAndUpdateState without using ARM Compute Library.
Refer to below link to know more about code generation using ARM Compute Library
  댓글 수: 2
Simon Linek
Simon Linek 2021년 3월 19일
Hi Sindhu,
thank you for your answer, but apparently C++ code generation has been added in R2021a for predictAndUpdateState. So we will have a look into it and see if it works.
世记
世记 2023년 10월 26일
Hi Simon,
I wonder if you have solved this problem as im facing the same one right now.
If you do , please give some suggestions for me and that will be very helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by