Azzera filtri
Azzera filtri

Error reshape in neural network

4 visualizzazioni (ultimi 30 giorni)
Paola HUMBERT
Paola HUMBERT il 15 Mag 2020
Modificato: Asvin Kumar il 22 Set 2021
Hello,
I'm trying to code a neural network (EEG2Net) to classify a signal but I get an error that I can't solve. My input data (a signal at the beginning) was changed into a cell array of dimension 30*80 and the labels are in a cell array of dimension 30*1.
The code is the following :
DataSize = size(CNN_TrainingData);
LabelSize = size(CNN_TrainingLabel);
%% Building the EEG2Net layers
EEG2Net = [
sequenceInputLayer([DataSize 1],'Name','Input')
sequenceFoldingLayer('Name','fold')
convolution2dLayer([2 1],16,'Stride',1,'Padding','Same','Name','ConvolutionLayer1')
batchNormalizationLayer('Name','BatchNorm1')
reluLayer('Name','ReLu1')
maxPooling2dLayer([2 2],'stride',[2 2],'Padding','Same','Name','MaxPooling1')
convolution2dLayer([1 64],8,'Stride',1,'Padding','Same','Name','ConvolutionLayer2')
batchNormalizationLayer('Name','BatchNorm2')
reluLayer('Name','ReLu2')
maxPooling2dLayer([2 2],'stride',[2 2],'Padding','Same','Name','MaxPooling2')
dropoutLayer(0.5,'Name','Dropout2')
convolution2dLayer([5 5],4,'Stride',1,'Padding','Same','Name','ConvolutionLayer3')
batchNormalizationLayer('Name','BatchNorm3')
reluLayer('Name','ReLu3')
maxPooling2dLayer([2 2],'Stride',[1 1],'Padding','Same','Name','MaxPooling3')
dropoutLayer(0.5,'Name','Dropout3')
flattenLayer('Name','Flatten4')
fullyConnectedLayer(1024,'Name','DenseLayer4')
reluLayer('Name','ReLu4')
dropoutLayer(0.5,'Name','Dropout4')
fullyConnectedLayer(2,'Name','DenseLayer5')
sequenceUnfoldingLayer('Name','unfold')
softmaxLayer('Name','Softmax5')
classificationLayer('Name','Classification')];
lgraph = layerGraph(EEG2Net);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
%% Analyze the network
%analyzeNetwork(lgraph)
%% Training of network
options = trainingOptions('adam','Plots','training-progress','MiniBatchSize',miniBatchSize);
trainetNet = trainNetwork(CNN_TrainingData, CNN_TrainingLabels, lgraph, options);
The error message is the following :
Error using trainNetwork (line 170)
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the
appropriate size for that dimension.
Error in Test_EEG2Net (line 65)
trainetNet = trainNetwork(CNN_TrainingData, CNN_TrainingLabels, lgraph, options);
Caused by:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the
appropriate size for that dimension.
I have changed tried a lot of changes in the code but i can't find what has to be done, if someone could help me I would really appreciate it.
Thank you.
(I'm using the 2020a version of matlab)

Risposte (1)

Asvin Kumar
Asvin Kumar il 19 Mag 2020
The first input argument to the sequenceInputLayer should be the size of the input sequence at each time step.
If your input is 30 sequences of length 80 each, then this argument would be 1 because that’s the size of the input at each step.
sequenceInputLayer(1,'Name','Input')
Have a look at the Japanese Vowel Classification example where the input is many sequences of variable length but the input at each time step is a 12-length vector.
This still raises the question as to why your dataset is a cell array of 30*80. You can have a look at the example linked above to get a better idea about the way the data should be shaped too.
  6 Commenti
France
France il 17 Set 2021
I have exaclty the same problem...
when everything should work, it appears this error message:
Error using trainNetwork (line 170)
Invalid training data. Sequence responses must have the same sequence length as the corresponding
predictors.
Did you find out how to solve this problem?
Many thanks
Asvin Kumar
Asvin Kumar il 22 Set 2021
Modificato: Asvin Kumar il 22 Set 2021
Hi France, this seems like a straightforward mismatch between the sizes of the data.
I would recommend posting a new question in the forum and you should easily be able to get help. Please provide more details about the data that you're using, sample code and any example data to reproduce the error that you are seeing.
Old/Answered posts are not actively monitored and may not get much responses.

Accedi per commentare.

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by