I keep getting this error
"Incompatible input and output sequence lengths. The network must return sequences with the same length as the
input data or a sequence with length one."
when I try to run this 1D CNN:
(For reference I am trying to analyse 320 signals with 2000 time points each)
inputSize = size(xTrain());
numClasses = 2; % Cracked or not cracked
layers = [
sequenceInputLayer(time_points,'Name', 'input','MinLength', 2000)
convolution1dLayer(32,20,'Padding', 'same')
batchNormalizationLayer
reluLayer
maxPooling1dLayer(2,'Stride',2)
convolution1dLayer(64,10,'Padding', 'same')
batchNormalizationLayer
reluLayer
maxPooling1dLayer(2,'Stride',2)
fullyConnectedLayer(256)
reluLayer
dropoutLayer(0.5)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
%----------------------Define training options-----------------------------
options = trainingOptions('adam', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',50, ...
'MiniBatchSize',128, ...
'Shuffle','every-epoch', ...
'ValidationData',{xTest,yTest}, ...
'ValidationFrequency',5, ...
'Verbose',false, ...
'Plots','training-progress');
% Train the network
net = trainNetwork(xTrain, yTrain, layers, options);
This is my first time using these neural networks so I have left all the layers and options in case there is an error in those. Any help would be useful.
Thank you

 채택된 답변

Matt J
Matt J 2023년 3월 2일

0 개 추천

Shouldn't your input layer be,
sequenceInputLayer(inputSize,'Name', 'input','MinLength', time_points)

댓글 수: 5

Nikolas Katsaros
Nikolas Katsaros 2023년 3월 2일
Thank you that seems to have fixed it. Can you explain why that worked? 'time_points' is set equal to 2000 and inputSize is equal to [320, 1] now. I thought inputSize is supposed to be equal to the number of features in the sequence?
Matt J
Matt J 2023년 3월 2일
Yes, you have 320 features and 2000 time points.
Nikolas Katsaros
Nikolas Katsaros 2023년 3월 2일
Okay, I am now getting an error saying that the input data to my fullyConnectedLayer is invalid as it cannot have both spatial and temporal dimensions. How can this be possible if each sequence is only 1D (2000,1)? I have tried taking the real component of each value but this doesn't change anything
Matt J
Matt J 2023년 3월 2일
Seems like a good question. You should post it! However, if you do, you should attach an example of the training input that triggers the error, so that people can reproduce and study it.
Nikolas Katsaros
Nikolas Katsaros 2023년 3월 3일
Will do - thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 3월 2일

댓글:

2023년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by