Input shape for the LSTM model

조회 수: 2 (최근 30일)
XIAOLONG YI
XIAOLONG YI 2022년 4월 14일
답변: Milan Bansal 2023년 9월 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에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by