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 个评论
Hamid Ebrahimi
2019-12-24
Image Analyst
2019-12-24
What does this show in the command window
whos trainD
whos targetD
Hamid Ebrahimi
2019-12-24
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
