Error on convolutional layer's: input data has 0 spatial dimensions and 0 temporal dimensions.
68 次查看(过去 30 天)
显示 更早的评论
I'm building a Deep Learning model for regression. My training data is composed of 1512 samples of 512 numeric features.
disp(size(X_train)); % 1512x512
disp(size(Y_train)); % 1512x3
layers = [
featureInputLayer(size(X_train, 2))
convolution1dLayer(3, 20)
tanhLayer()
averagePooling1dLayer(2)
convolution1dLayer(3, 10)
tanhLayer()
averagePooling1dLayer(2)
flattenLayer()
fullyConnectedLayer(20)
tanhLayer()
fullyConnectedLayer(10)
tanhLayer()
fullyConnectedLayer(3)
tanhLayer()
regressionLayer()
];
opts = trainingOptions('adam', ...
'MaxEpochs',200, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false);
net = trainNetwork(X_train, Y_train, layers, opts);
However, I get the following error on the first convolutional layer:
Layer 'conv_layer_1': Input data must have one spatial dimension only, one temporal dimension only, or one of each. Instead, it has 0 spatial dimensions and 0 temporal dimensions.
7 个评论
Christian Holz
2023-6-16
Hello, thanks for the tip.
Unfortunately, I have not been able to solve it yet.
The application is not exactly the same for me. Therefore, here is the code excerpt from the network architecture.
The aim of this codepart is to reduce the input number to num (fc-layer) and to perform a combined probability of the number of possibilities (num) with the help of the softmaxLayer and to output the corresponding most probable or highest value with the help of the maxPooling1dLayer.
...
num = 10;
tempLayers = [
fullyConnectedLayer(num,"Name","fc_1")
layerNormalizationLayer("Name","class_layernorm_1")
softmaxLayer("Name","softmax_1")
maxPooling1dLayer(num,"Name","maxPooling_1"];
lgraph = addLayers(lgraph,tempLayers);
...
Christian Holz
2023-6-16
Error using trainNetwork
Invalid network.
Caused by:
Layer 'maxPooling_1': Input data must have one spatial dimension only, one temporal dimension only, or one of each. Instead, it has 0 spatial dimensions and 0 temporal dimensions.
回答(1 个)
Matt J
2023-4-5
编辑:Matt J
2023-4-6
So far, I have only managed to work around the problem by reformulating the training inputs as 2D images of dimension 512x1:
X_train=rand(512,1,1,1512);
Y_train=rand(1512,3);
layers = [
imageInputLayer([512, 1]);
convolution2dLayer([3,1], 20)
tanhLayer()
averagePooling2dLayer([2,1])
convolution2dLayer([3,1], 10)
tanhLayer()
averagePooling2dLayer([2,1])
flattenLayer()
fullyConnectedLayer(20)
tanhLayer()
fullyConnectedLayer(10)
tanhLayer()
fullyConnectedLayer(3)
tanhLayer()
regressionLayer()
];
analyzeNetwork(layers)
opts = trainingOptions('adam', ...
'MaxEpochs',5, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ExecutionEnvironment','cpu');
net = trainNetwork(X_train, Y_train, layers, opts);
0 个评论
另请参阅
类别
在 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!