processImagesMNIST doesn't give the right data format for trainNetwork
4 views (last 30 days)
Show older comments
Loading mnist:
I load MNIST by this:
filenameImagesTrain = 'train-images-idx3-ubyte.gz';
filenameLabelsTrain = 'train-labels-idx1-ubyte.gz';
XTrain = processImagesMNIST(filenameImagesTrain);
YTrain = processLabelsMNIST(filenameLabelsTrain);
By running whos XTrain and YTrain,
XTrain size: 28 28 1 6000, class: dlarray, YTrain size: 60000 1, class: categorical.
Training network
I define a layers as the Convolutional neural network.
When I run the training,
net = trainNetwork(XTrain, YTrain, layers, options);
It throws the error:
Invalid 2-D image training data. Specify image data as a 3-D numeric array containing a single image, a 4-D numeric array containing multiple images, a datastore, or a table containing image file paths or images in the first column.
But XTrain is indeed 4-d array.
What's the problem here?
Answers (1)
Aman
on 12 Sep 2023
Hi Runcong,
It is my understanding that you are having issues while loading the data for model training.
The “processImagesMNIST” function returns a “dlarray”, and the “trainNetwork” method does not accept “dlarray” as an input parameter. In order to resolve the error, you need to convert the “dlarray” into a numerical array using the “extractdata” function and then pass the numerical array to the “trainNetwork” function.
You can convert the “dlarray” to a numerical array in the following manner:
XTrain = extractdata(XTrain);
Please refer to the following links to know more about the “trainNetwork” function and the list of the functions that support “dlarray”:
Hope this helps and resolves your error!
Regards,
Aman Mehta
0 Comments
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!