How do I use trainNetwork for a sequence-to-one regression?
13 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I'm trying to create a model for a sequence-to-one regression. But sadly I receive an error:
Invalid training data. If the network outputs sequences, then regression responses must be a cell array of numeric sequences, or a single numeric sequence.
My Dataset: (a snapshot with 128 samples is attached - see .mat file)
load dataset.mat
whos X_train y_train
size(X_train) % 128x1 cell (128 samples)
size(X_train{1}) % 35x168 double (35 features with 168 time steps each)
size(y_train) % 128x1 double (1 numeric output for each sample)
My Network:
layers = [
sequenceInputLayer(35) % number of features
fullyConnectedLayer(42) % dummy value
tanhLayer
fullyConnectedLayer(1) % number of responses per sample
regressionLayer
];
options = trainingOptions('adam', 'MaxEpochs', 1);
trainNetwork(X_train, y_train, layers, options)
After reading the docs of Train deep learning neural network - MATLAB trainNetwork - MathWorks Deutschland I don't see my mistake.
From my point of view I'm doing the same thing as shown in the example from Sequence input layer - MATLAB - MathWorks Deutschland except I'm doing a regression instead of categorization.
openExample('matlab/DivideArrayAndReturnSubarraysInCellArrayExample')
0 件のコメント
採用された回答
Nikhil Reddy
2021 年 8 月 18 日
I understand that you are trying to create a sequence-to-one regression model. However, you are recieving an error regarding the responses (y_train) input parameter to the "trainNetwork" function. I see that since you are trying to acheive a single response for each sample(X_train), y_train has a dimentionality of n x 1.
It is my understanding that since you are providing sequence data, we also need to add an additional layer in the "layers" array which learns long term dependencies between time steps in the sequence data. We can add a "lstmLayer" with desired number of hidden memory units (depending on how much information the model should remember) along with the desired 'OutputMode' (in this case the 'OutputMode' is set to 'last' since the desired configuration of the regression model is sequence-to-one which is an extension of the sequence-to-sequence model). Find the redefined code for layers array below:
layers = [
sequenceInputLayer(35) % number of features
lstmLayer(10, 'OutputMode',"last")
fullyConnectedLayer(42) % dummy value
tanhLayer
fullyConnectedLayer(1) % number of responses per sample
regressionLayer
];
Please refer to the following links for more information:
lstmLayer:
Network architecture in sequence-to-sequence models:
4 件のコメント
Md Zahidul Islam
2022 年 2 月 8 日
編集済み: Md Zahidul Islam
2022 年 2 月 8 日
Recently I faced same problem while using 1dimentional CNN model. However, one way to solve the problem is to use globalAveragePooling1dLayer for such case. This layer take the average of all sequence in a channel and give single output.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!