How to determine the dimension label of a vector and MiniBatchFormat for input of a deep neural network

6 次查看(过去 30 天)
I am trying to construct a mutiple input layer deep-NN, under the help of example "Train Network on Image and Feature Data". The difference are that my input for NN are "image" and a "vector" which may affect the result of classification, rather "image" and " its angle" as example shows, and i have two output layers.
this is the dimension of a input sample
"Imageinput" [244 244 3]
"processparameter' [5 1]
i have already make the arraydatastore and custom loop setting, and when i use this setting for check runing, it works but "Loss value" unstable, and iteration cost so much time
numEpochs = 20;
miniBatchSize = 1;
mbq = minibatchqueue(dsTrain,...
'MiniBatchSize',miniBatchSize,...
'MiniBatchFcn', @preprocessData,...
'MiniBatchFormat',{'SSCB','C','',''});
so i want change the miniBatchSize to any other value, like 10, but it comes an error
numEpochs = 20;
miniBatchSize = 10;
mbq = minibatchqueue(dsTrain,...
'MiniBatchSize',miniBatchSize,...
'MiniBatchFcn', @preprocessData,...
'MiniBatchFormat',{'SSCB','C','',''});
-----------------------------------------------------------------
Error using minibatchqueue (line 319)
Unable to apply MiniBatchFormat value 'C' to output 2.
Error in Multi_Task_Learning007_1 (line 231)
mbq = minibatchqueue(dsTrain,...
Caused by:
Error using dlarray (line 174)
Not enough dimension labels. Setting the label of just one dimension is supported only for vector arguments.
i have try another 'MiniBatchFormat' for "processparameter'' like 'CB' or 'SCB', but still can't work.
Specially, when i set
'MiniBatchFormat',{'SSCB','SCB','',''}
which i think will be more reasonable for a 'vector' input which will be batched, but it comes another error: "Layer 'features': Invalid input data. Invalid number of spatial dimensions. Layer expects 0 but received 1."
by the way, this is my 'preprocessData' function
function [X1,X2,Y,angle] = preprocessData(X1Cell,X2Cell,YCell,angleCell)
% Extract image data from cell and concatenate
X1 = cat(4,X1Cell{:});
% Extract feature data from cell and concatenate
X2 = cat(3,X2Cell{:});
% Extract label data from cell and concatenate
Y = cat(2,YCell{:});
% Extract angle data from cell and concatenate
angle = cat(2,angleCell{:});
% One-hot encode labels
Y = onehotencode(Y,1);
end
i don't know why this error come and how can i do to run this NN with a bigger miniBatchSize?

回答(1 个)

Shubham
Shubham 2024-1-16
Hi 畅 孙 ,
When working with multiple input layers in a deep neural network using MATLAB, it's essential to ensure that the minibatch queue (mbq) is set up correctly to handle the different input types and their corresponding dimensions. It looks like you are facing issues with setting the MiniBatchFormat option for the second input, which is a vector.
The error message you're encountering indicates that there's a mismatch between the expected dimensions of your input data and the format specified in the MiniBatchFormat. Let's address these issues step by step.
Error Analysis:
  1. Error with 'C' format for the second input: The error message "Not enough dimension labels. Setting the label of just one dimension is supported only for vector arguments." suggests that when you use 'C' as the minibatch format for your second input, it expects a vector, but you might be providing a matrix or an array with more than one dimension.
  2. Error with 'SCB' format for the second input: The error message "Invalid number of spatial dimensions. Layer expects 0 but received 1." suggests that the network expects the second input to have no spatial dimensions, but the 'SCB' format implies one spatial dimension (S), which is not compatible with your input.
To resolve the errors, you need to ensure that the minibatch format correctly reflects the dimensions of your input data. For the second input, which is a vector, you should use 'CB' or 'BC' (depending on whether the channel dimension comes before or after the batch dimension).
Here's what you should consider:
  • Your second input is a process parameter vector with a dimension of [5 1]. When you create a minibatch of size 10, the dimension would become [5 10], where 5 is the feature dimension and 10 is the batch size.
  • The minibatch format for this input should be 'CB', where 'C' stands for the channel (feature) dimension, and 'B' stands for the batch dimension.
  • Your preprocessData function should correctly handle the batching of inputs. Ensure that the concatenation for the second input (X2) is along the second dimension to match the 'CB' format.
  • Make sure that the rest of your network and training loop can handle the 'CB' format for the second input. If you continue to encounter errors, double-check the dimensions of your inputs and outputs at each step, and ensure they match the expected dimensions of your network layers.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by