sequenceInputLayer() 串联的数组维度不一致

sequenceInputLayer() Dimensions of arrays being concatenated are not consistent

我尝试创建一个 LSTM 模型。我收到以下错误:

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in source (line 9) sequenceInputLayer(33)

sequenceInputLayer 的输入应该是什么及其大小?

Data = csvread('newData.csv');
num_timesteps = size(Data,1)
num_features = size(Data,2)
Data = normalize(Data);
numHiddenUnits = 200;
size(Data)
layers = [
    sequenceInputLayer(33)
    lstmLayer(numHiddenUnits,'OutputMode','sequence')
    fullyConnectedLayer(50)
    dropoutLayer(0.5)
    fullyConnectedLayer(num_features),regressionLayer];
maxEpochs = 60;
miniBatchSize = 20;
options = trainingOptions('adam', ...
    'MaxEpochs',maxEpochs, ...
    'MiniBatchSize',miniBatchSize, ...
    'InitialLearnRate',0.001, ...
    'GradientThreshold',1, ...
    'Shuffle','never', ...
    'Plots','training-progress',...
    'Verbose',0);
% net = trainNetwork(Data,Data,layers,options);

问题不在 sequenceInputLayer,问题在于您创建 layers 数组的方式。

替换:

layers = [
    sequenceInputLayer(33)
    lstmLayer(numHiddenUnits,'OutputMode','sequence')
    fullyConnectedLayer(50)
    dropoutLayer(0.5)
    fullyConnectedLayer(num_features),regressionLayer];

有:

layers = [
    sequenceInputLayer(33)
    lstmLayer(numHiddenUnits,'OutputMode','sequence')
    fullyConnectedLayer(50)
    dropoutLayer(0.5)
    fullyConnectedLayer(num_features),
    regressionLayer];

解释: 在数组声明中,当在新行中添加元素(或用 ; 分隔)时,你正在创建一个列向量,当用 [= 分隔时15=],你正在创建一个行向量。你不知何故把它们搞混了。