Last dimension disappears when I use an arrayDatastore
7 views (last 30 days)
Show older comments
Hello everyone,
I was using a 4-d array of shape 8x234x1x1000 to train a ResNet, 8x234 being the size of my matrix, 1 being the number of channels and 1000 the number of points in my training set.
It worked well, however, I now want to use a multiple input neural network and hence need to use an arrayDatastore (I think?)
I specify : XTrain_features = arrayDatastore(features_mat(:,:,:,trainInd), "IterationDimension",4);
However, read(XTrain_features) gives :
1×1 cell array
{8×234 double}
And my neural network which input layer is imageInputLayer([8 234 1]) now gives an error saying I have no channel dimension.
Could someone please give me a workaround?
Thanks!
1 Comment
Accepted Answer
Aneela
on 12 Mar 2025
MATLAB implicitly performs squeezing action on the arrays. It removes singleton dimensions from an array. So, if an array has a size of 2x3x1, MATLAB will often display or treat it as a 2x3 array. This is called “Trailing Singleton Dimensions”.
Please refer to the below MATLAB Answers from the community for more information on “Trailing Singleton Dimensions”:
- https://www.mathworks.com/matlabcentral/answers/1971659-how-to-expand-dimension-of-a-2d-array
- https://www.mathworks.com/matlabcentral/answers/229956-how-can-i-reshape-a-20370x1-matrix-into-2037x10x1
Furthermore, for dlnetworks like “resnet18”, “resnet101”, “resnet50”, it is recommended to use “trainnet” for training.
Please refer to the following MathWorks documentation for more details on various datastores supported by “trainnet” for different input data.
0 Comments
More Answers (0)
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!