processImagesMNIST doesn't give the right data format for trainNetwork

6 ビュー (過去 30 日間)
Runcong Kuang
Runcong Kuang 2022 年 7 月 31 日
回答済み: Aman 2023 年 9 月 12 日
Loading mnist:
According to the dataset for DL,
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 件のコメント
Runcong Kuang
Runcong Kuang 2022 年 7 月 31 日
I use
XTrain = extractdata(XTrain)
to convert dlarray to numerical array.
And then it works.
But I believe dlarray is advanced for doing DL. If I convert it back to do the DL, I think it's not efficient.
What's the best way to make use of the dlarray directly? Any toolbox?
Thanks.

サインインしてコメントする。

回答 (1 件)

Aman
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

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by