processImagesMNIST doesn't give the right data format for trainNetwork
3 次查看(过去 30 天)
显示 更早的评论
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?
回答(1 个)
Aman
2023-9-12
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 个评论
另请参阅
类别
在 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!