필터 지우기
필터 지우기

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 CenterFile Exchange에서 Custom Training Loops에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by