Borrar filtros
Borrar filtros

Error creating a CNN-LSTM network with sequences.

11 visualizaciones (últimos 30 días)
Mar Ayuso
Mar Ayuso el 7 de Mayo de 2024
Editada: Alex Wu el 13 de Mayo de 2024
Hello:
I'm writting here because I have the following issue:
I want to train a CNN-LSTM deep network in order to classify sequences into 2 labels.
I have 252 sequences of 45 seconds of 1891 channels, 80% of then (201) are used as training, 10% (25) are used in validation and the other 10% (26) are used in testing.
I created the neural network in Deep Network Designer as follows:
When I try to train the network, this error message is shown:
Error using trainnet (line 46)
Number of observations in predictors (201) and targets (1) must match. Check that the data and network are
consistent.
Te workspace generated is this:
Could somebody help me find where is the problem please?
Thank you so much.
This is the code:
rng('shuffle')
load('datos.mat');
data_ordenado = cell(252,1);
mylabels_ordenado = cell(252,1);
data_desordenado = cell(252,1);
mylabels_desordenado = cell(252,1);
for i = 1:252
if (i<=131)
data_ordenado{i} = cxy1(:,:,i)';
mylabels_ordenado{i} = 'Pre_experiment';
else
data_ordenado{i} = cxy17(:,:,i-131)';
mylabels_ordenado{i} = 'Post_experiment';
end
end
idx = randperm(252);
for i = 1:252
data_desordenado{i} = data_ordenado{idx(i)};
mylabels_desordenado{i} = mylabels_ordenado{idx(i)};
end
labels = categorical(mylabels_desordenado);
classNames = categories(labels);
numObservations = numel(data_desordenado);
[idxTrain,idxValidation,idxTest] = trainingPartitions(numObservations,[0.8 0.1 0.1]);
XTrain = data_desordenado(idxTrain);
TTrain = labels(idxTrain);
XValidation = data_desordenado(idxValidation);
TValidation = labels(idxValidation);
XTest = data_desordenado(idxTest);
TTest = labels(idxTest);
options = trainingOptions("adam", ...
MaxEpochs=500, ...
InitialLearnRate=0.0005, ...
GradientThreshold=1, ...
ValidationData={XValidation,TValidation}, ...
Shuffle = "every-epoch", ...
Plots="training-progress", ...
Metrics="accuracy", ...
Verbose=false);
net = trainnet(XTrain,TTrain',net_1,"crossentropy",options);
scores = minibatchpredict(net,XTest);
YTest = scores2label(scores,classNames);
acc = mean(YTest == TTest)
figure
confusionchart(TTest,YTest)

Respuestas (1)

Alex Wu
Alex Wu el 13 de Mayo de 2024
Editada: Alex Wu el 13 de Mayo de 2024
Number of observations in predictors (201) and targets (1) must match.
This means during training, your input data X and target data T have different number of observations.
net = trainnet(XTrain,TTrain',net_1,"crossentropy",options);
Your TTrain matrix has dimensions 201x1. However, transposing it results in dimensions of 1x201, which is interpreted as a single observation. Try removing the transpose operation here.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by