Can I use "trainNetwork" to train deep neural networks with non-image or non-sequence data for regression​/classific​ation?

8 visualizzazioni (ultimi 30 giorni)

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 17 Gen 2025
Modificato: MathWorks Support Team il 31 Gen 2025
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.
To find more information on "trainNetwork" in MATLAB R2020a, execute the following command in the command window to view the release-specific documentation: 
>> web(fullfile(docroot, 'deeplearning/ref/trainnetwork.html'))
In this version, 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 a 2D matrix. 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);
The "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 layers 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 latter 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:
Please use the below link to search for the required information in the latest release: 

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by