Error using trainNetwork...output size (4) of last layer does not match the number of classes (2)

1 Ansicht (letzte 30 Tage)
I have downloaded example code from this MathWorks tutorial to try my hand at training a neural network from scratch: https://www.mathworks.com/videos/training-a-neural-network-from-scratch-with-matlab-1492008542195.html
The tutorial states I may replace the training data in the example code with my own and that is what I have been trying to do.
The error in my code occurs at the line:
[net, info] = trainNetwork(imds, layers, opts);
The error states:
Error using trainNetwork (line 170)
Invalid training data. The output size (4) of the last layer does not match the number of classes (2).
I suspect the trouble lies in the code that I am using to load the training data, as I am unsure of whether this code loads the images as necessary:
categories = {'dogs','cats'};
rootFolder = 'C:\Users\js\Desktop\training'
imds = imageDatastore(fullfile(rootFolder, categories), ...
'LabelSource', 'foldernames', 'IncludeSubfolders',true, 'FileExtensions','.jpg');
I am trying to load training images from two folders containing 32x32 .jpg images of cats and dogs: ...\training\cats and ...\training\dogs
Are the images being loaded properly and is that the source of the error in my code?
Thanks!

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by