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);

采纳的回答

Angelo Yeo
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)
paddedData = 10x3 cell array
{[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double} {[405]} {[10]} {440x5 double}
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);
Training on single CPU. |========================================================================================| | Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Base Learning | | | | (hh:mm:ss) | RMSE | Loss | Rate | |========================================================================================| | 1 | 1 | 00:00:00 | 405.00 | 82012.9 | 0.0010 | | 10 | 10 | 00:00:00 | 397.93 | 79175.6 | 0.0010 | |========================================================================================| Training finished: Max epochs completed.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Build Deep Neural Networks 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by