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
댓글 수: 0
채택된 답변
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.
Read about analyzeNetwork from https://www.mathworks.com/help/deeplearning/ref/analyzenetwork.html
댓글 수: 3
Nayan
2023년 3월 7일
Happy Learning Nikolas, Hope "analyzeNetwork " can help you understand your model better and get the desired results.
추가 답변 (1개)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!