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 comentarios

Hamid Ebrahimi
Hamid Ebrahimi el 24 de Dic. de 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 el 24 de Dic. de 2019
Hi,trainD is two class image and targetD is the prediction of two class
ero cnn.png

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 23 de Dic. de 2019

Comentada:

el 24 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by