필터 지우기
필터 지우기

How is data characterised as 'spatial or temporal' in the context of neural networks?

조회 수: 9 (최근 30일)
I have been repeatedly facing this error and it confuses me. Any explanations or general knowledge on the fullyConnectedLayer would be very helpful!
Invalid input data for fully connected layer. The input data must not have both spatial and temporal dimensions.
I am trying to classify 1D time series data (signals) into 2 classes using a 1D CNN using the following code:
inputSize = size(xTrain);
numClasses = 2; % Cracked or not cracked
layers = [
sequenceInputLayer(inputSize,'Name', 'input','MinLength', time_points)
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);
The input data is in a cell array with dimensions (320,2) where col 1 is the signal data and col 2 is the label(a 0 or 1). The signal data is a 2000x1 array with complex values representing the amplitude of a wave at a point in time.
If anyone has any idea how to resolve this - please let me know!
Thank you

채택된 답변

Nayan
Nayan 2023년 3월 7일
As your error suggests, the input data to your fullyConnectedLayer has both spatial and temporal dimensions" . This may have occured because the "maxPooling1dLayer" applied to the "convolution1dLayer(64,10,'Padding', 'same')" retains the number of channels after "maxPooling". You may want to use "layer = flattenLayer" after the maxPooling1dLayer(2,'Stride',2) layer.
I would suggest you to go through https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.flattenlayer.html to read more about flatten.
Also, it would helpful to use "analyzeNetwork" to get more details on the dimensions of each layers.
  댓글 수: 3
Nayan
Nayan 2023년 3월 7일
Happy Learning Nikolas, Hope "analyzeNetwork " can help you understand your model better and get the desired results.
Nikolas Katsaros
Nikolas Katsaros 2023년 3월 7일
I have a lot to learn - this toolbox is very confusing to me

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

추가 답변 (1개)

Matt J
Matt J 2023년 3월 7일
편집: Matt J 2023년 3월 7일
The input data is in a cell array with dimensions (320,2) where col 1 is the signal data and col 2 is the label(a 0 or 1). The signal data is a 2000x1 array with complex values representing the amplitude of a wave at a point in time.
This seems to violate the requirements in the trainNetwork documentation in several ways. See the doc excerpt below, in particular the high-lighted sections.
Additionally, it is not clear how you intend he network to process your complex-valued input. How are the maxpooling layers to maximize over numbers that are not real-valued? How will the backpropagation process take derivatives with respect to complex-valued functions (in theory I guess there is a way, but I'm doubtful if trainNetwork is that fancy). What you might want to do is split the real and imaginary parts of the signal into separate channels.
  댓글 수: 1
Nikolas Katsaros
Nikolas Katsaros 2023년 3월 7일
Thank you - you make a lot of good points that I should address in my code!
I have since separated the sequences and responses into a cell array with the format mentioned above. It is now a [320 1] cell array where each element contains a 2000x1 sequence of timepoints. The responses are stored in a separate categorical array of size [320 1].
This hasn't been successful either and resulted in an error saying I have 'Invalid training data. If the network outputs sequences, then the responses must be a cell array of categorical sequences, or a categorical sequence.'
I am considering restructuring my input data to include the time steps in another channel however I think I would only get more confused.
Thank you for taking the time to help me

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by