Azzera filtri
Azzera filtri

error with classes in network classification layer

8 visualizzazioni (ultimi 30 giorni)
Hi all matlab folk,
I am seeking some assistance in solving this challenge and move forward! for some reason I am not getting this and I am in need of some assistance!
This error persists no matter if i set the classification layer to auto and I am finding it challenging to move past this phase of the network!
please see layers! then check the error at the bottom
thanx in advance!
Error using vision.internal.cnn.validation.checkNetworkClassificationLayer (line 11)
The number object classes in the network classification layer must be equal to the number of classes defined in the input
trainingData plus 1 for the "Background" class.
Error in trainRCNNObjectDetector>checkNetworkAndFillRemainingParameters (line 290)
vision.internal.cnn.validation.checkNetworkClassificationLayer(analysis, trainingData);
Error in trainRCNNObjectDetector (line 256)
params = checkNetworkAndFillRemainingParameters(trainingData, network, params);
Error in test19 (line 54)
rcnn = trainRCNNObjectDetector(Wgtruth, Newlayers, options, 'NegativeOverlapRange', [0 0.3])
this is my layers
Newlayers = [
imageInputLayer([32 32 3],"Mean",[],"Normalization","zerocenter", "Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
maxPooling2dLayer([3 3],"Name","maxpool","Stride",[2 2])
convolution2dLayer([5 5],32,"Name","conv_1","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
averagePooling2dLayer([3 3],"Name","avgpool","Stride",[2 2])
convolution2dLayer([5 5],64,"Name","conv_2","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
averagePooling2dLayer([3 3],"Name","avgpool_1","Stride",[2 2])

Risposta accettata

Srivardhan Gadila
Srivardhan Gadila il 4 Mar 2020
Please refer to the following workflow: Create R-CNN Object Detection Network.
The total number of classes the RCNNdetector should detect will be the number of object classes you want to detect plus an additional background class. So try changing the outputSize argument of the fullyConnectedLayer to 3 (in this particular case)
  2 Commenti
Matpar il 4 Mar 2020
Hi Srivardhan Gadila, I solved this and your answer is what I actually did! I messed around changing the values but one thing that was throwing the errors was the procedure of the transfer learning. This was in the wrong place based on the stepwise progression whilst creating the network layers. Thank you very much for responding and acknowledging me
Daniel Rodinger
Daniel Rodinger il 21 Lug 2022
hi guys i have a question. i face a pretty similar situation now, i want to detect one object so it should be 1 +1 for the background calls but i always get the error message
"The number of object classes in the network classification layer must be equal to the number of classes defined in the input trainingData plus 1 for the "Background" class" im really confused i basically just copy pasted the matlab example but it does not work. my trainingData is a 12x2 table so my
close all;
net = resnet50();
lgraph = layerGraph(net);
% figure
% plot(lgraph)
% ylim([-5 16])
% Remove the last 3 layers.
layersToRemove = {
lgraph = removeLayers(lgraph, layersToRemove);
% Display the results after removing the layers.
% figure
% plot(lgraph)
% ylim([-5 16])
% Specify the number of classes the network should classify.
numClasses = 1;
numClassesPlusBackground = numClasses + 1;
% Define new classfication layers
newLayers = [
fullyConnectedLayer(numClassesPlusBackground, 'Name', 'rcnnFC')
softmaxLayer('Name', 'rcnnSoftmax')
classificationLayer('Name', 'rcnnClassification')
% Add new layers
lgraph = addLayers(lgraph, newLayers);
% Connect the new layers to the network.
lgraph = connectLayers(lgraph, 'avg_pool', 'rcnnFC');
% Display the final R-CNN network. This can be trained using trainRCNNObjectDetector.
% figure
% plot(lgraph)
% ylim([-5 16])
load gTruth;
layers = resnet50('Weights', 'none')
trainingData = objectDetectorTrainingData(gTruth);
options = trainingOptions('sgdm', ...
'MiniBatchSize', 128, ...
'InitialLearnRate', 1e-6, ...
'MaxEpochs', 5);
[detector,info] = trainRCNNObjectDetector(trainingData, layers, options, 'NegativeOverlapRange', [0 0.3]);

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by