Multivariate LSTM mini-batch size error

6 次查看(过去 30 天)
Coding a multivariate LSTM for power demand regression/forecasting. Please see attached code.
After training the LSTM on a N x 1 cell array (26 x 1 cells) training set of EMD (of the demand data) and some other non-0 change information (renewables, ccgt, etc), trying to predict using the trained LSTM throws the following error:
Error using DAGNetwork/predictRNN>iAssertInitialStateIsValidForPredict (line 67)
Incorrect network state. The network expects mini-batches size of 45, but was
passed a mini-batch of size 1.
Error in DAGNetwork/predictRNN (line 9)
iAssertInitialStateIsValidForPredict(statefulLayers, dispatcher.MiniBatchSize)
Error in DAGNetwork/predictAndUpdateState (line 130)
[Y, finalState, predictNetwork] = this.predictRNN(X, dispatcher, ...
Error in SeriesNetwork/predictAndUpdateState (line 396)
[this.UnderlyingDAGNetwork, Y] =
this.UnderlyingDAGNetwork.predictAndUpdateState(X, varargin{:});
Error in DPM_V2_1 (line 124)
[net,YPred(i,:)] =
predictAndUpdateState(net,XTest(i,:),'ExecutionEnvironment','gpu');
I have attempted to change the miniBatchSize in the training options, however I don't think this is the solution, and didn't get any change in results.
Altering the sequenceLength to longest also didn't get any results.
Any help would be appreciated, thanks
  1 个评论
Shashank Gupta
Shashank Gupta 2021-4-22
Hi Harry,
I ran the attached file as it is and I am not able to get the same error as yours. Although looking at the error, it seems like the numFeatures and mini batch size is mismatched. Try looking at this direction.

请先登录,再进行评论。

回答(1 个)

Niccolò Dal Santo
Niccolò Dal Santo 2021-7-26
编辑:Niccolò Dal Santo 2021-7-26
Hi Harry,
I was able to reproduce the error you report, which is caused by the fact that you do not reset the state of the network before the for-loop. You can add the following line before the for-loop which invokes the predictAndUpdateState method:
net = resetState(net);
Notice that for training the network in R2021a release I had to changed the definition of YTrain to
YTrain = cell2mat(YTrain(2:end,:));
The format of the inputs to trainNetwork for training on sequences from cell arrays are
  • The input X a cell array of size N x 1, where each element is one time series of size C x S, C being the number of features and S being the number of timesteps. Each element of the cell array is an observation.
  • The input Y a matrix of targets or a cell array of size N x 1, where each element is a matrix of size R x S, R being the number of output responses and S being the number of timestepsv(which must be equal to the corresponding input observation).
Please see the documentation page of trainNetwork function for further details: https://www.mathworks.com/help/deeplearning/ref/trainnetwork.html#bu6sn4c-2
I hope this helps.
Cheers,
Niccolò

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by