Can I use "trainNetwork" to train deep neural networks with non-image or non-sequence data for regression/classification?
54 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 7 Mär. 2018
Bearbeitet: MathWorks Support Team
am 19 Dez. 2023
Can I use "trainNetwork" to train deep neural networks with non-image or non-sequence data for regression/classification?
Akzeptierte Antwort
MathWorks Support Team
am 4 Dez. 2023
Bearbeitet: MathWorks Support Team
am 19 Dez. 2023
It is possible to use "trainNetwork" to train deep neural networks for regression/classification using non-image or non-sequence data.
For MATLAB R2020b and later:
Use "featureInputLayer" when you have a data set of numeric scalars representing features (data without spatial or time dimensions).
The following example in the "trainNetwork" documentation page uses "featureInputLayer" to train a deep learning model.
For MATLAB R2020a and earlier:
If you follow the documentation link:
for "trainNetwork", then the function assumes the input "X" to be an image matrix of size 4D with the last dimension corresponding to different images. The output "Y" can be 2D matrix. So you can use the following workaround to reshape the input dataset, if you want to use deep neural networks for solving traditional regression and/or classification problems for non-image, non-sequence data.
nFeatures = 20;
nExamples = 10000;
nOutputs = 1; % this example is for setting up a regression problem
x = rand(nExamples,nFeatures);
t = rand(nExamples, nOutputs);
XNew = reshape(x', [1,1,size(x,2),size(x,1)]);
The new input "XNew" now has the last dimension corresponding to different observations in the data set.
You will also have to change the layers as shown below:
layers = [ ...
imageInputLayer([1 1 nFeatures]); % this layer needs the first 3 dimensions of input "XNew"
fullyConnectedLayer(10);
fullyConnectedLayer(nOutputs); % this connected layer needs to have an output-size same as the number of responses (columns) in the output data set "t"
regressionLayer];
options = trainingOptions('sgdm');
trainedNet = trainNetwork(XNew, t, layers, options);
"trainNetwork" is actually agnostic to images or any other type of data, as long as you have less than 3 dimensions and all observations have the same dimensionality. In that case, observations are the 4-th dimension, like this example. This has the advantage that data requiring up to 3 dimensions (like colour images) can be easily represented. However, "trainNetwork" is not agnostic to the type of data in the sense of what layers make sense to use. If you want to use non image data, then the variety of layer that would make sense to use is reduced.
Further general information:
In regards to performing classification/regression with non-image, non-sequence data, it is beneficial to use the "FullyConnected" and "ReLU" layers instead of layers like "Convolution2DLayer", "LSTM", "MaxPooling2D". Using the later layers will not make much sense since they all assume some spatially or temporal correlation on the data. Please refer to the following documentation links for additional information on the "FullyConnected" and "ReLU" layers:
There is also functionality of creating custom layers to implement other custom functionalities based on your requirements. You can refer to the examples in the following documentation link:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!