我正在尝试训练这个神经网络,trainingD_r是N X 2 double,classTr是N X 1 double,但是我遇到了这个错误:
Error using trainNetwork (line 150)
Invalid network.
Error in script_NN_1 (line 74)
[trainedNet, info] = trainNetwork(trainingD_r,categorical(classTr),layers,training_options);
Caused by:
Layer 4: Input size mismatch. Size of input to this layer is different from the expected input
size.
Inputs to this layer:
from layer 3 (1×1×2 output)
如何解决此错误,这是代码:
training_options = trainingOptions ...
('sgdm', ...
'Verbose', 1 ,...
'VerboseFrequency' , 20, ...
'MaxEpochs', 30, ...
'MiniBatchSize', 128, ...
'Shuffle', 'every-epoch', ...
'ValidationFrequency', 20, ...
'ValidationPatience', 5, ...
'InitialLearnRate', 0.001, ...
'L2Regularization', 0, ...
'Momentum', 0, ...
'ExecutionEnvironment', 'cpu', ...
'Plots','training-progress');
layers = [ ...
imageInputLayer(size(trainingD_r))
convolution2dLayer(size(trainingD_r),2)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer];
[trainedNet, info] = trainNetwork(trainingD_r,categorical(classTr),layers,training_options);