Clear Filters
Clear Filters

Training a deep neural network with a database as input

41 views (last 30 days)
giulia
giulia on 18 Jul 2024 at 17:48
Commented: giulia on 20 Jul 2024 at 8:05
After converting my data into a combined datastore, I tried training a deep neural network with the architecture shown below but the error " Error forming mini-batch for network input "sequence_prop". Data interpreted with format "CBT". To specify a different format, use the InputDataFormats option.
Error in netPaperv4 net = trainnet(dsTrain, net, "mse", options);
Caused by:
Batch dimension of datastore must match the format batch dimension (2)." occurred.
Here a datastore preview: 1×2 cell array
{[-0.2964 -0.2723 0 0.3049 0.1613 -0.9312]} {[2.2746]}
I want to combine three different sequence inputs (the goal is time series forecasting, not image classification: my inputs are all time-depending sequences) : two of size 1 and the other of size 4 to predict a single output (size 1).
Can anyone help me solve this? I can provide code if needed.

Answers (1)

Ruchika Parag
Ruchika Parag on 19 Jul 2024 at 18:02
Hi Giulia, it looks like you are facing an error while training your deep neural network for time series forecasting. The error indicates that the batch dimension of your datastore does not match what the network expects.To fix this, first, ensure your datastore is set up correctly. Since you have three sequences (two of size 1 and one of size 4), they need to be the same length for batching. You can pad the shorter sequences with zeros to achieve this.Next, specify the input data format in your training options. For example, you can use the "CBT" format (Channel-Batch-Time) like this:
options = trainingOptions('adam', ...
'InputDataFormats', 'CBT', ...
'MaxEpochs', 100, ...
'MiniBatchSize', 32, ...
'Verbose', false);
Here is an example of how you might set everything up:
data = {[-0.2964 -0.2723 0 0.3049 0.1613 -0.9312], [2.2746]};
dsTrain = arrayDatastore(data, 'OutputType', 'cell');
net = trainnet(dsTrain, net, "mse", options);
By ensuring your sequences are the same length and specifying the correct input format, you should be able to resolve the error. Hope this helps!
  1 Comment
giulia
giulia on 20 Jul 2024 at 8:05
What I have done to preprocess my data is:
dsXCTrain = arrayDatastore([X,C]);
% X is a 19079x2 double array (the first column is the first input, the second column the second input)
% C is a 19079x4 double array (these are 4 covariates, that should be treated as feature input)
dsTTrain = arrayDatastore(T); % T is a 19079x1 double array (target array)
dsTrain = combine(dsXCTrain, dsTTrain);
Given the architecture of the net
I have set these options to the net:
options = trainingOptions("adam", ...
"MaxEpochs", 150, ...
"SequencePaddingDirection", "left", ...
"Shuffle", "every-epoch", ...
"Plots", "training-progress", ...
"Verbose", false, ...
"InputDataFormats", {'CBT','CBT','CBT'}, ...
"TargetDataFormats", {'CBT'});
Then I tried training the net with the command:
net = trainnet(dsTrain, net, "mse", options);
I got this error:
Error using trainnet (line 46)
Error forming mini-batch for network input "sequence_prop". Data interpreted with format "CBT".
To specify a different format, use the InputDataFormats option.
Error in netPaperv4 (line 116)
net = trainnet(dsTrain, net, "mse", options);
Caused by:
Batch dimension of datastore must match the format batch dimension (2).
What should I do to solve this?

Sign in to comment.

Categories

Find more on Deep Learning Toolbox 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!