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

1 回表示 (過去 30 日間)
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 件のコメント
AYUSH ANAND SAGAR
AYUSH ANAND SAGAR 2020 年 9 月 18 日
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

サインインしてコメントする。

回答 (1 件)

Mohammad Sami
Mohammad Sami 2020 年 9 月 19 日
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.

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by