images classification with cnn error

Hi all, I run cnn with some images but I get an error what is wrong?
error:
Error using trainNetwork (line 154)
Invalid training data. X and Y must have the same number of observations.
Error in cnnmatlb (line 35)
net = trainNetwork(trainD,targetD',layers,options);
Caused by:
Error using nnet.internal.cnn.util.NetworkDataValidator/assertXAndYHaveSameNumberOfObservations (line 142)
Invalid training data. X and Y must have the same number of observations.
clear all
clc
Path = 'D:\eegdata\*.jpg';
Files = dir(Path);
for i=1:length(Files)
fn = [Path(1:end-5) Files(i,1).name];
I=imread(fn);
I=imresize(I,[28,28]);
I(:,:,3)=rgb2gray(I);
[m,n,o]=size(I);
if i<=30
trainD(:,:,:,1)= I(:,:,:);
end
if i>=31
trainD(:,:,:,2)=I(:,:,:);
end
targetD=categorical([1;2]);
%% Define Network Architecture
% Define the convolutional neural network architecture.
layers = [
imageInputLayer([m n o]) % 22X5X1 refers to number of features per sample
convolution2dLayer(n,16,'Padding','same')
reluLayer
fullyConnectedLayer(384) % 384 refers to number of neurons in next FC hidden layer
fullyConnectedLayer(384) % 384 refers to number of neurons in next FC hidden layer
fullyConnectedLayer(2) % 6 refers to number of neurons in next output layer (number of output classes)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm',...
'MaxEpochs',5000, ...
'Plots','training-progress');
net = trainNetwork(trainD,targetD',layers,options);
predictedLabels = classify(net,trainD)'
end

3 commentaires

Hamid Ebrahimi
Hamid Ebrahimi le 24 Déc 2019
There's not anyone can help me in this issue???
What does this show in the command window
whos trainD
whos targetD
Hamid Ebrahimi
Hamid Ebrahimi le 24 Déc 2019
Hi,trainD is two class image and targetD is the prediction of two class
ero cnn.png

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by