How to create a datastore for using the Deep Network Designer App?

I'm trying to use the Deep Network Designer app (R2021b) to perform regression between numeric inputs and outputs. I have prepared the trainind dataset in a matrix X of size n x f, where f is the number of features, and a matrix Y of size n x r, where r is the number of responses (n is the number of observations). Similarly, Xv and Yv hold the validation data. When I run the app, I see that it needs the data to be in a datastore, so I tried the following to make the appropriate datastores: (f = 3, r = 5, n = 500, n_val = 100).
ar_c = mat2cell([X Y],ones(500,1),[3,5]);
arv_c = mat2cell([Xv Yv],ones(100,1),[3,5]);
ds = arrayDatastore(ar_c,'OutputType','same');
ds_v = arrayDatastore(arv_c,'OutputType','same');
The datastores ds and ds_v get accepted as legitimate input (I can see the first 5 observations previewed).
But when I hit "train", I get the following error: Training with trainNetwork failed. Input datastore returned more than one observation per row for network input 1. (not sure why the "Don't" rules for posting recommend against pasting images of error messages).
As per the instructions given to mat2cell, I have only one row per observation (or so I think). Can someone please tell me what I'm doing wrong here? Thanks!

 Accepted Answer

From the above information, I think your input layer would be a featureInputLayer. So according to your training data, the output of read operation on the combined datastore should be as follows:
>> read(cds)
ans =
1×2 cell array
{3×1 double} {5×1 double}
For more information you can refer to the documentation of trainNetwork and desciption of training data format for feature data in case of a datastore: features - trainNetwork.
I am attaching code to generate random training data:
f = 3; r = 5; n = 5;
layers = [featureInputLayer(f)
fullyConnectedLayer(r)
regressionLayer];
xtrain = randn(f,n);
ytrain = randn(r,n);
xds = arrayDatastore(xtrain,IterationDimension=2);
yds = arrayDatastore(ytrain,IterationDimension=2);
cds = combine(xds,yds)
cds =
CombinedDatastore with properties: UnderlyingDatastores: {[1×1 matlab.io.datastore.ArrayDatastore] [1×1 matlab.io.datastore.ArrayDatastore]} SupportedOutputFormats: ["txt" "csv" "xlsx" "xls" "parquet" "parq" "png" "jpg" "jpeg" "tif" "tiff" "wav" "flac" "ogg" "mp4" "m4a"]

5 Comments

Thanks for the clarification! The trouble with what I did was that each of the cells of the combined datastructure was a row vector, whereas it needed to be a column vector. In hindsight I should have realized this just by parsing the error message better!
@xadu Can you clarify how were you able to solve your error ?
I am training a multi-input network. I have a 3D image in one path, and a 4x1 feature vector image in the second. I have generated a combined datastore, with output being a binary class. I am getting the same error you got.
Any clarification will be helpful?
Hey Srivardhan,
Would you be able to comment on the error I am getting.
My inputs are:
Input 1: 3D image 124 x 124 x 124
Input 2: 4 features vector
Output: Binary class.
This is my combined datastore
dsTrain =
CombinedDatastore with properties:
UnderlyingDatastores: {1×3 cell}
SupportedOutputFormats: ["txt" "csv" "xlsx" "xls" "parquet" "parq" "png" "jpg" … ]
Error using trainNetwork (line 184)
Input datastore returned more than one observation per row for network input 2.
Hey @Bahar Dadfar No, I was not able to solve this issue. At that time, I was trying to build a multi-modal network using Matlab. My inputs were 3D image and a vector of 4 features. The example of multi-modal network in Matlab uses 2D (not 3D Images) and I was getting this error. I reached out to the deep learning team in Matlab and this was not solved. I haven't checked for a while, but I think that Matlab still doesn't have a clear straightfroward process to do multi-modal networks and basically datasets.
Are you trying to do the same?

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!