C-RNN regression error (Array inputs have incompatible channel dimensions)
5 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Angelo Yeo
on 16 May 2024
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 Comments
More Answers (0)
See Also
Categories
Find more on Build Deep Neural Networks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!