How is data characterised as 'spatial or temporal' in the context of neural networks?
12 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1316840/image.png)
另请参阅
类别
在 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!