简体   繁体   English

sequenceInputLayer() 被连接的数组的维度不一致

[英]sequenceInputLayer() Dimensions of arrays being concatenated are not consistent

I try to create an LSTM model.我尝试创建一个 LSTM 模型。 I get following error:我收到以下错误:

Error using vertcat Dimensions of arrays being concatenated are not consistent.错误使用 vertcat 被连接的数组的维度不一致。 Error in source (line 9) sequenceInputLayer(33)源错误(第 9 行) sequenceInputLayer(33)

What should be the input of sequenceInputLayer and its size? 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);

The problem is not in sequenceInputLayer , the problem is in the way you are creating the layers array.问题不在于sequenceInputLayer ,问题在于您创建layers数组的方式。

Replace:代替:

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

With:和:

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

Explanation: In an array declaration, when adding elements in new lines (or separating by ; ) you are crating a columns vector, when separating by , , you are crating a row vector.说明:在数组声明中,当在新行中添加元素(或以;分隔)时,您正在创建列向量,当以,分隔时,您正在创建行向量。 Somehow you mixed them up.不知怎的,你把它们混在一起了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接的数组的尺寸不一致,但两个数组的大小相同 - Dimensions of arrays being concatenated are not consistent but both arrays have the same size 在MATLAB中调试错误“被连接的数组的维度不一致” - Debugging the error "Dimensions of arrays being concatenated are not consistent" in MATLAB 使用 horzcat 时出错 连接的 arrays 的维度不一致。 Matlab - Error using horzcat Dimensions of arrays being concatenated are not consistent. Matlab bsxfun:所连接矩阵的维数不一致 - bsxfun: Dimensions of matrices being concatenated are not consistent matlab连接的矩阵尺寸不一致 - matlab Dimensions of matrices being concatenated are not consistent 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent 如何解决:使用horzcat时发生错误所连接矩阵的维数不一致 - How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters 我的代码运行,有时会出现错误“使用horzcat时出错,所连接的矩阵维数不一致。” - My code runs then sometimes it has error “Error using horzcat Dimensions of matrices being concatenated are not consistent.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM