필터 지우기
필터 지우기

images classification with cnn error

조회 수: 1 (최근 30일)
Hamid Ebrahimi
Hamid Ebrahimi 2019년 12월 23일
댓글: Hamid Ebrahimi 2019년 12월 24일
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
Image Analyst
Image Analyst 2019년 12월 24일
What does this show in the command window
whos trainD
whos targetD
Hamid Ebrahimi
Hamid Ebrahimi 2019년 12월 24일
Hi,trainD is two class image and targetD is the prediction of two class
ero cnn.png

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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