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

5 visualizaciones (últimos 30 días)
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 comentario
AYUSH ANAND SAGAR
AYUSH ANAND SAGAR el 18 de Sept. de 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

Iniciar sesión para comentar.

Respuestas (1)

Mohammad Sami
Mohammad Sami el 19 de Sept. de 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.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by