C-RNN regression error (Array inputs have incompatible channel dimensions)
5 次查看(过去 30 天)
显示 更早的评论
Hi.
I am writing a C-RNN regression learning code. The loaded "paddedData2.mat" file is saved as paddedData, and it is stored as an N X 3 cell, as shown in the attached image. The input matrix used for training is the 3rd column of paddedData, which is [440 5] double, and the regression variable is the values in the 1st column. With this, I plan to create features of size [436 1] using two [3 3] kernels of convolution and train them using LSTM. The code is as follows. When running this code, the training window pops up, and at the same time, an error message "Array inputs have incompatible channel dimensions." occurs. Is there a solution?
clc;
clear all;
load("paddedData2.mat","-mat")
XTrain = paddedData(:,3);
YTrain1 = cell2mat(paddedData(:,1));
layers = [
sequenceInputLayer([440 5 1])
convolution2dLayer(3,8)
batchNormalizationLayer
reluLayer
convolution2dLayer(3,8)
batchNormalizationLayer
reluLayer
flattenLayer
fullyConnectedLayer(100)
lstmLayer(100,'OutputMode','last')
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',2000, ...
'MiniBatchSize',100, ...
'Plots','training-progress');
net = trainNetwork(XTrain, YTrain1, layers, options);
0 个评论
采纳的回答
Angelo Yeo
2024-5-16
It might be a bug in R2022a, but I'm not sure where exactly the error comes from because it uses a "builtin" function. However, it looks like the issue is fixed in a recent release. You can see that there is no issue in R2024a.
Please update to the most recent version of MATLAB and run the code.
clear;
paddedData = cell(10, 3); % Intentionally changed the #observations from 900 to 10 for reproduction purpose
paddedData(:,1) = cellfun(@(x) 405, paddedData(:,1), 'UniformOutput', false);
paddedData(:,2) = cellfun(@(x) 10, paddedData(:,2), 'UniformOutput', false);
paddedData(:,3) = cellfun(@(x) rand(440, 5), paddedData(:,3), 'UniformOutput', false)
XTrain = paddedData(:,3);
YTrain1 = cell2mat(paddedData(:,1));
layers = [
sequenceInputLayer([440 5 1])
convolution2dLayer(3,8)
batchNormalizationLayer
reluLayer
convolution2dLayer(3,8)
batchNormalizationLayer
reluLayer
flattenLayer
fullyConnectedLayer(100)
lstmLayer(100,'OutputMode','last')
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',10, ... % Intentionally changed the max epochs for reproduction purpose
'MiniBatchSize',100, ...
'Plots','none'); % Intentionally changed 'none' for reproduction purpose
net = trainNetwork(XTrain, YTrain1, layers, options);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Build Deep Neural Networks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!