Error creating a CNN-LSTM network with sequences.

6 ビュー (過去 30 日間)
Mar Ayuso
Mar Ayuso 2024 年 5 月 7 日
編集済み: Alex Wu 2024 年 5 月 13 日
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)

回答 (1 件)

Alex Wu
Alex Wu 2024 年 5 月 13 日
編集済み: Alex Wu 2024 年 5 月 13 日
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.

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by