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

6 ビュー (過去 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 Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by