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 CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by