Error with layer when trying to train my own CNN
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
Problem is, I have this error message when I try to start the training :
Error using trainNetwork (line 140)
Invalid training data. The output size (250000) of the last layer doesn't match the number of classes (1).
Caused by:
Error using nnet.internal.cnn.util.TrainNetworkDataValidator/assertCorrectResponseSizeForOutputLayer (line
217)
Invalid training data. The output size (250000) of the last layer doesn't match the number of classes (1).
Here is my code :
digitDatasetPath = 'ChinaSet_AllFiles/CXR_png';
digitData = imageDatastore(digitDatasetPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
% creating datastore with files from my folder
trainingNumFiles = 500;
rng(1) % For reproducibility
[trainDigitData,testDigitData] = splitEachLabel(digitData,...
trainingNumFiles,'randomize');
% splits the image files in digitData into two new datastores, trainDigitData and testDigitData
layers = [imageInputLayer([600 600 1]);
convolution2dLayer(500,50);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(500*500);
softmaxLayer();
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',50,...
'InitialLearnRate',0.0001);
convnet = trainNetwork(trainDigitData,layers,options); % starts the training
Does anyone knows where it comes from ?
Thanks in advance!
2 Kommentare
Maria Duarte Rosa
am 15 Dez. 2017
Hi Alizee,
The outputSize of the fullyConnectedLayer should be equal to the number of classes in your dataset. Currently you have outputSize = 500*500. If your digit dataset contains 10 classes then you should use fullyConnectedLayer(10). You can also count the number of classes from the data:
numClasses = numel(categories(trainDigitData.Labels));
Then use this variable in the fully connected layer:
fullyConnectedLayer(numClasses).
Thanks
sasmita mahakud
am 28 Jun. 2019
What will be the fullyconnected layer output If we want to remove noise kind of thing not class?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!