Number of observations in X and Y disagree.
5 ビュー (過去 30 日間)
古いコメントを表示
Hey everyone - Cannot for the life of me get this to work. No matter what I do, I get the "Number of observations in X and Y disagree." error. I understand that X train should be a HxWxCxN 4-D matrix and that YTrain should be a Nx1 matrix. I've checked that already and this seems correct.
Any help would be appreciated.
Thanks,
Ben Payne
data = load('C:\Users\Ben Payne\Downloads\matlab\matlab\emnist-letters.mat');
testImages = reshape(data.dataset.test.images.', 28, 28, []);
figure;
for i = 1:20
subplot(4,5,i);
imshow(testImages(:,:,i));
end
trainingImages = reshape(data.dataset.train.images.', 28, 28, []);
idx = randperm(size(trainingImages,3),1000);
XValidation = trainingImages(:,:,idx);
YValidation = categorical(data.dataset.train.labels(idx));
layers = [
imageInputLayer([28 28 1])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(10)
softmaxLayer
classificationLayer
];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',8, ...
'Shuffle','every-epoch', ...
'ValidationData',{XValidation,YValidation}, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
XTrain = reshape(data.dataset.train.images', 28, 28, 1, []);
YTrain = categorical(data.dataset.train.labels);
net = trainNetwork(XTrain, YTrain, layers, options);
The dataset can be downloaded from here
0 件のコメント
回答 (1 件)
Shashank Gupta
2020 年 10 月 28 日
Hi Ben,
I am not sure if you already figured out the mistake. Neverthless it seems the YTrain has 26 classes which is conflcting with the number of neuron(10) defined at the last fully connnected layer. Ideally both should be same, I did not dig much in to the code but surely changing the neuron to 26 would solve your problem.
I hope it helps you.
Cheers.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!