Invalid training data. The output size (8) of the last layer does not match the number of classes (6).

1 vue (au cours des 30 derniers jours)
clc;
close all;
clear all;
%% load network
net=alexnet;
ppl=net.Layers;
net=net.Layers(1:19);
% layers(23)=fullyConnectedLayer(7);
% layers(25)=classificationLayer;
layers=[net
fullyConnectedLayer(8)
softmaxLayer()
classificationLayer()];
matlabpath='C:\Users\ayush\MATLAB_CAPSTONE\Dataset1';
data=fullfile(matlabpath,'trainingset');
train=imageDatastore(data,'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames');
[imgtrain,imgtest]=splitEachLabel(train,0.8,'randomized');
count=train.countEachLabel;
%% training
opt=trainingOptions('sgdm','MaxEpochs',2,'InitialLearnRate',0.001,'Plots','training-progress','MiniBatchSize',64);
TrainNet=trainNetwork(train,layers,opt);
%% accuracy
pred=classify(TrainNet,imgtest);
accuracy=mean(pred==imgtest.Labels);
  1 commentaire
AYUSH ANAND SAGAR
AYUSH ANAND SAGAR le 18 Sep 2020
Error using trainNetwork (line 170)
Invalid training data. The output size (8) of the last layer does not match the number of classes (6).
Error in transfer (line 27)
TrainNet=trainNetwork(train,layers,opt);
this is the error thats popping up all the time

Connectez-vous pour commenter.

Réponses (1)

Mohammad Sami
Mohammad Sami le 19 Sep 2020
Your final layer has 8 outputs, however your image data store only has 6 labels / classes. If you expect there to be 8 classes, check you image data store. If there are 6 classes, then change your final layer to have 6 outputs.

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by