Last dimension disappears when I use an arrayDatastore

7 views (last 30 days)
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!

Accepted Answer

Aneela
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”:
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.

More Answers (0)

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!