Input shape for the LSTM model

5 次查看(过去 30 天)
XIAOLONG YI
XIAOLONG YI 2022-4-14
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)

回答(1 个)

Milan Bansal
Milan Bansal 2023-9-14
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.

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by