Input shape for the LSTM model

2 views (last 30 days)
XIAOLONG YI
XIAOLONG YI on 14 Apr 2022
Answered: Milan Bansal on 14 Sep 2023
XTrain dataset (a cell) has a shape of 12x1 and each of 12 elements has 55x1 data. YTrain data set (as a matrix) has a shape of 12x55. How can I match the dimension of these datasets? The error msg: error msg " Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell array of sequences, where N is the number of sequences. The feature dimension of all" is alway there
%%Train the Layers
numFeatures = 55;
numHiddenUnits = 300;
numResponses = 1;
LSTM = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numResponses)
regressionLayer];
maxEpochs = 10
miniBatchSize = 100
options = trainingOptions('adam', ...
'ExecutionEnvironment','auto', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,LSTM,options)

Answers (1)

Milan Bansal
Milan Bansal on 14 Sep 2023
Hi,
I understand you are facing an error when passing a "cell array" as input to the Long Short Term Memory (LSTM) Model.
According to given code, the input layer expects a sequence of features of dimension 55. Ensure that each element in the input array i.e "XTrain" has dimension of (55 × 1) and cell array has the dimension of (N × 1), where N is the number of sequences.
You may also convert the cell array to matrix using the below code.
A = cell2mat(C) % C is the cell array
The variable "numResponses" has value 1, which means that the output layer is expecting each output response to have dimension of 1, but each element in "YTrain" has a dimension of 55. Set the value of "numResponses" to 55.
Refer to the documentation link to know more about LSTM Models.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!