Multivariate LSTM mini-batch size error

조회 수: 18 (최근 30일)
Harry Bannister
Harry Bannister 2021년 4월 18일
편집: Niccolò Dal Santo 2021년 7월 26일
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에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by